3

I am trying to create a Helm chart (x) with 5 deployments within chart (x) in a specific order:

  1. Deployment 1 ( zk)
  2. Deployment 2 (security)
  3. Deployment 3 (localmaster)
  4. Deployment 4 (nginx)
  5. Deployment 5 (semoss)

Helm/Tiller version: "v2.12.3" Kubectl version: Major:"1", Minor:"17" Minikube version: v1.6.2

What I currently have: RESOURCES: ==> v1/Deployment

NAME

  1. Localmaster
  2. Nginx
  3. Security
  4. Semoss
  5. Zk

I can easily deploy chart (x) but once I run helm ls, my (x) chart is in a random order as you can see above. I only have one chart name (x) and within (x) I have:

Chart.yaml charts templates values.yaml

Templates and charts are directories and the rest are files. Is there a specific way or trick to have my x (chart) in the order I want? I’ve done some research and I am not so sure if helm spray in the right call as I am trying to deploy 1 chart with different deployment as opposed to an umbrella chart, and many other sub-charts. Let me know if you need more info.

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
Karl Diji
  • 103
  • 1
  • 6
  • Why do they need to be deployed in that order? What will happen if they all do get deployed, but in the opposite order? (Typically a pod will fail and restart if its dependencies aren't there, but given enough time everything will come up.) – David Maze Jan 09 '20 at 01:53
  • 1
    Check this: https://stackoverflow.com/questions/51957676/helm-install-in-certain-order – Rafał Leszko Jan 09 '20 at 07:55
  • Thanks for the feedback @David Maze. It has to be deployed in this order because (zookeeper "zk" - "security"- "lm") all have dependencies so dependent from each other so must come up first. "Nginx" only depend on "zk", and the actual app "semoss" depends on all of them so comes last. This is the architecture I would like to have. So technically speaking, I don't really care about the order of those 3 deployments (zookeeper "zk" - "security"- "lm") as long as they are deployed first. Once they are up, now the rest of the deployments should be ordered as indicated above. – Karl Diji Jan 09 '20 at 15:07

1 Answers1

11

Helm is package manager, allows you to define applications as a set of components on your cluster, and provides mechanisms to manage those sets from start to end.

Helm itself its not creating pods, it send requests to Kubernetes api and then Kubernetes is creating everything.

I have one idea how it can be achieve using Helm.

Helm order of deploying Kinds is hardcoded here. However if you want to set deploying order of the same kind to k8s, it can be done using annotations.

You could set annotations: Pre-install hook with hook-weight like in this example (lower value in hook-weight have higher priority). Similar case can be found on Github.

It would look like example below:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    helm.sh/hook: pre-install
    helm.sh/hook-weight: "10"
  labels:
    app.kubernetes.io/instance: test
...

You can check which deployment was created first using kubectl get events. However, creation of pods is still scheduled by Kubernetes.

To obtain exactly what you need you can use initContainers and hardcode "sleep" command.
First deployment with sleep 1s, second deployment with 5s, third with 10s, depends how long deployment need to create all pods.

You can check this article, but keep in mind spec.containers and spec.initContainers are two different things.

PjoterS
  • 12,841
  • 1
  • 22
  • 54
  • thanks for the feedback. That helps. I am reading about helm hooks and hooks weight and a bit confused. I currently have all deployment.yamls and services.yamls in my template dir. Does it mean that I need to create a hook.yaml for each one of my service I noted above, or, just inject the hook annotations ("helm.sh/hook": pre-install & "helm.sh/hook-weight": "#") in each one of my deployment.yaml?? – Karl Diji Jan 14 '20 at 20:39
  • Unfortunately, you need specify in each deployment initContainer with sleep and hook weight. Are you using liveness readiness probes in your deployment? – PjoterS Jan 15 '20 at 08:22
  • It worked! you are my hero! SHOUKRANNN,. I actually did not use an init, I just injected the hooks annotations with the weights (-5, -5, -5, 0, 5) , even though my services were listed in alphabetical order after "kubectl get pods", they were deployed in the order I wanted. :) how magical.... Related to the liveness I was getting some error with it on my nginx pod which threw me off with some CrashloopBackOff error. What I did to get around it, I just removed the values on the liveness fields, (uncomment them didn't work), and I used a different tag for my nginx image and it's fine now.. – Karl Diji Jan 15 '20 at 14:38
  • 1
    Glad to hear it worked. If my answer was helpful you can accept it. It will be more visible if someone will want to do similar thing. – PjoterS Jan 15 '20 at 14:48