Usage

If you are not installing the operator using Helm then after installation the CRD for this operator must be created:

kubectl apply -f /etc/stackable/zookeeper-operator/crd/zookeepercluster.crd.yaml

To create a three-node Apache ZooKeeper cluster you can use the example shown below.

Please note that the version you need to specify is not only the version of ZooKeeper which you want to roll out, but has to be amended with a Stackable version as shown. This Stackable version is the version of the underlying container image which is used to execute the processes. For a list of available versions please check our image registry. It should generally be safe to simply use the latest image version that is available.

---
apiVersion: zookeeper.stackable.tech/v1alpha1
kind: ZookeeperCluster
metadata:
  name: simple-zk
spec:
  version: 3.8.0-stackable0.7.1
  servers:
    roleGroups:
      default:
        replicas: 3
        config: {}

Afterwards, a ZNode can be created:

---
apiVersion: zookeeper.stackable.tech/v1alpha1
kind: ZookeeperZnode
metadata:
  name: simple-znode
spec:
  clusterRef:
    name: simple-zk
    namespace: default

Finally, a ConfigMap is created, containing a path that a ZooKeeper client can connect to:

$ kubectl get configmap simple-znode-nodeport -o yaml
$ $ZOOKEEPER_HOME/bin/zkCli.sh -server $(kubectl get configmap simple-znode-nodeport -o jsonpath='{.data.ZOOKEEPER}')

Encryption

The quorum and client communication are encrypted by default via TLS. This requires the Secret Operator to be present in order to provide certificates. The utilized certificates can be changed in a top-level config.

---
apiVersion: zookeeper.stackable.tech/v1alpha1
kind: ZookeeperCluster
metadata:
  name: simple-zk
spec:
  version: 3.8.0-stackable0.7.0
  config:
    tls:
      secretClass: tls (1)
    quorumTlsSecretClass: tls (2)
  servers:
    roleGroups:
      default:
        replicas: 3
1 The tls.secretClass refers to the client-to-server encryption. Defaults to the tls secret.
2 The quorumTlsSecretClass refers to the server-to-server quorum encryption. Defaults to the tls secret.

The tls secret is deployed from the Secret Operator and looks like this:

---
apiVersion: secrets.stackable.tech/v1alpha1
kind: SecretClass
metadata:
  name: tls
spec:
  backend:
    autoTls:
      ca:
        secret:
          name: secret-provisioner-tls-ca
          namespace: default
        autoGenerate: true

You can create your own secrets and reference them e.g. in the tls.secretClass to use different certificates.

Authentication

The quorum or server-to-server communication is authenticated via TLS per default. In order to enforce TLS authentication for client-to-server communication, you can set an AuthenticationClass reference in the custom resource provided by the Commons Operator.

---
apiVersion: zookeeper.stackable.tech/v1alpha1
kind: ZookeeperCluster
metadata:
  name: simple-zk
spec:
  version: 3.8.0-stackable0.7.0
  config:
    clientAuthentication:
      authenticationClass: zk-client-tls (1)
    quorumTlsSecretClass: tls
  servers:
    roleGroups:
      default:
        replicas: 3
---
apiVersion: authentication.stackable.tech/v1alpha1
kind: AuthenticationClass
metadata:
  name: zk-client-tls (2)
spec:
  provider:
    tls:
      clientCertSecretClass: zk-client-auth-secret (3)
---
apiVersion: secrets.stackable.tech/v1alpha1
kind: SecretClass
metadata:
  name: zk-client-auth-secret (4)
spec:
  backend:
    autoTls:
      ca:
        secret:
          name: secret-provisioner-tls-zk-client-ca
          namespace: default
        autoGenerate: true
1 The config.clientAuthentication.authenticationClass can be set to use TLS for authentication. This is optional.
2 The referenced AuthenticationClass that references a SecretClass to provide certificates.
3 The reference to a SecretClass.
4 The SecretClass that is referenced by the AuthenticationClass in order to provide certificates.

