版本概況
服務(wù) | 版本 |
---|---|
centos | 7.9 |
kubernetes | v1.20.15 |
helm | v3.10.1 |
zookeeper | 3.8.1 |
kafka | 3.4.0 |
一、添加helm倉(cāng)庫(kù)
# 添加bitnami和官方helm倉(cāng)庫(kù):
helm repo add bitnami https://charts.bitnami.com/bitnami
# 查看倉(cāng)庫(kù)
helm repo list
二、安裝部署集群
安裝方式有兩種,在線安裝和離線安裝,在線安裝方便快捷,但是無(wú)法修改參數(shù)。由于需要修改配置,故本文采用離線安裝方式。
2.1 在線安裝zookeeper+kafka集群
1. 部署zookeeper集群
# 部署zookeeper集群
helm install zookeeper bitnami/zookeeper \
--set replicaCount=3 \
--set auth.enabled=false \
--set allowAnonymousLogin=true
# 查看
helm list
提示:
由于這個(gè)ApacheZookeeper集群不會(huì)公開(kāi),所以在部署時(shí)禁用了身份驗(yàn)證。對(duì)于生產(chǎn)環(huán)境,請(qǐng)考慮使用生產(chǎn)配置。
生產(chǎn)環(huán)境參考:https://github.com/bitnami/charts/tree/main/bitnami/zookeeper#production-configuration
2. 部署kafka集群
# 部署kafka集群
helm install kafka bitnami/kafka \
--set zookeeper.enabled=false \
--set replicaCount=3 \
--set externalZookeeper.servers=ZOOKEEPER-SERVICE-NAME # ZOOKEEPER-SERVICE-NAME 替換為上一步結(jié)束時(shí)獲得的Apache ZOOKEEPER服務(wù)名稱
2.2 離線安裝zookeeper+kafka集群
由于在線安裝,zookeeper的pod起不來(lái),一直處于pending的狀態(tài),原因是因?yàn)閜vc存儲(chǔ)卷掛載的問(wèn)題,所以這里選擇把zookeeper和kafka的包下載下來(lái),修改配置文件,然后進(jìn)行離線安裝。
我這里將zookeeper和kafka安裝在default命名空間下,如果您想按在指定namespace下,命令后加-n [namespace]
就可以了。
1. 下載離線包
# 創(chuàng)建存放壓縮包目錄
mkdir /bsm/zookeeper-kafka && cd /bsm/zookeeper-kafka
# 拉取壓縮包
helm pull bitnami/zookeeper
helm pull bitnami/kafka
# 解壓
tar -zvxf kafka-22.1.2.tgz
tar -zvxf zookeeper-11.4.1.tgz
2. 部署zookeeper集群
-
修改配置文件
values.yaml
主要修改內(nèi)容:enabled設(shè)為false ;注釋掉 storageClass: “”、existingClaim: “”
cd /bsm/zookeeper-kafka/zookeeper
vim values.yaml
# 修改配置文件,主要修改存儲(chǔ)storageclass(kafka的配置文件類(lèi)似)
persistence:
## @param persistence.enabled Enable ZooKeeper data persistence using PVC. If false, use emptyDir
##
enabled: false # 測(cè)試環(huán)境可設(shè)置為false
## @param persistence.existingClaim Name of an existing PVC to use (only when deploying a single replica)
##
# existingClaim: ""
## @param persistence.storageClass PVC Storage Class for ZooKeeper data volume
## If defined, storageClassName: <storageClass>
## If set to "-", storageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
## set, choosing the default provisioner. (gp2 on AWS, standard on
## GKE, AWS & OpenStack)
##
# storageClass: "" # 注釋掉storageClass。如果創(chuàng)建好了storageclass可打開(kāi)注釋?zhuān)?xiě)入storageClass的名稱
- 安裝zookeeper集群
# 安裝zookeeper
cd /bsm/zookeeper-kafka/zookeeper
helm install zookeeper --set replicaCount=3 --set auth.enabled=false --set allowAnonymousLogin=true ./
# ./ 表示zookeeper的value.yaml文件所在路徑
# 查看pod狀態(tài):
[root@k8s-master1 rabbitmq]# kubectl get pods
NAME READY STATUS RESTARTS AGE
zookeeper-0 1/1 Running 0 85s
zookeeper-1 1/1 Running 0 85s
zookeeper-2 1/1 Running 0 84s
3. 安裝kafka集群
-
修改配置文件
values.yaml
主要修改內(nèi)容:enabled設(shè)為false ;注釋掉 storageClass: “”、existingClaim: “”;kraft.enable 修改為 false
cd /bsm/zookeeper-kafka/kafka
vim values.yaml
修改一:
persistence:
## @param persistence.enabled Enable Kafka data persistence using PVC, note that ZooKeeper persistence is unaffected
##
enabled: false #改為false
## @param persistence.existingClaim A manually managed Persistent Volume and Claim
## If defined, PVC must be created manually before volume will be bound
## The value is evaluated as a template
##
# existingClaim: ""
## @param persistence.storageClass PVC Storage Class for Kafka data volume
## If defined, storageClassName: <storageClass>
## If set to "-", storageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
## set, choosing the default provisioner.
##
# storageClass: ""
## @param persistence.accessModes Persistent Volume Access Modes
修改二:
kraft:
## @param kraft.enabled Switch to enable or disable the Kraft mode for Kafka
##
enabled: false #改為false
## @param kraft.processRoles Roles of your Kafka nodes. Nodes can have 'broker', 'controller' roles or both of them.
##
processRoles: broker,controller
- 安裝 kafka 集群
# 安裝zookeeper
cd /bsm/zookeeper-kafka/kafka
helm install kafka --set zookeeper.enabled=false --set replicaCount=3 --set externalZookeeper.servers=ZOOKEEPER-SERVICE-NAME ./
# ZOOKEEPER-SERVICE-NAME 替換為上一步結(jié)束時(shí)獲得的Apache ZOOKEEPER服務(wù)名稱
# ./ 表示kafka的value.yaml文件所在路徑
# 查看:
[root@k8s-master1 kafka]# kubectl get pods
NAME READY STATUS RESTARTS AGE
kafka-0 1/1 Running 0 3m58s
kafka-1 1/1 Running 0 3m58s
kafka-2 1/1 Running 0 3m58s
報(bào)錯(cuò):
Error: INSTALLATION FAILED: execution error at (kafka/templates/NOTES.txt:314:4):
VALUES VALIDATION:
kafka: Kraft mode
You cannot use Kraft mode and Zookeeper at the same time. They are mutually exclusive. Disable zookeeper in ‘.Values.zookeeper.enabled’ and delete values from ‘.Values.externalZookeeper.servers’ if you want to use Kraft mode
原因:
新版kafka新增了一個(gè)kraft模式,他與zookeeper是沖突的,不能同時(shí)使用,所以如果使用指定的zookeeper,kraft模式要關(guān)閉。
解決辦法:
修改kafka的配置文件“value.yaml”,將 kraft.enable 的值改為false
三、驗(yàn)證kafka與zookeeper是否綁定
查看kafka日志中有以下信息:
kubectl logs -f kafka-0 | grep socket
四、測(cè)試集群
# 進(jìn)入kafka的pod創(chuàng)建一個(gè)topic
[root@k8s-master1 kafka]# kubectl exec -it kafka-0 bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
I have no name!@kafka-0:/$ kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic testtopic
heCreated topic testtopic.
# 啟動(dòng)一個(gè)消費(fèi)者
[root@k8s-master1 ~]# kubectl exec -it kafka-0 bash
I have no name!@kafka-0:/$ kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic testtopic
# 新開(kāi)一個(gè)窗口,進(jìn)入kafka的pod,啟動(dòng)一個(gè)生產(chǎn)者,輸入消息;在消費(fèi)者端可以收到消息
[root@k8s-master1 ~]# kubectl exec -it kafka-0 bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
I have no name!@kafka-0:/$ kafka-console-producer.sh --bootstrap-server localhost:9092 --topic testtopic
在生產(chǎn)者頁(yè)面輸入信息,可以在消費(fèi)者頁(yè)面查看到。
部署成功。
附:可改善地方
持久化存儲(chǔ),配置文件value.yaml中storageclass參數(shù)未設(shè)定,親和力未設(shè)定,測(cè)試環(huán)境要求沒(méi)有那么多,生產(chǎn)環(huán)境大家可以按需配置。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-483353.html
卸載應(yīng)用
helm uninstall kafka -n [namespace]
helm uninstall zookeeper -n [namespace]
參考文章:
bitnami官網(wǎng):https://docs.bitnami.com/tutorials/deploy-scalable-kafka-zookeeper-cluster-kubernetes
csdn文章:https://blog.csdn.net/heian_99/article/details/114840056文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-483353.html
到了這里,關(guān)于Helm方式部署 zookeeper+kafka 集群 ——2023.05的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!