Skip to content

Small example for initContainers I read. Also contains instructions on displaying logs in a better way (either a specific container or the last 2 hours for example etc.)

License

Notifications You must be signed in to change notification settings

Robert076/initContainers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ initContainers

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.

πŸš€ Run the setup:

  1. Create the pod:
kubectl apply -f initContainer.yml
  1. Watch the logs:
kubectl get pods -w
  1. See the logs for a specific container:
kubectl logs pods/nginx-with-init-container -c nginx-container
  1. See all logs for all containers in a pod:
kubectl logs pods/nginx-with-init-container
  1. See logs for past 2 hours in a certain container:
kubectl logs --since=2h pods/nginx-with-init-container -c nginx-container
  1. 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.

❗️ Also, here is a useful resource I found on pod creation:

Image

About

Small example for initContainers I read. Also contains instructions on displaying logs in a better way (either a specific container or the last 2 hours for example etc.)

Topics

Resources

License

Stars

Watchers

Forks