Add custom annotations in Legacy HiveMQ Kubernetes operator

This article explains how to add custom annotations to pods in the Kubernetes operator.

By default, there is no way to add custom annotations through helm charts for pods hence we will be using operator.templateConfigMap to add custom annotations.

Prerequisite

Make sure to select the correct namespace where you want to deploy HiveMQ

Instructions

  1. Generate default operator templates for configMap using the following command.

    • $ helm template -s templates/hivemq-operator/operator-templates.yaml hivemq hivemq/hivemq-operator >> custom-template.yaml

       

  2. Edit the custom-template.yaml which was generated by step1.

    1. You can add the annotations / other changes either in the custom-template.yaml

      • change the configMap name (in example its set as )

      • Search for block cluster-deployment.yaml and inside this block look for spec and template block

      • add annotations inside metadata block

        apiVersion: v1 kind: ConfigMap metadata: name: "custom-template" data: cluster-daemon-set.yaml: |- ... cluster-deployment.yaml: |- apiVersion: apps/v1 kind: Deployment metadata: name: "{{ spec.name }}" namespace: "{{ spec.namespace }}" ... spec: minReadySeconds: 30 ... template: metadata: labels: app: "hivemq" hivemq-cluster: "{{ spec.name }}" hivemq.com/node-offline: "false" annotations: prometheus.io/path: /metrics prometheus.io/port: "9100" prometheus.io/scrape: "true" ... spec: initContainers: - name: "init-shared" resources: ... ...

         

  3. Apply the config map by using the following command

    $ kubectl apply -f <your custom template yaml filename>
    1. You can verify the created configMap and its values by using the following command

       

  4. set templateConfigMap config in values.yaml of Kubernetes operator

  5. Execute helm upgrade / install the operator with the following command.

    1. Here <cluster name> is the one you have used during HiveMQ deployment while installing the helm chart. 

    2. Verify custom annotation with the following commands