Kubernetes CKA sample exam question 113 with answer

Question
Deploy a pod which runs nginx image for a web app. However, it needs 1200 seconds to initialize before nginx container starts.

Answer
Generate pod manifest:

kubectl run nginx --image=nginx --dry-run=client -o yaml
Adjust it and define initContainer in the pod definition. Init container is the one which gets executed first of all followed by other containers defined in the pod:
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  initContainers:
  - name: install
    image: busybox
    command:
    - /bin/sh
    - -c
    - "sleep 1200"
  containers:
  - image: nginx
    name: nginx
Apply:
kubectl apply -f po.yaml