Skip to content

Kubernetes Pod configuration schema

The Kubernetes Pod configuration schema is defined using YAML (or JSON), structured primarily into four top-level fields: apiVersion, kind, metadata, and spec.^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md]

Top-level Fields

  • apiVersion: Specifies the version of the Kubernetes API schema used for the object^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].
  • kind: Indicates the type of Kubernetes object being created; in this context, it is set to Pod^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].
  • metadata: Stores data that helps identify the object, such as the Pod name and labels^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].
  • spec: Defines the desired state of the Pod, including the container configurations and images^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].

Metadata Configuration

The metadata field is essential for organizing and identifying resources within the cluster^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].

Name

The metadata.name attribute assigns a unique identifier to the Pod^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].

Labels

metadata.labels are key-value pairs attached to Kubernetes objects^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md]. They are used to group meaningful and related objects, allowing services or deployments to select and target specific Pods using selectors^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].

Specification (spec)

The spec section outlines the actual behavior and configuration of the Pod^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].

Containers

The spec.containers field is a list that defines one or more containers to run within the Pod^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].

  • name: A user-defined string identifying the container within the Pod^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].
  • image: Specifies the location of the container image to be pulled, typically from a registry like Docker Hub^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].

Ports

The spec.containers.ports configuration manages network access for the container^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].

  • containerPort: Defines which specific port on the container is open for external resource access^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md]. This value should correspond to the port exposed by the application (e.g., port 8080 for a Golang API server)^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md].

Example Configuration

apiVersion: v1
kind: [Pod](<./pod.md>)
metadata:
  name: foo
  labels:
    app: foo
spec:
  containers:
    - name: foo
      image: mikehsu0618/foo
      ports:
        - containerPort: 8080
^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md]

Sources

^[400-devops-06-kubernetes-k8s-ithelp-day6-readme.md]