- apiVersion
- kind
- metadata
- spec
API Version
TheapiVersion field specifies the Kubernetes API version used to create the object. For Pods, the version is typically set as:
apps/v1 for Deployments or extensions/v1beta1 in legacy configurations.
Kind
Thekind field indicates the type of Kubernetes object to be created. For a Pod, it is defined as:
ReplicaSet, Deployment, or Service.
Metadata
In themetadata section, you provide key information about the Kubernetes object. This includes the object’s name and labels, which are key-value pairs that assist in organizing and filtering resources. Note the following:
- The
namefield must be a string. - The
labelsfield is a dictionary where you can define several key-value pairs.
app: myapp and type: front-end, it becomes easier to filter and manage your Pods later.
Ensure that within the metadata section you only include properties expected by Kubernetes. Proper indentation is crucial—children properties must be indented relative to their parent, and sibling properties must share the same indentation level.
Spec
Thespec section describes the desired state of the object. For a Pod, this primarily involves specifying the list of containers. Although a Pod can run multiple containers, this example focuses on a single container defined within an array for clarity. Each container configuration includes properties like the container’s name and the Docker image used.
Below is an example of a complete YAML configuration for a Pod:
Save the above configuration as a file (for example,
pod-definition.yml) and use it to deploy your Pod.Creating the Pod
To create the Pod from your YAML file, run the following command:Verifying the Pod
Once the Pod is created, you can verify its status using severalkubectl commands.
Listing All Pods
To list all Pods in your cluster, use:Viewing Detailed Pod Information
For detailed information about the Pod, execute:Summary
This lesson covered the essential components of YAML configurations for creating a Kubernetes Pod. We reviewed the purpose of theapiVersion, kind, metadata, and spec fields, and demonstrated how to apply these in a practical example. In subsequent lessons, we will explore additional Kubernetes objects and configurations.
Happy learning and happy deploying!