Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add pod dependency in kubernetes as like 'depends_on' in docker-compose.yml

I need to start kubernetes pods in a sequence like pod2 should start only when pod1 is up and running.

we can do this in docker-compose.yml using depends_on

like image 946
sam Avatar asked May 17 '18 06:05

sam


People also ask

What is Depends_on in Docker compose?

depends_on is a Docker Compose keyword to set the order in which services must start and stop. For example, suppose we want our web application, which we'll build as a web-app image, to start after our Postgres container.

How do you make a pod in Kubernetes using yaml?

To create a Kubernetes pod with YAML, you first create an empty file, assign it the necessary access permissions, and then define the necessary key-value pairs. The important ones are the apiVersion, the kind (pod), name, and the containers within the pod.

How do I add pods to Kubernetes?

To create a pod using the nginx image, run the command kubectl run nginx --image=nginx --restart=Never . This will create a pod named nginx, running with the nginx image on Docker Hub. And by setting the flag --restart=Never we tell Kubernetes to create a single pod rather than a Deployment.

Can we have similar container in pod?

Yes, you can add multiple container with same image. The containers object must contain: name: Name of the container. It must be a DNS_LABEL and be unique within the pod.


2 Answers

No, there is no built-in dependency management equivalent to depends_on available. In general, we assume loosely coupled services and as a good practice there should be no hard dependency in terms of start-up order, but retries and timeouts should be used. If you have to hardcode dependencies, you can use init containers. In your case, a init container in pod2 could simply query if pod1 (or better: the service in front of it) is ready in a while loop. The main container in pod2 is guaranteed only to be launched if and when the init container exits successfully.

like image 55
Michael Hausenblas Avatar answered Oct 01 '22 23:10

Michael Hausenblas


There isn't a direct equivalent to dependency with Kubernetes primitives, as a workaround you can implement a readiness probe that will render pod2 unusable until it sees pod1 up and running.

like image 39
itaysk Avatar answered Oct 01 '22 23:10

itaysk