initContainers is a feature provided by K8s pods to run setup scripts before the actual containers start.
You can execute multiple initContainers in the same Pod, but keep in mind they will run one after another, not in parallel.
initContainers can have their own Docker images, so you can offload some configuration to them and keeping your main images as small as possible, increasing the security of your cluster.
Keep in mind that a pod will not be launched if one of the initContainers will stop. They are not to be seen as something optional or something that could fail.
- Create the pod:
kubectl apply -f initContainer.yml- Watch the logs:
kubectl get pods -w- See the logs for a specific container:
kubectl logs pods/nginx-with-init-container -c nginx-container- See all logs for all containers in a pod:
kubectl logs pods/nginx-with-init-container- See logs for past 2 hours in a certain container:
kubectl logs --since=2h pods/nginx-with-init-container -c nginx-container- See only the last 30 logs of a container:
kubectl logs --tail=30 pods/nginx-with-init-container -c nginx-containerπ There are many more ways to see logs, the command is pretty flexible. You can try for yourself.
