DEV Community

Wycliffe A. Onyango
Wycliffe A. Onyango

Posted on

100 Days of DevOps: Day 48

How to Create and Verify a Kubernetes Pod

Creating and managing Kubernetes pods is a fundamental skill for DevOps teams. This guide walks you through the steps to create a simple pod using a YAML manifest and then verify its status and configuration. We'll create a pod named pod-httpd using the httpd:latest image, with the label app=httpd_app, and name the container httpd-container.

Step 1: Create the Pod Manifest File

First, we'll create a YAML file that defines the desired state of our pod. The file, named pod-httpd.yaml, specifies the pod's name, labels, and the container it should run.

thor@jumphost ~$ vi pod-httpd.yaml
Enter fullscreen mode Exit fullscreen mode

Content for pod-httpd.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: pod-httpd
  labels:
    app: httpd_app
spec:
  containers:
  - name: httpd-container
    image: httpd:latest
Enter fullscreen mode Exit fullscreen mode
  • apiVersion: Specifies the Kubernetes API version. For pods, this is v1.
  • kind: Defines the type of Kubernetes resource, which is Pod.
  • metadata: Contains data that uniquely identifies the object, including its name and labels.
  • spec: Describes the desired state of the resource. Here, we define the containers array, specifying the name and image for our container.

Step 2: Apply the Manifest to the Cluster

Once the YAML file is created, use kubectl apply to submit the pod definition to the Kubernetes cluster. The cluster's control plane will then work to match the desired state by creating the pod.

thor@jumphost ~$ kubectl apply -f pod-httpd.yaml
Enter fullscreen mode Exit fullscreen mode

Expected Output:

pod/pod-httpd created
Enter fullscreen mode Exit fullscreen mode

This output confirms that the Kubernetes API server has accepted the pod definition and initiated the creation process.

Step 3: Verify the Pod's Status

After applying the manifest, it's essential to check if the pod is running as expected. The kubectl get pods command provides a quick overview of all pods in the current namespace.

thor@jumphost ~$ kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Expected Output:

NAME          READY   STATUS    RESTARTS   AGE
pod-httpd     1/1     Running   0          20s
Enter fullscreen mode Exit fullscreen mode
  • NAME: The name of the pod (pod-httpd).
  • READY: Shows that 1 out of 1 container in the pod is ready and running.
  • STATUS: Confirms the pod is in the Running state.
  • RESTARTS: Indicates the number of times the container has restarted. A value of 0 is ideal.
  • AGE: The time since the pod was created.

Step 4: Inspect the Pod's Details

For a more comprehensive look at the pod's configuration and events, use the kubectl describe pod command. This is invaluable for troubleshooting.

thor@jumphost ~$ kubectl describe pod pod-httpd
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Name:         pod-httpd
Namespace:    default
...
Labels:       app=httpd_app
...
Status:       Running
...
Containers:
  httpd-container:
    Container ID:   containerd://...
    Image:          httpd:latest
    Image ID:       docker.io/library/httpd@sha256:027c678f...
    State:          Running
      Started:      Sat, 20 Sep 2025 11:47:44 +0000
    Ready:          True
...
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  2m29s default-scheduler  Successfully assigned default/pod-httpd to kodekloud-control-plane
  Normal  Pulling    2m28s kubelet            Pulling image "httpd:latest"
  Normal  Pulled     2m23s kubelet            Successfully pulled image "httpd:latest" in ...
  Normal  Created    2m23s kubelet            Created container httpd-container
  Normal  Started    2m23s kubelet            Started container httpd-container
Enter fullscreen mode Exit fullscreen mode

The output of kubectl describe confirms that the pod has the correct name, label (app=httpd_app), and container configuration (httpd-container running the httpd:latest image). The Events section provides a chronological log of the pod's lifecycle, from being scheduled on a node to the container successfully starting. This detailed information confirms the pod was created and is operating correctly.

Top comments (0)