Set custom variables using Kubernetes Legacy HiveMQ operator
This artical explains how to set custom variables using the Kubernetes operator. custom variables are nothing but additional properties specified in HiveMQCluster specification.
With the help of operator.templateConfigMap
and controllerTemplate
we can set custom variables.
Let's take the example of setting custom annotations with help of a custom variable.
Instructions
Generate default operator templates for configMap using the following steps.
$ helm template -s templates/hivemq-operator/operator-templates.yaml hivemq hivemq/hivemq-operator >> custom-template.yaml
Edit the
custom-template.yaml
to incorporate your changes which was generated by step 1apiVersion: v1 kind: ConfigMap metadata: name: <your custom template name> 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: mycustomValue: "{{ spec.customProperties.myCustomProperty }}"
Apply the config map by using the following command
$ kubectl apply -f <your custom template yaml filename>
Set templateConfigMap config in
values.yaml
of Kubernetes operatoroperator: deployCr: false templateConfigMap: <configmap name you created in step3 > ...
Execute helm upgrade / install the operator with the following command.
$ helm upgrade --install -f values.yaml <cluster name> hivemq/hivemq-operator
Add custom controller template in HiveMQ cluster yaml. This will refer to the custom template which was created and configured in step 1 and step 2 respectively.
apiVersion: hivemq.com/v1 kind: HiveMQCluster metadata: name: hivemq-cluster spec: controllerTemplate: "cluster-deployment.yaml" customProperties: myCustomProperty: "testvalue" ...
Deploy HiveMQ cluster with the following command
$ kubectl apply -f < hivemq cluster.yaml
You can check your changes are applied correctly or not by executing the following command
$ kubectl get pods $ kubectl describe pod <one of running pod name>
The output of the describe command will include changes.
Please refer following output as an example.Name: hivemq-cluster1123-6fd545799f-4xnc5 Namespace: XXXXX Priority: 0 Node: node11/10.2.1.218 Start Time: Mon, 31 May 2021 11:39:10 +0200 Labels: app=hivemq hivemq-cluster=hivemq-cluster1123 hivemq.com/node-offline=false pod-template-hash=6fd545799f Annotations: mycustomValue: test123 Status: Running ...