Specify Depends on in Kubernetes deployment

3/28/2018

I have two kubernetes deployments say backend and frontend. frontend deployment depends on the backend deployments. Means after backend deployment pods are ready then the pods for frontend should be created. How can I specify this in the deployment yaml?

-- Jitendra
kubernetes

1 Answer

3/28/2018

The solution you are looking for is Init container. Pod can have one or more Init containers and they run one after another before main Pod containers are started. Please be aware that each Init container runs until completion.

So you can use Init containers to check availability of your back-end applications. Here is an example:

apiVersion: v1
kind: Pod
metadata:
  name: front-end
  labels:
    app: front-end
spec:
  containers:
  - name: front-end
    image: node:boron
  initContainers:
  - name: init-backend
    image: busybox
    command: ['sh', '-c', 'until <put check condition for your back-end>; do echo waiting for back-end; sleep 2; done;']

For more information you can go through documentation.

-- Artem Golenyaev
Source: StackOverflow