Managing Application Initialization with Init Containers
Create a deployment named:
lab153deploy
Requirements:
apiVersion: apps/v1
kind: Deployment
metadata:
name: lab153deploy
spec:
replicas: 1
selector:
matchLabels:
app: lab153deploy
template:
metadata:
labels:
app: lab153deploy
spec:
initContainers:
- name: wait-30-seconds
image: busybox
command:
- sh
- -c
- sleep 30
containers:
- name: nginx
image: nginx
kubectl apply -f lab153deploy.yaml
kubectl get pods
During startup you should see:
NAME READY STATUS lab153deploy-xxxxx 0/1 Init:0/1
After approximately 30 seconds:
NAME READY STATUS lab153deploy-xxxxx 1/1 Running
kubectl describe pod
Look for:
Init Containers:
wait-30-seconds:
State: Completed
This confirms the initialization completed before nginx was started.
kubectl create deployment lab153deploy \ --image=nginx \ --dry-run=client -o yaml > lab153deploy.yaml
Edit the YAML and insert the initContainer section.