- 官网
https://docs.bitnami.com/kubernetes/infrastructure/etcd/get-started/install/
https://bitnami.com/stacks/helm
https://bitnami.com/stack/kafka/helm
- 添加helm
helm repo add bitnami https://charts.bitnami.com/bitnami
拉取包
helm pull bitnami/kafka --untar
- 添加全局存储
- 编译 vim kafka/values.yaml
global:
imageRegistry: ""
imagePullSecrets: []
storageClass: "nfs-ok"
#你的storageClass
kafka-0 1/1 Running 0 20m
kafka-1 1/1 Running 0 19m
kafka-2 1/1 Running 0 19m
kafka-client 1/1 Running 0 13m
kafka-zookeeper-0 1/1 Running 0 20m
kafka-zookeeper-1 1/1 Running 0 19m
kafka-zookeeper-2 1/1 Running 0 19m
- 测试发送
kubectl exec -it kafka-0 -- kafka-console-producer.sh --broker-list kafka-0.kafka-headless.default.svc.cluster.local:9092 --topic test
- 另外启动终端测试
kubectl exec -it kafka-0 -- kafka-console-consumer.sh --bootstrap-server kafka.default.svc.cluster.local:9092 --topic test --from-beginning
- 可以使用官网提供的demon
[root@master240 nnn]# helm install kafka kafka/
NAME: kafka
LAST DEPLOYED: Thu Sep 9 14:50:11 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
** Please be patient while the chart is being deployed **
Kafka can be accessed by consumers via port 9092 on the following DNS name from within your cluster:
kafka.default.svc.cluster.local
Each Kafka broker can be accessed by producers via port 9092 on the following DNS name(s) from within your cluster:
kafka-0.kafka-headless.default.svc.cluster.local:9092
To create a pod that you can use as a Kafka client run the following commands:
kubectl run kafka-client --restart='Never' --image docker.io/bitnami/kafka:2.8.0-debian-10-r84 --namespace default --command -- sleep infinity
kubectl exec --tty -i kafka-client --namespace default -- bash
PRODUCER:
kafka-console-producer.sh \
--broker-list kafka-0.kafka-headless.default.svc.cluster.local:9092 \
--topic test
CONSUMER:
kafka-console-consumer.sh \
--bootstrap-server kafka.default.svc.cluster.local:9092 \
--topic test \
--from-beginning
- 导出模板
helm template kafka --name-template my > kafka-test.yaml
- 可以使用以下方式
helm install kafka bitnami/kafka \
--set replicaCount=3 \
--set persistence.enabled=true \
--set global.storageClass=nfs-ok \
--set persistence.size=8Gi \
--set service.type=NodePort
#某些场景需要加--set statefulset.replicaCount=3