Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify Depends on in Kubernetes deployment

Tags:

kubernetes

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?

like image 251
Jitendra Avatar asked Mar 28 '18 05:03

Jitendra


People also ask

How do I set an environment variable in Kubernetes deployment?

To set environment variables, include the env or envFrom field in the configuration file. Note: The environment variables set using the env or envFrom field override any environment variables specified in the container image. Note: Environment variables may reference each other, however ordering is important.

What do you need to specify to access the Microservice running on a pod in Kubernetes?

Irrespective of the Service type, if you choose to create a Service and your container listens on a port (incoming), you need to specify two ports. The Service will be created mapping the port (incoming) to the target port seen by the container. This Service will route to your deployed Pods.

What are the specs declared in deployment in Kubernetes?

Under spec, we declare the desired state and characteristics of the object we want to have. For example, in deployment spec, we would specify the number of replicas, image name etc. Kubernetes will make sure all the declaration under the spec is brought to the desired state. Spec has three important subfields.


1 Answers

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.

like image 68
Artem Golenyaev Avatar answered Sep 21 '22 22:09

Artem Golenyaev