Question
Create a pod named cka-pod with image nginx which have modified index.html by init container.
The content of index.html file should be "Hello World".
Answer
Generate pod manifest:
kubectl run cka-pod --image=nginx --dry-run=client -o yaml
Adjust it:
apiVersion: v1
kind: Pod
metadata:
labels:
run: cka-pod
name: cka-pod
spec:
initContainers:
- image: busybox
name: init
command: ['sh', '-c', 'echo "Hello World" > /data/index.html']
volumeMounts:
- name: vol
mountPath: /data
containers:
- image: nginx
name: cka-pod
volumeMounts:
- name: vol
mountPath: /usr/share/nginx/html
volumes:
- name: vol
emptyDir: {}
Apply and check:
kubectl applu -f po.yaml
kubectl get po
kubectl describe po cka-pod
Test with curl:
kubectl run test --rm --image=curlimages/curl -it --restart=Never -- "-m 5" $(kubectl get po cka-pod --template '{{.status.podIP}}')
output should be:
Hello World