# Deploying Kafka Clusters with TLS on Kubernetes using Koperator and Helm ![Kafka Operator Architecture](https://raw.githubusercontent.com/banzaicloud/koperator/master/docs/img/kafka-operator-arch.png) The [CNCF Landscape](https://landscape.cncf.io/) is a great resource for anything you want to run in kubernetes. There's many streaming and messaging options, and today I want to deploy a tls-secured Kafka cluster using [Koperator](https://banzaicloud.com/docs/supertubes/kafka-operator/install-kafka-operator/). ## Prerequisites ```{eval-rst} Choosing Kubernetes means your organization is signing up for an ever-changing ecosystem, and this guide will likely be dated in the coming years. ``` ### Minikube I'm running a minikube cluster on kubernetes `1.24.3` with `48` CPUs and `128` GB ram. ```bash minikube profile list -o json | jq -r '.valid[0].Config | "cpus: " + (.CPUs | tostring) + " memory: " + (.Memory | tostring)' cpus: 48 memory: 128000 ``` ```bash kubectl get nodes | grep minikube minikube Ready control-plane 13d v1.24.3 ``` ### Helm I'm using helm ``3.9.3``: ```bash helm version --short v3.9.3+g414ff28 ``` ## Getting Started ### Zookeeper ```{eval-rst} .. note:: Previously Kafka helm charts bundled Zookeeper into the same helm chart as the Kafka cluster, but Koperator does not recommend that approach. Instead you have to deploy and manage Zookeeper separately. ``` #### Install ```{eval-rst} .. note:: By default the Zookeeper operator will manage any ``zookeepercluster`` objects in any namespace ``` ```bash helm repo add pravega https://charts.pravega.io helm repo update helm upgrade --install zookeeper-operator --namespace=zookeeper --create-namespace pravega/zookeeper-operator ``` Output: ```bash "pravega" has been added to your repositories Hang tight while we grab the latest from your chart repositories... ...Successfully got an update from the "pravega" chart repository Update Complete. ⎈Happy Helming!⎈ NAME: zookeeper-operator LAST DEPLOYED: Wed Sep 7 14:15:22 2022 NAMESPACE: zookeeper STATUS: deployed REVISION: 1 TEST SUITE: None ``` #### Deploy the Zookeeper Cluster ```bash kubectl create --namespace zookeeper -f - < tls.key kubectl get secret -n dev -o yaml dev-kafka-server-certificate | grep tls.crt | awk '{print $NF}' | base64 -d > tls.crt kubectl get secret -n dev -o yaml dev-kafka-server-certificate | grep ca.crt | awk '{print $NF}' | base64 -d > ca.crt ``` **Verify TLS works with OpenSSL on the Kafka NodePort** ```bash openssl s_client -connect dev-kafka-all-broker.dev.svc.cluster.local:32000 -key ./tls.key -cert ./tls.crt -CAfile ./ca.crt -verify_return_error ``` ```{eval-rst} .. note:: If you do not have a real dns set up, then please ensure ``/etc/hosts`` assigns your minikube ip (``192.168.49.2`` by default) to ``dev-kafka-all-broker.dev.svc.cluster.local`` ``` 1. Are Zookeeper's install upgrade pods failing with an `Error` state? If your Zookeeper pods got stuck, please delete the job: ```bash zookeeper zookeeper-operator-post-install-upgrade-2bgjb 0/1 Error 0 3m14s zookeeper zookeeper-operator-post-install-upgrade-9grpk 0/1 Error 0 4m56s zookeeper zookeeper-operator-post-install-upgrade-bttph 0/1 Error 0 6m38s zookeeper zookeeper-operator-post-install-upgrade-bvdgh 0/1 Error 0 3m48s zookeeper zookeeper-operator-post-install-upgrade-gsnd9 0/1 Error 0 2m6s zookeeper zookeeper-operator-post-install-upgrade-jqzd4 0/1 Error 0 2m40s zookeeper zookeeper-operator-post-install-upgrade-n24lg 0/1 Error 0 58s zookeeper zookeeper-operator-post-install-upgrade-nf9jz 0/1 Error 0 4m22s zookeeper zookeeper-operator-post-install-upgrade-t4r8r 0/1 Error 0 5m30s zookeeper zookeeper-operator-post-install-upgrade-vbpcm 0/1 Error 0 6m5s zookeeper zookeeper-operator-post-install-upgrade-vrkx2 0/1 Error 0 92s ``` ```bash kubectl delete job -n zookeeper zookeeper-operator-post-install-upgrade ``` ## Uninstall ### Uninstall Kafka Cluster ```bash kubectl delete -n kafka -f https://raw.githubusercontent.com/jay-johnson/koperator/nodeport-with-headless-example/config/samples/simplekafkacluster-with-nodeport.yaml ``` ### Uninstall Koperator ```{eval-rst} .. note:: This will hang if there are any ``kafkaclusters`` still in use ``` ```bash helm delete -n kafka kafka-operator ``` ### Uninstall Zookeeper Cluster ```bash kubectl delete -n zookeeper zookeeperclusters zookeeper ``` ### Uninstall Zookeeper Operator ```{eval-rst} .. note:: This will hang if there are any ``zookeeperclusters`` still in use ``` ```bash helm delete -n zookeeper zookeeper-operator kubectl delete crd zookeeperclusters.zookeeper.pravega.io ``` ## Sources 1. For those that want to refer to the official docs, I followed the [Install the Kafka Operator guide](https://banzaicloud.com/docs/supertubes/kafka-operator/install-kafka-operator/).