strimzi-drain-cleaner
by pierreneter
Utility which helps with moving the Apache Kafka pods deployed by Strimzi from Kubernetes nodes which are being drained.
About this chart
Strimzi Drain Cleaner
Strimzi Drain Cleaner is a utility which helps with moving the Apache Kafka® pods deployed by Strimzi from Kubernetes nodes which are being drained. It is useful if you want the Strimzi operator to move the pods instead of Kubernetes itself. The advantage of this approach is that the Strimzi operator makes sure that no partition replicas become under-replicated during the node draining. To use it:
- Configure your Kafka topics to have replication factor higher than 1 and make sure the
min.insync.replicasis always set to a number lower than the replication factor. Availability of topics with replication factor1or withmin.insync.replicasset to the same value as the replication factor will always be affected when the brokers are restarted. - Deploy Kafka using Strimzi.
apiVersion: kafka.strimzi.io/v1
kind: KafkaNodePool
metadata:
name: controller
labels:
strimzi.io/cluster: my-cluster
spec:
replicas: 3
roles:
- controller
storage:
type: jbod
volumes:
- id: 0
type: persistent-claim
size: 100Gi
deleteClaim: false
# Uncomment when using the legacy mode
# template:
# podDisruptionBudget:
# maxUnavailable: 0
---
apiVersion: kafka.strimzi.io/v1
kind: KafkaNodePool
metadata:
name: broker
labels:
strimzi.io/cluster: my-cluster
spec:
replicas: 3
roles:
- broker
storage:
type: jbod
volumes:
- id: 0
type: persistent-claim
size: 100Gi
deleteClaim: false
# Uncomment when using the legacy mode
# template:
# podDisruptionBudget:
# maxUnavailable: 0
---
apiVersion: kafka.strimzi.io/v1
kind: Kafka
metadata:
name: my-cluster
spec:
kafka:
listeners:
- name: plain
port: 9092
type: internal
tls: false
- name: tls
port: 9093
type: internal
tls: true
config:
offsets.topic.replication.factor: 3
transaction.state.log.replication.factor: 3
transaction.state.log.min.isr: 2
entityOperator:
topicOperator: {}
userOperator: {}
- Deploy the Strimzi Drain Cleaner
- Drain the node with some Kafka broker or controller pods using the
kubectl draincommand
How does it work?
Strimzi Drain Cleaner uses Kubernetes Admission Control features and Validating Web-hooks to find out when something tries to evict the Kafka broker or controller pods.
When it receives the eviction request for one of the Strimzi managed Kafka broker or controller pods, it annotates them with the strimzi.io/manual-rolling-update annotation which will tell Strimzi Cluster Operator that this pod needs to be restarted and denies the eviction request.
Denying the eviction request prevents Kubernetes from restarting the Pod on their own based only on the PodDisruptionBudget configuration and leaves it to the Strimzi Cluster operator.
Strimzi Cluster Operator will roll it in the next reconciliation using its algorithms which make sure the cluster is available while the Pod is restarted.
Strimzi Cluster Operator will always roll the pods one-by-one regardless of the Pod Disruption Policy settings.
This is supported from Strimzi 0.21.0.
Legacy mode
Different Kubernetes distributions and tools might react differently to the eviction request being denied. If the tools used by your Kubernetes cluster do not handle it well, you can switch the Drain Cleaner into a legacy mode where the eviction requests will be allowed. To do so, you have to:
- Edit the Drain Cleaner
Deploymentand set theSTRIMZI_DENY_EVICTIONenvironment variable tofalse. - Configure the
PodDisruptionBudgetsfor the Kafka brokers and controllers to havemaxUnavailableset to0. You can configure this in theKafkaNodePoolcustom resources inspec.template.podDisruptionBudget.maxUnavailable.
Once running in the legacy mode, the Drain Cleaner will still annotate the pods with the strimzi.io/manual-rolling-update annotation.
But it will allow the eviction request.
The eviction request will be ignored by Kubernetes because of the PodDisruptionBudget having maxUnavailable set to 0 and the Pod will be rolled by the Strimzi Cluster Operator.
See it in action
You can easily test how it works:
- Install Strimzi on your cluster
- Deploy Kafka cluster
- Install the Drain Cleaner
- Drain one of the Kubernetes nodes with one of the Kafka broker or controller pods
kubectl drain <worker-node> --delete-emptydir-data --ignore-daemonsets --timeout=6000s --force - Watch how it works:
- The
kubectl draincommand will cordon the worker node and trigger the eviction of the Kafka broker and controller pods running on it. It will evict the Pods that can be evicted and eventually fail because Drain Cleaner denied the eviction of the Kafka broker and controller podskubectl drain <worker-node> --delete-emptydir-data --ignore-daemonsets --timeout=6000s <worker-node> cordoned evicting pod myproject/my-cluster-kafka-1 evicting pod myproject/my-cluster-entity-operator-8499d956cb-r8b5t ... pod/my-cluster-entity-operator-8499d956cb-r8b5t evicted ... There are pending pods in node "<worker-node>" when an error occurred: error when evicting pods/"my-cluster-kafka-1" -n "myproject": admission webhook "strimzi-drain-cleaner.strimzi.io" denied the request: The pod will be rolled by the Strimzi Cluster Operator pod/my-cluster-controllers-1 error: unable to drain node "<worker-node>" due to error:error when evicting pods/"my-cluster-kafka-1" -n "myproject": admission webhook "strimzi-drain-cleaner.strimzi.io" denied the request: The pod will be rolled by the Strimzi Cluster Operator, continuing command... There are pending nodes to be drained: <worker-node> error when evicting pods/"my-cluster-kafka-1" -n "myproject": admission webhook "strimzi-drain-cleaner.strimzi.io" denied the request: The pod will be rolled by the Strimzi Cluster Operator - The Drain Cleaner log should show how it gets the eviction events
- Strimzi Cluster Operator log should show how it rolls the pods which are being evicted
- Once the Pods are restarted, you can retry the
kubectl draincommand and it should succeedkubectl drain <worker-node> --delete-emptydir-data --ignore-daemonsets --timeout=6000s <worker-node> already cordoned Warning: ignoring DaemonSet-managed Pods: ... <worker-node> drained
- The
Getting help
If you encounter any issues while using Strimzi, you can get help using:
Contributing
You can contribute by raising any issues you find and/or fixing issues by opening Pull Requests. All bugs, tasks or enhancements are tracked as GitHub issues.
The development documentation describe how to build, test and release Strimzi Drain Cleaner.
License
Strimzi is licensed under the Apache License, Version 2.0
Installing the Chart
To install the chart with the release name my-strimzi-drain-cleaner:
$ helm install my-strimzi-drain-cleaner oci://quay.io/strimzi-helm/strimzi-drain-cleaner
The command deploys the Strimzi Drain Cleaner on the Kubernetes cluster with the default configuration. It expects Cert Manager to be installed to issue the TLS certificates. The configuration section lists the parameters that can be configured during installation.
Uninstalling the Chart
To uninstall/delete the my-strimzi-drain-cleaner deployment:
$ helm delete my-strimzi-drain-cleaner
The command removes all the Kubernetes components associated with the Drain Cleaner utility and deletes the release.
Configuration
The following table lists the configurable parameters of the Strimzi Drain Cleaner chart and their default values.
For the full default configuration, check the values.yaml file.
| Parameter | Description | Default |
|---|---|---|
replicaCount | Number of replicas of the Drain Cleaner webhook | 1 |
nameOverride | Override the name of the chart (used in the resource names) | "" |
fullnameOverride | Override the fully qualified name of the chart (used in the resource names) | "" |
image.registry | Override default Drain Cleaner image registry | quay.io |
image.repository | Override default Drain Cleaner image repository | strimzi |
image.name | Drain Cleaner image name | drain-cleaner |
image.tag | Override default Drain Cleaner image tag | 1.8.0 |
image.pullPolicy | Image pull policy for the Drain Cleaner Pod | nil |
image.imagePullSecrets | List of Docker registry pull secrets | [] |
serviceAccount.create | Specifies whether a service account should be created | true |
serviceAccount.annotations | Annotations to add to the service account | {} |
serviceAccount.name | The name of the service account to use (generated using the fullname template when not set) | "" |
certManager.create | Enables or disables the creation of cert-manager resources (Issuer and Certificate) used to secure the Drain Cleaner webhook. | true |
certManager.duration | Configures |
Deploy strimzi-drain-cleaner with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has strimzi-drain-cleaner on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartstrimzi-drain-cleaner is pinned at v1.8.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply