Contents

Kubernetes initContainers

What is initContainers?

initContainers
initContainers is just executing on starting the POD.
The initContainers runs one at a time in sequential order.
If any of the initContainers fail to complete, Kubernetes restarts the POD repeatedly until the Init Container succeeds.

initContainers YAML

pod-definition.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
    - name: myapp-container
      image: nginx
      command: [ "echo", "This is main conatiner." ]
  initContainers:
    - name: init-myservice
      image: nginx
      command: [ "echo", "This is one of initContainers. Init Service." ]
    - name: init-mydb
      image: mysql
      command: [ "echo", "This is one of initContainers. Init Database." ]