<p>I have a helm deployment which deploys 2 containers pod.</p>
<p>Now I need to  include init container to one of the container pod.</p>
<p>I'm new to helm. Kindly share the snippet to achieve this. Here under spec I have defined 2 containers in which container 1 is dependent on container 2. So container 2 should be up and then I need to run init container for container 1.</p>
<p><strong>deployment.yaml</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include &quot;test.fullname&quot; . }}
  namespace: {{ .Values.global.namespace }}
  labels:
    {{- include &quot;test.labels&quot; . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include &quot;testLabels&quot; . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include &quot;test.selectorLabels&quot; . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ .Values.cloudsqlproxySa }}
      automountServiceAccountToken: true
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      
      containers:
        - name: {{ .Chart.Name }} # For this I need to include the init container.
          securityContext:
            {{- toYaml .Values.test.securityContext | nindent 12 }}
          image: &quot;{{ .Values.test.image.repository }}:{{ .Values.test.image.tag | default .Chart.AppVersion }}&quot;
          imagePullPolicy: {{ .Values.test.image.pullPolicy }}
          ports:
            - name: {{ .Values.test.port.name }}
              containerPort: {{ .Values.test.port.containerPort }}
              protocol: {{ .Values.test.port.protocol }}
          livenessProbe:
            httpGet:
              path: /
              port: {{ .Values.test.port.containerPort }}
          readinessProbe:
            httpGet:
              path: /
              port: {{ .Values.test.port.containerPort }}
          envFrom:
            - configMapRef:
                name: {{ .Values.configmap.name }}  
          resources:
            {{- toYaml .Values.test.resources | nindent 12 }}
          volumeMounts:
          - name: gcp-bigquery-credential-file
            mountPath: /secret
            readOnly: true
      
        - name: {{ .Chart.Name }}-gce-proxy 
          securityContext:
            {{- toYaml .Values.cloudsqlproxy.securityContext | nindent 12 }}
          image: &quot;{{ .Values.cloudsqlproxy.image.repository }}:{{ .Values.cloudsqlproxy.image.tag | default .Chart.AppVersion }}&quot;
          imagePullPolicy: {{ .Values.cloudsqlproxy.image.pullPolicy }}
          command:
          - &quot;/cloud_sql_proxy&quot;
          - &quot;-instances={{ .Values.cloudsqlConnection }}=tcp:{{ .Values.cloudsqlproxy.port.containerPort }}&quot;
          ports:
          - name: {{ .Values.cloudsqlproxy.port.name }}
            containerPort: {{ .Values.cloudsqlproxy.port.containerPort }}
          resources:
            {{- toYaml .Values.cloudsqlproxy.resources | nindent 12 }}
          volumeMounts:
          - name: gcp-bigquery-credential-file
            mountPath: /secret
            readOnly: true    

      volumes:
      - name: gcp-bigquery-credential-file
        secret:
          secretName: {{ .Values.bigquerysecret.name }}

      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
</code></pre>

user2439278
<p>Posting this as a community wiki out of comments, feel free to edit and expand.</p>
<hr />
<p>As @anemyte responded in comments, it's not possible to start init container after the main container is started, this is the logic behind init-containers. <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#understanding-init-containers" rel="nofollow noreferrer">Understanding init-containers</a></p>
<p>Possible solution for this from @DavidMaze is to separate containers into different deployments and setup a container with application to restart itself until proxy container is up and running. Full quote:</p>
<blockquote>
<p>If the init container exits with an error if it can't reach the proxy
container, and you run the proxy container in a separate deployment,
then you can have a setup where the application container restarts
until the proxy is up and running. That would mean splitting this into
two separate files in the <code>templates</code> directory</p>
</blockquote>
