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
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
Edit the
custom-template.yaml
which was generated by step1.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 forspec
andtemplate
blockadd 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: ... ...
Apply the config map by using the following command
$ kubectl apply -f <your custom template yaml filename>
You can verify the created configMap and its values by using the following command
set
templateConfigMap
config invalues.yaml
of Kubernetes operatorExecute helm upgrade / install the operator with the following command.
Here <cluster name> is the one you have used during HiveMQ deployment while installing the helm chart.
Verify custom annotation with the following commands