0

I am running a static pod in my 1.21.5 Kubernetes cluster following this guide.

I am now trying to add an init container to my static pod manifest using the usual syntax

initContainers:
  - name: debug
    image: gcr.io/my-image
    command:
    - ...

Unfortunately, using the crictl and the kubectl, I see that my static pod starts well an properly but there is no init container neither in logs, nor in crictl nor in the pods container count in the kubectl.

Are init containers supported in static pods?

Thank you!

Sergey Shcherbakov
  • 143
  • 1
  • 2
  • 9
  • 2
    this should be possible. Are you sure there's no indentation issue that could cause kubelet to drop your initContainer? Maybe restart kubelet would force its reading back those static pods configuration? – SYN Aug 15 '22 at 12:25
  • Thank you SYN, indeed, at the moment I'm not sure anymore that my changes to the static pod manifest in /etc/kubernetes/manifests/kube-apiserver.yaml are being picked up at all. (I'm trying to modify kube-apiserver static pod and cannot get its config updated no matter what I restart) – Sergey Shcherbakov Aug 15 '22 at 15:59
  • 1
    If the Init container is run and exited successfully (exit code 0) without outputting anything, then it's expected there is nothing in STDOUT/STDERR. As far as I can tell, static pod have some limitation but nothing specific to init container could be a limitation regarding initContainer I think in most cases using a Daemonset should be the preferred method. – Sai Chandra Gadde Aug 16 '22 at 10:21
  • Thank you @SaiChandraGadde, I am pretty sure the reason of my problem was the manifest changes not being picked up. – Sergey Shcherbakov Aug 17 '22 at 15:28
  • Did you had time to check my answer? It helped you to solve your problem? If yes, Please consider to accept and upvote it. [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – Sai Chandra Gadde Aug 23 '22 at 03:54

1 Answers1

1

I tried to replicate this scenario but by using your image i got an error : image pull back but when im using nginx image i have successfully created an init container.

Once check your image for errors before deploying.

Here is the yaml file I have used.

apiVersion: v1

kind: Pod

metadata:

 name: static-web

 labels:

   role: myrole

spec:

 containers:

   - name: web

     image: nginx

     ports:

       - name: web

         containerPort: 80

         protocol: TCP

 initContainers:
  
   - name: debug
    
     image: nginx

After the pod is created try using this command kubectl describe -f <nameofyamlfile>.yaml

enter image description here

Here in the above screenshot you can see the error or status of the containers.

For sample code and for verifying follow Init containers.