Search code examples
rabbitmqkubernetes-helmumbrella

Rabbitmq deployment using helm umbrella chart and rabbitmq operator with kubernetes


I am trying to deploy to a kubernetes cluster an umbrella chart that contains the rabbitmq operator + rabbitmq. So in total 2 sub-charts.

The operator sub-chart first deploys the CRD needed "kind: RabbitmqCluster" for the rabbitmq sub-chart and everything is installed correctly when I install the umbrella chart. I see 2 containers, the operator and an instance of rabbitmq.

The problem arises when I want to uninstall the umbrella chart (helm uninstall...), the rabbit operator is removed (since it has a "kind: Deployment") but not the rabbitmq instance that it has created. To do so, I need to manually run kubectl delete rabbitmqcluster name of instance.

Is there a way to do so when the helm uninstall is run or am I barking up the wrong tree?


Solution

  • One way to solve this is to use an annotation using a helm hook to transform a job into a pre-delete operation.

    Then in the spec part of the job, one can run kubectl commands if needed using a public image or whatever you like:

    containers:
          - name: kubectl
            image: "k8s.gcr.io/hyperkube:v1.12.1"
            imagePullPolicy: "IfNotPresent"
            command:
            - /bin/sh
            - -c
            - >
                kubectl delete rabbitmqcluster {{ .Release.Name }}-rabbitmq -n {{ .Release.Namespace }};
                sleep 10;