5. Introduction to Pod
Pod is the smallest schedulable unit in Kubernetes
Containers within a Pod share:
IP address space
Port space
Mounted Volumes
Containers within a Pod can communicate via
Localhost
IPC mechanism such as Semaphores or Shared Memory
6. Interaction with Pods
Kubectl create -f <POD Definition YAML>
Kubectl get pods
Kubectl describe pod <POD NAME>
Kubectl logs <POD NAME>
Kubectl exec <POD NAME> -- <COMMAND>
Kubectl top <POD NAME>
7. Birth of a Pod
Image Courtesy: Joe Beda
https://blog.heptio.com/core-kubernetes-
jazz-improv-over-orchestration-
a7903ea92ca
8. Phases of a Pod
Pending: Accepted by Kubernetes but container not created yet.
Running: Pod bound to a node, all containers created and at least one
container is running/starting/restarting
Succeeded: Container(s) exited with status 0
Failed: All containers exit and at least one exited with non-zero status.
Unknown: State of Pod could not be determined due to communication issues
with its node
9. Probes
Probe is a diagnostic performed periodically by kubelet on a container. There are
three types of handlers which can be used to probe containers:
ExecAction: Executes specified command inside container.
TCPSocketAction: Performs check against TCP socket. Returns success if port
is open
HTTPGetAction: Performs HTTP GET against specified port and path.
Successful if 200 > status code > 400.
10. Liveness and Readiness probes
livenessProbe: Indicates whether the Container is running. If the liveness probe
fails, the kubelet kills the Container, and the Container is subjected to its restart
policy.
readinessProbe: Indicates whether the Container is ready to service requests. If
the readiness probe fails, the endpoints controller removes the Pod’s IP address
from the endpoints of all Services that match the Pod.
12. Handlers to Lifecycle events
apiVersion: v1
kind: Pod
metadata:
name: lifecycle-demo
spec:
containers:
- name: lifecycle-demo-container
image: nginx
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]
preStop:
exec:
command: ["/usr/sbin/nginx","-s","quit"]
13. Init Containers
Out of Beta since 1.6
Init containers allow some pre-actions to run before the actual container is started.
Init containers run to completion sequentially.
Example Use Cases:
Copy source code from a repo
Generate config file for application (update pod specific variables etc)
Check readiness of dependent services
14. Init Containers Example
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
initContainers:
- name: init-myservice
image: busybox
command: ['sh', '-c', 'until nslookup myservice; do echo waiting for myservice; sleep 2; done;']
- name: init-mydb
image: busybox
command: ['sh', '-c', 'until nslookup mydb; do echo waiting for mydb; sleep 2; done;']