What is a Pod?
A Pod is the smallest deployable unit in Kubernetes. It represents a single instance of a running process in your cluster. Pods contain one or more containers, such as Docker containers, with shared storage and network resources.
Key Concept
Think of a Pod as a logical host for your application. Containers within a Pod share the same IP address, port space, and can communicate via localhost.
Pod Lifecycle
Understanding the Pod lifecycle is crucial for debugging and managing your applications effectively. Here are the main phases:
Pod Phases
Creating Pods
While you typically create Pods indirectly through Deployments or StatefulSets, understanding the Pod manifest is essential.
YAML Manifest
1apiVersion: v12kind: Pod3metadata:4 name: nginx-pod5 labels:6 app: nginx7spec:8 containers:9 - name: nginx10 image: nginx:1.2511 ports:12 - containerPort: 8013 resources:14 limits:15 memory: "128Mi"16 cpu: "500m"17 requests:18 memory: "64Mi"19 cpu: "250m"Apply the manifest:
kubectl apply -f nginx-pod.yamlkubectl get podskubectl describe pod nginx-podBest Practices
Interview Questions
Q: What is the difference between a Pod and a Container?
A: A Pod is a Kubernetes abstraction that can contain one or more containers. Containers share the Pod's network namespace and storage volumes.
Q: When would you use multiple containers in a Pod?
A: Use multiple containers when they are tightly coupled (sidecar pattern), such as a logging agent, proxy, or helper container that needs to share resources with the main application.
Q: How do containers within a Pod communicate?
A: Containers within the same Pod share the network namespace, meaning they can communicate via localhost and the same port space.