Delay Container Start Until other Container in pod is Started

Viewed 1601

I am working on a use case where sidecar container runs a shell script continuously on changes directory permission of main container. I want to Start side container only after Main Container in pod is ready .

I was looking at Init Containers and what I could see is init containers are good candidate when we have inter-pod dependency (pod A starts only after Pod B has started/healthy).

In my case I need container B to start only after Container A is started in the same Pod.

Deployment.yaml for refrence

     containers:
    - name: {{ .Chart.Name }}
      securityContext:
        {{- toYaml .Values.securityContext | nindent 12 }}
      image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
      imagePullPolicy: {{ .Values.image.pullPolicy }}
   - name: container2
      image: some-repo
      imagePullPolicy: {{ .Values.image.pullPolicy }}
1 Answers

I am not aware of any K8s native feature or hook that satisfies the use case you describe.

I would solve it like this:

Run your sidecar container within the same Pod as a regular container and get it to executes a script that pings the readiness endpoint of your application container before proceeding to check directory permissions.

Related