<p>So I have a helm chart that deploys a pod, so the next task is to create another pod once the first pod is running.</p>

<p>So I created a simple pod.yaml in chart/templates which creates a simple pod-b, so next step to only create pod-b after pod-a is running.</p>

<p>So was only at helm hooks but don't think they care about pod status.</p>

<p>Another idea is to use Init container like below but not sure how to write command to lookup a pod is running?</p>

<pre><code>spec:
  containers:
  - name: myapp-container
    image: busybox
    command: ['sh', '-c', 'echo The app is running! &amp;&amp; sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox
    command: ['sh', '-c', 'until nslookup myservice; do echo waiting for myservice; sleep 2; done;']
</code></pre>

<p>Another idea is a simple script to check pod status something like:</p>

<pre><code>y=`kubectl get po -l app=am -o 'jsonpath={.items[0].status.phase}'`
   while [ $i -le 5 ]
   do
    if [[ "$y" == "Running" ]]; then
      break
    fi
    sleep 5
   done
</code></pre>

<p>Any advice would be great.</p>

daverocks
<p>If you want your <code>post-install/post-upgrade</code> <a href="https://helm.sh/docs/topics/charts_hooks/" rel="nofollow noreferrer">chart hooks</a> to work, you should add <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes" rel="nofollow noreferrer">readiness probes</a> to your first pod and use <a href="https://github.com/helm/helm-www/blob/master/content/en/docs/helm/helm_upgrade.md#options" rel="nofollow noreferrer">--wait</a> flag.</p>

<p><code>helm upgrade --install -n test --wait mychart .</code></p>

<p><strong>pod.yaml</strong></p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: readiness-exec
  labels:
    test: readiness
spec:
  containers:
  - name: readiness
    image: k8s.gcr.io/busybox
    args:
    - /bin/sh
    - -c
    - sleep 30; touch /tmp/healthy; sleep 600
    readinessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 10
      periodSeconds: 5
      failureThreshold: 10
</code></pre>

<p><strong>hook.yaml</strong></p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: "post-deploy"
  annotations:
    "helm.sh/hook": post-upgrade,post-install
    "helm.sh/hook-delete-policy": before-hook-creation
spec:
  backoffLimit: 1
  template:
    metadata:
      name: "post-deploy"
    spec:
      restartPolicy: Never
      containers:
        - name: post-deploy
          image: k8s.gcr.io/busybox
          args:
          - /bin/sh
          - -c
          - echo "executed only after previous pod is ready"
</code></pre>
