Init Containers in Kubernetes

Hello everyone!!
I made a mistake but I couldn’t find it.
The question said.
"
There are some applications that need to be deployed on Kubernetes cluster and these apps do have some pre-requisites where some configuration need to be changes before deploying the app container. Some of these changes can not be made inside the images so DevOps team has come up with a solution to use init containers to perform these tasks during deployment. Below is a sample scenario team is going to test first.

  1. Create a Deployment named as ic-deploy-datacenter.

  2. Configure spec as replicas should be 1, labels app should be ic-datacenter, template’s metadata lables app should be same ic-datacenter.

  3. The initContainers should be names as ic-msg-datacenter, use image debian, preferably with latest tag and use command ‘/bin/bash’, ‘-c’ and ‘echo Init Done - Welcome to xFusionCorp Industries > /ic/official’. The volume mount should be named as ic-volume-datacenter and mount path should be /ic.

  4. Main container should be named as ic-main-datacenter, use image debian, preferably with latest tag and use command ‘/bin/bash’, ‘-c’ and ‘while true; do cat /ic/official; sleep 5; done’. The volume mount should be named as ic-volume-datacenter and mount path should be /ic.

  5. Volume to be named as ic-volume-datacenter and it should be an emptyDir type.

Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.
"
my proposed solution is

Where did I make the mistake?
Thanks.

Hello, elsebasan
I think you need to use all command instructions in the command field not in the args field. Might be the reason.

Hello.
Maybe. But this way works and do the same. It’s similar to the brabo’s solution to game of pods for the deployment drupal.
Thanks you @player001 for answer me.

@Inderpreet can you please advise? I don’t think it is wrong having the second part of the command at the “args” section.

Hi @elsebasan @Salim:
I’ll say, try this way,

command: [ “/bin/bash”]
args: [ “-c”, “while true; do cat /ic/official; sleep 5; done” ]

This way, it works.
Hope it will help. Thanks.

1 Like

Yes you are right. This is the correct way to use command and args as defined in the kubernetes documentation.

Common mistakes which everyone makes due to which mostly the tasks failed.