Mastering Pods in Kubernetes: A Quick Guide to Commands and Outputs

in this article we are going to learn about pod’s.

POD’s

  • In Kubernetes, a “pod” is the smallest building block and most basic unit

  • A Pod is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers.

  • it represents a single instance of a running process

  • pods are typically created and managed using higher level of abstraction such as Deployments, Replica-Sets or Stateful-Sets, which provides additional features like scaling, rolling updates, and self-healing capabilities

    Pods in a Kubernetes cluster are used in two main ways:

  • Pods that run a single container: The "one-container-per-Pod" model is the most common Kubernetes use case; in this case, you can think of a Pod as a wrapper around a single container; Kubernetes manages Pods rather than managing the containers directly.

  • Pods that run multiple containers that need to work together: A Pod can encapsulate an application composed of multiple co-located containers that are tightly coupled and need to share resources. These co-located containers form a single cohesive unit. Multi Container includes initcontainer and sidecar/helper container.

    To create a pod we will use manifest YAML files

    The following is an example of a Pod which consists of a container running the image nginx:latest

  • Create a file named nginx-pod.yaml with the following content

      ---
      apiVersion: v1 # species the API version of the Kubernetes object
      kind: pod  # specifies the kind of object, in this case, a Pod
      metadata: # metadata contains information about the object        3
        name: my-pod # name of the Pod3
      spec:   # specification of the Pod
        containers: # list of containers in the Pod
          - name: my-container # name of the container
            image: nginx:latest # image to use for the container
            ports: # list of ports to expose from the container
              - containerPort: 80 # port number to expose from the container
      ...
    

    To create the Pod shown above, run the following command:

      kubectl apply -f nginx-pod.yaml
      pod/nginx-pod created
    

    Check if the pod is running:

      kubectl get pods
    

    Output:

      NAME        READY   STATUS    RESTARTS   AGE
      nginx-pod   1/1     Running   0          10s
    

    If you need more details about the pod:

      kubectl describe pod nginx-pod
    

    sample Output Snippet:

      Name:         nginx-pod
      Namespace:    default
      Labels:       app=nginx
      Status:       Running
      Containers:
        nginx-container:
          Image:          nginx:latest
          Port:           80/TCP
          State:          Running
      Events:
        Type    Reason     Age   From               Message
        ----    ------     ----  ----               -------
        Normal  Scheduled  ...   default-scheduler  Successfully assigned default/nginx-pod to node-1
        Normal  Pulling    ...   kubelet            Pulling image "nginx:latest"
        Normal  Pulled     ...   kubelet            Successfully pulled image "nginx:latest"
        Normal  Created    ...   kubelet            Created container nginx-contai
    

Pod Commands:

  • kubectl get pod : Get pod

    Output:

      NAME         READY   STATUS    RESTARTS   AGE
      nginx-pod    1/1     Running   0          1h
      test-pod     0/1     Pending   0          2m
    
  • kubectl get pod -o wide : Get pod wide information
    Output:

      NAME         READY   STATUS    RESTARTS   AGE   IP            NODE           NOMINATED NODE   READINESS GATES
      nginx-pod    1/1     Running   0          1h    10.244.0.5   node-1         <none>           <none>
      test-pod     0/1     Pending   0          2m    <none>       node-2
    
  • kubectl get pod -w : Get pod with watch

    Output: (Continuously updates as pod statuses change)

      NAME         READY   STATUS    RESTARTS   AGE
      nginx-pod    1/1     Running   0          1h
      test-pod     0/1     Pending   0          2m
      test-pod     1/1     Running   0          3m
    
  • kubectl get pod -o yaml : Get pod in yaml

    kubectl get pod nginx-pod -o yaml

    Output: (Shows the pod configuration in YAML format)

      apiVersion: v1
      kind: Pod
      metadata:
        name: nginx-pod
        namespace: default
      spec:
        containers:
        - image: nginx:latest
          name: nginx-container
          ports:
          - containerPort: 80
      status:
        phase: Running
        podIP: 10.244.0.5
    
  • kubectl edit pod : Edit pod

    Command:

      kubectl edit pod nginx-pod
    

    Action: Opens the pod configuration in the editor (e.g., nano or vi) for direct editing. After saving changes, Kubernetes applies them.

  • kubectl describe pod : Describe pod

    Output:

      Name:         nginx-pod
      Namespace:    default
      Status:       Running
      IP:           10.244.0.5
      Containers:
        nginx-container:
          Image:       nginx:latest
          Port:        80/TCP
      Events:
        Type    Reason     Age   From               Message
        ----    ------     ----  ----               -------
        Normal  Scheduled  1h    default-scheduler  Successfully assigned default/nginx-pod to node-1
        Normal  Pulled     1h    kubelet            Successfully pulled image "nginx:latest"
    
  • kubectl delete pod : Delete pod

    Output:

      pod "nginx-pod" deleted
    
  • kubectl logs pod : Logs of the pod

    kubectl logs nginx-pod

    Output: (Shows logs generated by the pod)

      10.244.0.5 - - [28/Apr/2025:11:43 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.
    
  • kubectl exec -it pod /bin/bash : Execute into pod

    Output: (Opens a shell inside the container)

      kubectl exec -it nginx-pod -- /bin/bash
      root@nginx-pod:/#
    

Conclusion

This article aimed to provide a high-level overview of pods in Kubernetes, hopefully sparking your curiosity and encouraging you to delve deeper into its fascinating ecosystem. If you're intrigued, I urge you to explore Kubernetes further and immerse yourself in the rich world of cloud-native technologies.

Remember, Kubernetes may seem complex at first, but don't let it intimidate you. Once you've deployed a few applications, it becomes much more straightforward and intuitive to use—especially for developers. So, embrace the challenge and enjoy the journey!

Before you leave

If you enjoy the content I share, feel free to connect with me on Sai Prasad Annam | LinkedIn there’s a lot more to explore, and I think you’ll find it intriguing!"

0
Subscribe to my newsletter

Read articles from SAI PRASAD ANNAM directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

SAI PRASAD ANNAM
SAI PRASAD ANNAM

Hi there! I'm Sai Prasad Annam, an enthusiastic and aspiring DevOps engineer and Cloud engineer with a passion for integrating development and operations to create seamless, efficient, and automated workflows. I'm driven by the challenges of modern software development and am dedicated to continuous learning and improvement in the DevOps field.