Pod
Pod
The smallest deployment unit in Kubernetes. Contains one or more containers.
Pod
The smallest deployment unit in Kubernetes. Contains one or more containers.
A Pod is the smallest deployable unit that can be created and managed in Kubernetes. The name comes from "a pod of whales," and it groups one or more containers together, sharing the same network namespace and storage.
Containers within a Pod communicate with each other via localhost and share the same IP address. A single-container Pod is generally recommended, but multi-container Pods are used in the sidecar pattern (logging, proxy) or the ambassador pattern (external service proxy).
A Pod is designed to be ephemeral. It can be deleted and recreated at any time due to node failures, resource shortages, or scheduler decisions. Therefore, the standard practice is to manage Pods through higher-level controllers such as Deployment, StatefulSet, and DaemonSet.
In practice, a Pod spec defines resource requests/limits, liveness/readiness probes, security context, environment variables, secret mounts, and more. In production, set replicas: 3 or more to ensure high availability.
# νλ‘λμ
λ 벨 Pod μ€ν (Deployment κΆμ₯)
apiVersion: v1
kind: Pod
metadata:
name: api-server
labels:
app: api-server
version: v1.2.3
team: backend
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9090"
spec:
# 보μ μ€μ
securityContext:
runAsNonRoot: true
runAsUser: 1000
fsGroup: 2000
# μ΄κΈ°ν 컨ν
μ΄λ (λ©μΈ 컨ν
μ΄λ μ€ν μ )
initContainers:
- name: init-db-check
image: busybox:1.36
command: ['sh', '-c',
'until nc -z postgres-service 5432; do
echo "Waiting for database...";
sleep 2;
done']
containers:
# λ©μΈ μ ν리μΌμ΄μ
컨ν
μ΄λ
- name: api
image: myregistry.io/api-server:v1.2.3
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 8080
- name: metrics
containerPort: 9090
# 리μμ€ μ ν (νμ!)
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "1000m"
memory: "512Mi"
# νκ²½λ³μ
env:
- name: NODE_ENV
value: "production"
- name: DB_HOST
valueFrom:
configMapKeyRef:
name: db-config
key: host
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db-secrets
key: password
# ν¬μ€μ²΄ν¬ (νμ!)
livenessProbe:
httpGet:
path: /health/live
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /health/ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
failureThreshold: 3
# Graceful shutdown
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 10"]
# λ³Όλ₯¨ λ§μ΄νΈ
volumeMounts:
- name: config-volume
mountPath: /app/config
readOnly: true
- name: cache-volume
mountPath: /app/cache
# μ¬μ΄λμΉ΄ 컨ν
μ΄λ (λ‘κ·Έ μμ§)
- name: log-shipper
image: fluent/fluent-bit:2.2
resources:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "100m"
memory: "128Mi"
volumeMounts:
- name: log-volume
mountPath: /var/log/app
volumes:
- name: config-volume
configMap:
name: api-config
- name: cache-volume
emptyDir: {}
- name: log-volume
emptyDir: {}
# μ€μΌμ€λ§ μ€μ
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
app: api-server
topologyKey: kubernetes.io/hostname
terminationGracePeriodSeconds: 30
restartPolicy: Always
Senior: "The api-server Pod keeps getting OOMKilled. Have you done any memory profiling?"
Junior: "Yes, memory goes up to 480MB during peak hours. The current limit is 256Mi, so I think raising it to 512Mi should work."
Interviewer: "Please explain the difference between a Pod and a Container."
Candidate: "A Pod is the deployment unit of Kubernetes and contains one or more Containers. Containers within the same Pod share network and storage, are scheduled together, and are terminated together."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
Reviewer: "This Pod spec has no readinessProbe. During deployment, traffic could be routed to a Pod that isn't ready."
Developer: "Ah, the /health/ready endpoint exists, but I forgot to add the probe configuration. I'll add it."