skyho
skyho

Reputation: 1903

How to ensure the order of deployment of Spring cloud applications?

There are several microservices (of the order of 5 or more) and they need to be launched in a certain order.

Deployment can be Kubernetes (As an example).

Is it possible to specify the launch of applications in a certain order ?

At the same time, the launch of the next application should be initiated when the previous application reported a successful start ?

Upvotes: 0

Views: 223

Answers (1)

Mike
Mike

Reputation: 481

Kubernetes doesn't have a feature that lets you deploy something in "order". However ArgoCD that manages the deployment of your applications can make this work with Sync Waves/Argo Hooks.

You could also just create a shell script that does this for you if you want an easy solution. You could include an init container that would check the previous applications health and then have it start.

Edit1: You could add a init container that checks the pod/service of the previous "application" with:

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app.kubernetes.io/name: MyApp
spec:
  containers:
  - name: myapp-container
    image: busybox:1.28
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"]
  - name: init-mydb
    image: busybox:1.28
    command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]

If a Pod's init container fails, the kubelet repeatedly restarts that init container until it succeeds. This way you could "wait" before the preceeding application is startet until the previous application is running.

Upvotes: 2

Related Questions