Summary - Pod
- Docker & Kubernetes course
- Intermediate
- Lesson 24/82
- 5 min
Combine YAML and apply to write and apply a Pod definition.
Summary: Pods
In this group:
- A pod is a group of containers running on the same node and sharing IP/ports; it is ephemeral.
- YAML:
apiVersion: v1,kind: Pod,metadata,spec.containers;command/argsreplace ENTRYPOINT/CMD. apply -f,exec -it ... --,cpandport-forwardare the tools for working with pods.- Phases: Pending, Running, Succeeded, Failed; liveness and readiness probes watch health.
- Sidecar and init container patterns are the legitimate uses of multi-container pods.
kubectl apply -f pod.yaml
kubectl get pod api -w
kubectl logs api -c log-gondericiPractice A pod with a command
Write a pod YAML: name is; container named is, image busybox:1.36; command: ["sh", "-c"] and args: ["echo merhaba; sleep 3600"].
Starter code
# buraya yazSample solution
apiVersion: v1
kind: Pod
metadata:
name: is
spec:
containers:
- name: is
image: busybox:1.36
command: ["sh", "-c"]
args: ["echo merhaba; sleep 3600"]Expected output
pod/is created $ kubectl logs is merhaba
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the right way to keep a slow-starting app from being restarted constantly by its liveness probe?
- Shrinking the image
- Adding a startupProbe Correct answer
- Removing the readinessProbe
- Restarting the pod by hand
Explanation: The liveness check doesn't start until the startupProbe succeeds.
2 Open a shell in the pod's container.
kubectl exec -it api ____ sh
kubectl exec -it api -- sh
Explanation: After -- comes the command to run in the container.
3 Match.
| Term | Meaning |
|---|---|
kind: Pod |
apiVersion: v1 |
RESTARTS |
Restart count |
READY 2/2 |
Two containers ready |
port-forward |
Temporary access |