Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

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

    • Code Block
      languagebash
      $ helm template -s templates/hivemq-operator/operator-templates.yaml hivemq hivemq/hivemq-operator >> custom-template.yaml
  2. Edit the custom-template.yaml to incorporate your changes which was generated by step 1

    • Code Block
      apiVersion: 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 }}"
  3. Apply the config map by using the following command

    • Code Block
      $ kubectl apply -f <your custom template yaml filename>
  4. Set templateConfigMap config in values.yaml of Kubernetes operator

    • Code Block
      operator:
        deployCr: false  
        templateConfigMap: <configmap name you created in step3 >
        ...
  5. Execute helm upgrade / install the operator with the following command.

    • Code Block
      $ helm upgrade --install -f values.yaml <cluster name> hivemq/hivemq-operator
  6. 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.

    • Code Block
      apiVersion: hivemq.com/v1
      kind: HiveMQCluster
      metadata:
        name: hivemq-cluster
      spec:
        controllerTemplate: "cluster-deployment.yaml"
        customProperties:
          myCustomProperty: "testvalue"
      ... 
  7. Deploy HiveMQ cluster with the following command

    • Code Block
      $ kubectl apply -f < hivemq cluster.yaml 
  8. You can check your changes are applied correctly or not by executing the following command

    • Code Block
      $ 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.

      Code Block
      
      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
      ...

 

Filter by label (Content by label)
showLabelsfalse
max5
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@957
sortmodified
showSpacefalse
reversetrue
typepage
cqllabel = "kb-how-to-article" in ( "kubernetes" , "hivemq-operator" ) and type = "page" and space = "KB" and title ~ "Annotations"
labelskb-how-to-article