Pod:
- pod is smallest deployment unit in k8s
ALL container in pods
- we have same network ip address
- having shared volume
- Are started and stoped as a unit.

Types of container
- containers:
- this is used for application container
- all container will run parellel
- Mandatory atlest one container
- init-container:
- pre-conditional run before container start
- this will be run in sequence
- Optional
- this container will run and complete state.
alpine ==> bash ==> curl download dependancy ==> create folder and add files
- ephemeralContainers:
- temporary container for debug
- Optional
kubectl debug -it <pod> --image=<image> --target=<container>
API Referance link
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
labels:
app: sample
environment: production
spec:
containers:
- name: sample-container
image: nginx:latest
ports:
- containerPort: 80
initContainers:
- name: init-sample
image: busybox:latest
command: ["sh", "-c", "echo Initializing... && sleep 5"]
Pod lifecycle:
- pending: accept the cluster to create pod, also will pull images for container and init container
- Running: bound to node and at least one container will started running
- succeeded: all init container or container run and exist with status code
o
- Failed: if any container is failled and terminated
- Unknow: pod state can’t be determined.(resource issue, node problems , network issues)
Container states:
- waiting: (not yet running container but its in pulling images and runing init container)
- Running: Executing normally (application is runing)
- terminated: Finshed or failed
note deploy below yaml and test the container state by describe pod
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
labels:
app: sample
environment: production
spec:
containers:
- name: sample-container
image: nginx:latest
ports:
- containerPort: 80
- name: init-sample
image: busybox:latest
command: ["sh", "-c", "echo Initializing... && sleep 10"]
kubectl get pod <pod-name> -n <namespace> -o jsonpath='{range .status.containerStatuses[*]}{.name}{"\t"}{.state}{"\n"}{end}'
kubectl logs <pod_name> -c <container_name>
Restart policy
- Always: (deafault -> k8s try to restart if pod or container failed)
- Never: (never restart)
- OnFailure: Restart pod when if its failled when status code is not equal to
0
Task:
- create sample yaml for pod image tomcat:latest port: 8080
- add init container
initContainers:
- name: init-sample-data
image: busybox:latest
command: ["sh", "-c", "echo Initializing demo... && sleep 5"]
- check logs and describe pod to validate state