curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sh -
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sh -
Fahren wir in einem neuen Verzeichnis fort und erstellen auch einen separaten Namespace für den Strimzi-Operator:
mkdir ~/strimzi
cd ~/strimzi
kubectl create namespace strimzi-operator
kubectl create namespace kafka
Jetzt laden wir die Strimzi CRDs und den Operator herunter und passen die Namespace-Konfiguration an, damit der Operator im Namespace strimzi-operator
läuft:
wget https://github.com/strimzi/strimzi-kafka-operator/releases/download/0.40.0/strimzi-crds-0.40.0.yaml -O strimzi-crds.yaml
wget https://github.com/strimzi/strimzi-kafka-operator/releases/download/0.40.0/strimzi-cluster-operator-0.40.0.yaml -O strimzi-cluster-operator.yaml
sed -i 's/namespace: .*/namespace: strimzi-operator/' strimzi-cluster-operator.yaml
Wir möchten, dass der Strimzi-Operator alle Namespaces überwacht, damit wir auch mehrere Kafka-Cluster pro Kubernetes starten können.
Allerdings müssen wir dafür das Strimzi-Deployment anpassen. Ersetze dazu die folgenden Zeilen in der Datei strimzi-cluster-operator.yaml
:
strimzi-cluster-operator.yaml
# Alt (für mich Zeile 7452
env:
- name: STRIMZI_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
# Neu
env:
- name: STRIMZI_NAMESPACE
value: "*"
Der Operator benötigt einige zusätzliche Rechte, die im Deployment nicht verfügbar sind:
kubectl create clusterrolebinding strimzi-cluster-operator-namespaced --clusterrole=strimzi-cluster-operator-namespaced --serviceaccount strimzi-operator:strimzi-cluster-operator
kubectl create clusterrolebinding strimzi-cluster-operator-watched --clusterrole=strimzi-cluster-operator-watched --serviceaccount strimzi-operator:strimzi-cluster-operator
kubectl create clusterrolebinding strimzi-cluster-operator-entity-operator-delegation --clusterrole=strimzi-entity-operator --serviceaccount strimzi-operator:strimzi-cluster-operator
Jetzt können wir die CRDs und den Operator installieren:
kubectl apply -f strimzi-crds.yaml
kubectl apply -f strimzi-cluster-operator.yaml -n strimzi-operator
Warte einen Moment, bis der Operator bereit ist:
kubectl get pods -n strimzi-operator -w
Wir möchten nun den Kafka-Cluster "richtig" mit KRaft einrichten:
3 KRaft-Controller mit je 5GB Arbeitsspeicher
3 Kafka-Broker mit je 50GB Arbeitsspeicher
Dazu erstellen wir einen Node-Pool sowohl für die Controller als auch für die Broker:
kafka-controller-pool.yaml
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaNodePool
metadata:
name: controller
namespace: kafka
labels:
strimzi.io/cluster: kafka
spec:
replicas: 3
roles:
- controller
storage:
type: jbod
volumes:
- id: 0
type: persistent-claim
size: 5Gi
deleteClaim: false
kafka-broker-pool.yaml
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaNodePool
metadata:
name: broker
namespace: kafka
labels:
strimzi.io/cluster: kafka
spec:
replicas: 3
roles:
- broker
storage:
type: jbod
volumes:
- id: 0
type: persistent-claim
size: 50Gi
deleteClaim: false
Schließlich die Ressourcen für den Kafka-Cluster selbst:
kafka-cluster.yaml
apiVersion: kafka.strimzi.io/v1beta2
kind: Kafka
metadata:
name: kafka
namespace: kafka
annotations:
strimzi.io/node-pools: enabled
strimzi.io/kraft: enabled
spec:
kafka:
version: 3.7.0
listeners:
- name: plain
port: 9092
type: internal
tls: false
config:
offsets.topic.replication.factor: 3
transaction.state.log.replication.factor: 3
transaction.state.log.min.isr: 2
default.replication.factor: 3
min.insync.replicas: 2
entityOperator:
topicOperator: {}
userOperator: {}
Nun können wir die Ressourcen erstellen:
# Wir sind immer noch im Namespace kafka
kubectl apply -f kafka-controller-pool.yaml
kubectl apply -f kafka-broker-pool.yaml
kubectl apply -f kafka-cluster.yaml
Betrachte die Kafka-Ressource genauer und warte dann, bis die Pods gestartet sind:
kubectl config set-context --current --namespace=kafka
kubectl describe kafka kafka
kubectl get pods -w