Kubernetes CKA sample exam question 131 with answer

Question
Create a pod nginx using image nginx and init container git with image alpine/git with volume mount path of the main container's /usr/share/nginx/html.
nginx index.html needs to be overwritten in shared volume by index.html cloned from path https://github.com/dmitritelinov/dmitritelinov.github.io.git

Answer
Create pod manifest:

kubectl run nginx --image nginx --dry-run=client -o yaml
And modify it in the following way:
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: nginx
  name: nginx
spec:
  initContainers:
  - image: alpine/git
    name: git
    args:
    - clone
    - --
    - https://github.com/dmitritelinov/dmitritelinov.github.io.git
    - /data
    volumeMounts:
    - mountPath: "/data"
      name: data
  containers:
  - image: nginx
    name: nginx
    volumeMounts:
    - mountPath: "/usr/share/nginx/html"
      name: data
  volumes:
  - name: data
    emptyDir: {}
Apply:
kubectl apply -f pod.yaml
And verify:
kubectl exec -it nginx -- cat /usr/share/nginx/html/index.html