Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent for depends_on in kubernetes

I have a docker compose file with the following entries


version: '2.1'  services:   mysql:     container_name: mysql      image: mysql:latest      volumes:       - ./mysqldata:/var/lib/mysql      environment:        MYSQL_ROOT_PASSWORD: 'password'      ports:        - '3306:3306'      healthcheck:          test: ["CMD", "curl", "-f", "http://localhost:3306"]          interval: 30s          timeout: 10s          retries: 5     test1:      container_name: test1      image: test1:latest      ports:        - '4884:4884'        - '8443'      depends_on:        mysql:          condition: service_healthy      links:       - mysql  

The Test-1 container is dependent on mysql and it needs to be up and running.

In docker this can be controlled using health check and depends_on attributes. The health check equivalent in kubernetes is readinessprobe which i have already created but how do we control the container startup in the pod's?????

Any directions on this is greatly appreciated.

My Kubernetes file:

apiVersion: apps/v1beta1  kind: Deployment  metadata:    name: deployment  spec:    replicas: 1    template:      metadata:        labels:          app: deployment       spec:        containers:        - name: mysqldb          image: "dockerregistry:mysqldatabase"          imagePullPolicy: Always          ports:          - containerPort: 3306          readinessProbe:            tcpSocket:              port: 3306            initialDelaySeconds: 15            periodSeconds: 10        - name: test1          image: "dockerregistry::test1"          imagePullPolicy: Always          ports:          - containerPort: 3000  
like image 486
anish anil Avatar asked Mar 19 '18 16:03

anish anil


People also ask

What is maxSurge in Kubernetes?

maxSurge specifies the maximum number (or percentage) of pods above the specified number of replicas. In the example above, the maximum number of pods will be 5 since 4 replicas are specified in the yaml file. maxUnavailable declares the maximum number (or percentage) of unavailable pods during the update.

What is Kompose in Kubernetes?

Kompose (Kubernetes + Compose) kompose is a tool to help users who are familiar with docker-compose move to Kubernetes. kompose takes a Docker Compose file and translates it into Kubernetes resources. kompose is a convenience tool to go from local Docker development to managing your application with Kubernetes.

What is RollingUpdate in Kubernetes?

RollingUpdate implements automated, rolling updates for the Pods in the StatefulSet. RollingUpdate causes the controller to delete and recreate each of its Pod, and each Pod one at a time. It waits until an updated Pod is running and ready before to updating its predecessor.

What is imagePullSecrets in Kubernetes?

An imagePullSecrets is an authorization token, also known as a secret, that stores Docker credentials that are used for accessing a registry. The imagePullSecrets can be used when installing software that requires entitlement. Two formats are available for you to create an application from the management console.


1 Answers

That's the beauty of Docker Compose and Docker Swarm... Their simplicity.

We came across this same Kubernetes shortcoming when deploying the ELK stack. We solved it by using a side-car (initContainer), which is just another container in the same pod thats run first, and when it's complete, kubernetes automatically starts the [main] container. We made it a simple shell script that is in loop until Elasticsearch is up and running, then it exits and Kibana's container starts.

Below is an example of a side-car that waits until Grafana is ready.

Add this 'initContainer' block just above your other containers in the Pod:

spec:       initContainers:       - name: wait-for-grafana         image: darthcabs/tiny-tools:1         args:         - /bin/bash         - -c         - >           set -x;           while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://grafana:3000/login)" != "200" ]]; do              echo '.'             sleep 15;           done       containers:           .           .   (your other containers)           .           . 
like image 178
David Cardoso Avatar answered Sep 25 '22 15:09

David Cardoso