Table of contents
No headings in the article.
As word init
describe, init containers
are run before application containers run.
In some scenarios, we have to verify
or perform certain action
before starting the app container, like installing utilities
or run a setup script
etc. at that time, we can leverage the init container
.
Some facts about init containers
.
We can run multiple init containers before the app container.
init containers always run to
completion
.Each init contianer must
complete successfully
before the next one starts.
Let's do some hands-on with the init container.
In previous labs, we have created ruby on rails crud app
, we are going to add an init container in that same config,
initContainers:
- name: init-db
image: busybox:1.31
command: ['sh', '-c', 'while ! nc -z postgres 5432; do sleep 1; printf "-"; done; echo -e " >> Postgres DB Server has started";']
What if the application started serving the request and database
service is not up and running? nightmare
right?
to overcome this, we can use the init container as the above config. as you can see until the DB is not started
init container keeps running and will not allow application
container to start.
Reference: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
Reference: https://github.com/m3pratik/31daysofEKS/
Made with ❤️ by Pratikkumar Panchal. github.com/m3pratik/31daysofEKS