Init Container:
Init Containers are the containers that should run and complete before the startup of the main container in the pod.
It provides a separate lifecycle for the initialization so that it enables separation of concerns in the applications.
For example if you need to install any software before main application start. Using init container you can do the software installation task.
root@ip-172-31-44-144:~# kubectl create -f init-demo.yml
pod/init-cont-demo created
root@ip-172-31-44-144:~#
root@ip-172-31-44-144:~# kubectl get pods
NAME READY STATUS RESTARTS AGE
init-cont-demo 1/1 Running 0 4s
root@ip-172-31-44-144:~# kubectl exec -it init-cont-demo -- /bin/sh
Defaulted container "nginx" out of: nginx, busybox (init)
# apt-get update && apt-get install -y curl
Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
Get:2 http://security.debian.org/debian-security bullseye-security InRelease [44.1 kB]
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [39.4 kB]
Get:4 http://security.debian.org/debian-security bullseye-security/main amd64 Packages [122 kB]
Get:5 http://deb.debian.org/debian bullseye/main amd64 Packages [8183 kB]
Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [2596 B]
Fetched 8507 kB in 1s (5699 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
curl is already the newest version (7.74.0-1.3+deb11u1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
# curl localhost
<html><h1>This is data from Init Container</h1><html>
#
ReplyDeleteThank you for sharing very useful information.
Workday Online Training
Workday Online Training in Hyderabad