Understanding Kubernetes Pod — A Beginner’s Guide
Journey into the Podverse: A Comprehensive Introduction to Kubernetes Pods

Find Complete mind map of A Beginner’s Guide to Kubernetes
In the world of Kubernetes, pods are a fundamental building block that forms the foundation of application deployment. They provide a logical abstraction for running and managing containers within a cluster.
In this beginner-friendly guide, we will explore the concept of pods, why they are essential in Kubernetes, how they work, and their key features.
Check out “Understanding Kubernetes — A Beginner’s Guide” for the comprehensive series🚀
Why Do We Need Pods?
To truly grasp the importance of pods, we need to understand the role of containers in application deployment.

Containers have revolutionized the way we package, distribute, and run applications by providing a lightweight, isolated environment for applications and their dependencies.
However, managing individual containers at scale can be complex. This is where pods come in.
Pods serve as the basic unit of deployment in Kubernetes, acting as a wrapper around one or more containers.By grouping containers within pods, Kubernetes simplifies the management and orchestration of applications, making it easier to scale, update, and monitor them.
Key Features of Pods
- Co-located Containers: Pods allow multiple containers to run together within the same network and storage context, promoting co-location and enabling them to work seamlessly as a cohesive unit.
- Shared Networking: Containers within a pod share the same IP address and port space, simplifying communication between containers within the pod.
- Shared Storage: Pods can define shared volumes, enabling containers within the pod to access and share data, facilitating data persistence and collaboration.
- Atomic Deployment and Scaling: Pods provide atomicity in scaling and deployment, allowing for consistent scaling and updates of all containers within the pod.
Creating a Pod in Kubernetes
Imperative Method
You can create a Pod in Kubernetes using the imperative method, which involves running a command with the kubectl tool.
For example, to create a Pod named “web” with the image of nginx:latest, you can use the following command:
$ kubectl run web — image=nginx
This will create a Pod named “web” with the nginx:latest image.
You can also specify additional commands and arguments when creating a Pod using the imperative method.
For example, to create a Pod named “client” with the image of busybox and run a sleep command for 100000 seconds, you can use the following command:
$ kubectl run client — image=busybox — command — bin/sh -c “sleep 100000”
Declarative Method
Alternatively, you can create a Pod in Kubernetes using the declarative method, which involves defining a YAML file that describes the desired state of the Pod.
For example, the following YAML file defines a Pod named “web” with the nginx:latest image:
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
containers:
- name: nginx-container
image: nginx:latest
You can create the Pod using the YAML file with the kubectl apply command, like this:
$ kubectl apply -f nginx.yml
Similarly, you can specify additional commands and arguments in the YAML file.
For example, the following YAML file defines a Pod named “client” with the busybox image and runs a sleep command for 1000000 seconds:
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
containers:
- name: nginx-container
image: nginx:latest
Useful Commands for Understanding Pod YAML Syntax
There are several commands that can be helpful for understanding the Pod YAML syntax and validating manifests.
kubectl explain pods
: Provides detailed documentation on the Pod resource and its available fields.
kubectl explain pod.spec
: Provides documentation on the spec field of the Pod, which contains configuration details.
kubectl explain pod.spec.containers
: Provides documentation on the containers field within the spec field of the Pod, allowing you to define multiple containers within the same Pod.
Server-side Dry Run
With server-side dry run, kubectl processes the client’s request just like normal, but it does not persist the object’s status to storage.
Example:
$ kubectl apply -f nginx.yml — dry-run=server
Client-side Dry Run
With client-side dry run, kubectl outputs the object to stdout instead of actually applying it to the cluster. This can be useful for validating the syntax of a manifest or generating a correct YAML manifest.
Example 1: Validate manifest syntax
$ kubectl apply -f nginx.yml — dry-run=client
Example 2: Generate YAML manifest for a Pod
$ kubectl run web — image=nginx — dry-run=client -o yaml
Example 3: Generate and save YAML manifest to a file
$ kubectl run web — image=nginx — dry-run=client -o yaml > nginx.yml
Using kubectl dry-run in either server-side or client-side mode can help you validate your manifest syntax and generate correct YAML manifests for Kubernetes objects.
Basic Operations on Pods
You can perform various operations on Pods using kubectl commands.
1. Get Pod List
To list all Pods in the cluster, you can use the following command:
$ kubectl get pods
Example output:
NAME READY STATUS RESTARTS AGE
client 1/1 Running 0 5m14s
web 1/1 Running 0 15m
You can also use the -o wide option to get additional information like IP, Node, and Age of the Pods:
$ kubectl get pods -o wide
Example output:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
client 1/1 Running 0 5m17s 10.244.2.4 k8s-worker2 <none> <none>
web 1/1 Running 0 15m 10.244.1.2 k8s-worker1 <none> <none>
2. Get YAML Definition of a Pod
To get the YAML definition of a specific Pod, you can use the following command:
$ kubectl get pods <pod-name> -o yaml
Example output:
<YAML definition of the Pod>
3. Delete Pod
To delete a Pod, you can use the following command:
$ kubectl delete pod <pod-name>
Example output:
pod “web” deleted
4. Get Detailed Information of a Pod
To get detailed information about a Pod, you can use the following command:
$ kubectl describe pod <pod-name>
Example output:
<Detailed information about the Pod>
Debug : API Level Log
You can use the -v option to get detailed logs at the API level for each kubectl command, for example:
Get more detailed log for kubectl operations at API level (specify -v with different levels such as 6, 7, 8, 9 for more detailed information):
$ kubectl get pod <pod-name> -v 6
Use — watch to continuously watch kubectl operations at API level:
$ kubectl get pods <pod-name> — watch -v 6
Output:
...
I0421 15:30:26.123456 12345 round_trippers.go:434] GET https://api.example.com/v1/namespaces/default/pods/my-pod 200 OK in 1234 milliseconds
I0421 15:30:26.987654 12345 round_trippers.go:434] GET https://api.example.com/v1/namespaces/default/pods/my-pod/status 200 OK in 987 milliseconds
...
🔔 Stay tuned or subscribe to my series: “Understanding Kubernetes — A Beginner’s Guide” to explore everything about Kubernetes. 🚀
➕Join the Medium Membership Program to support my work and connect with other writers.
📝 Have questions or suggestions? Leave a comment or message me through Medium. Let’s connect!
Thank you for your support! 🌟