If both spec.config.tls.secretClass and spec.config.clientAuthentication.authenticationClass are set, the authentication class will take precedence over the secret class. The cluster will be encrypted and authenticate only against the authentication class.

Due to a bug in ZooKeeper, the clientPort property in combination with client.portUnification=true is used instead of the secureClientPort. This means that unencrypted and unauthenticated access to the ZooKeeper cluster is still possible.

Monitoring

The managed ZooKeeper instances are automatically configured to export Prometheus metrics. See Monitoring for more details.

Configuration & Environment Overrides

The cluster definition also supports overriding configuration properties and environment variables, either per role or per role group, where the more specific override (role group) has precedence over the less specific one (role).

Overriding certain properties which are set by operator (such as the ports) can interfere with the operator and can lead to problems.

Configuration Properties

For a role or role group, at the same level of config, you can specify: configOverrides for the zoo.cfg. For example, if you want to set the 4lw.commands.whitelist to allow the ruok administrative command, it can be configured in the ZookeeperCluster resource like so:

servers:
  roleGroups:
    default:
      configOverrides:
        zoo.cfg:
          4lw.commands.whitelist: "srvr, ruok"
      replicas: 1

Just as for the config, it is possible to specify this at role level as well:

routers:
  configOverrides:
    zoo.cfg:
      4lw.commands.whitelist: "srvr, ruok"
  roleGroups:
    default:
      replicas: 1

All override property values must be strings.

For a full list of configuration options we refer to the Apache ZooKeeper Configuration Reference.

Environment Variables

In a similar fashion, environment variables can be (over)written. For example per role group:

servers:
  roleGroups:
    default:
      envOverrides:
        MY_ENV_VAR: "MY_VALUE"
      replicas: 1

or per role:

servers:
  envOverrides:
    MY_ENV_VAR: "MY_VALUE"
  roleGroups:
    default:
      replicas: 1

Storage for data volumes

You can mount volumes where data is stored by specifying PersistentVolumeClaims for each individual role group:

servers:
  roleGroups:
    default:
      config:
        resources:
          storage:
            data:
              capacity: 2Gi

In the above example, all ZooKeeper nodes in the default group will store data (the location of the property dataDir) on a 2Gi volume.

By default, in case nothing is configured in the custom resource for a certain role group, each Pod will have a 1Gi large local volume mount for the data location.

Resource Requests

Stackable operators handle resource requests in a sligtly different manner than Kubernetes. Resource requests are defined on role or group level. See Roles and role groups for details on these concepts. On a role level this means that e.g. all workers will use the same resource requests and limits. This can be further specified on role group level (which takes priority to the role level) to apply different resources.

This is an example on how to specify CPU and memory resources using the Stackable Custom Resources:

---
apiVersion: example.stackable.tech/v1alpha1
kind: ExampleCluster
metadata:
  name: example
spec:
  workers: # role-level
    config:
      resources:
        cpu:
          min: 300m
          max: 600m
        memory:
          limit: 3Gi
    roleGroups: # role-group-level
      resources-from-role: # role-group 1
        replicas: 1
      resources-from-role-group: # role-group 2
        replicas: 1
        config:
          resources:
            cpu:
              min: 400m
              max: 800m
            memory:
              limit: 4Gi

In this case, the role group resources-from-role will inherit the resources specified on the role level. Resulting in a maximum of 3Gi memory and 600m CPU resources.

The role group resources-from-role-group has maximum of 4Gi memory and 800m CPU resources (which overrides the role CPU resources).

For Java products the actual used Heap memory is lower than the specified memory limit due to other processes in the Container requiring memory to run as well. Currently, 80% of the specified memory limits is passed to the JVM.

For memory only a limit can be specified, which will be set as memory request and limit in the Container. This is to always guarantee a Container the full amount memory during Kubernetes scheduling.

If no resource requests are configured explicitly, the ZooKeeper operator uses the following defaults:

servers:
  roleGroups:
    default:
      config:
        resources:
          memory:
            limit: '512Mi'
          cpu:
            max: '4'
            min: '500m'
          storage:
            data:
              capacity: '1Gi'