经过helm在k8s上部署kafka。zookeepernode
经过helm方法安装git
k8s上安装kafka,能够使用helm,将kafka做为一个应用安装。固然这首先要你的k8s支持使用helm安装。helm的介绍和参考见:https://yq.aliyun.com/articles/159601github
helm仓库地址https://github.com/helm/chartsshell
经过阿里仓库安装kafkabootstrap
helm repo add incubator https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator/ 安全
helm repo update 服务器
helm search kafkaapp
hlem fetch incubator/kafka # 下载tgz文件测试
tar zxf kafka-0.2.1.tgz && cd kafkafetch
把./charts/zookeeper/templates/statefulset.yaml中的zookeeper的镜像地址改成registry.cn-hangzhou.aliyuncs.com/appstore/k8szk:v2
将如下两个文件中的橘红色部分改成你的storageclass。
storageclass查询命令: kubectl get sc --all-namespaces
helm install ./ -n kafka --namespace xxx #安装
kubectl get pvc -n xxx #查看pvc状态
kubectl describe pvc pvcname -n xxx #查看pvc详细信息排错使用
要想外网访问,修改服务的yaml文件,设置type为NodePort为30946
还要在安全组中开放这个端口
能够先在pod里面测试
进入kafka的pod
建立主题
bin/kafka-topics.sh --create --zookeeper 10.233.61.237:2181 --replication-factor 1 --partitions 1 --topic device 这里面使用的是集群ip,容器间访问
建立消费者
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic device --from-beginning
建立生产者
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic device 使用本地ip bin/kafka-console-producer.sh --broker-list 10.233.9.150:9092 --topic device 使用集群id bin/kafka-console-producer.sh --broker-list 192.168.2.177:30946 --topic device 使用服务器内网ip和nodeport
如今pod内部能够访问了,如今尝试在外部建立生产者。
实验发现,在k8s上部署服务来访问k8s上的kafka,依然没有问题。
下面咱们尝试直接在本地pc访问服务器k8s中的kafka。
在本地电脑上cd到kafka的目录
cd /home/lp/soft/kafka_2.11-1.1.0 bin/kafka-console-producer.sh --broker-list 192.168.2.177:30946 --topic device
发现访问不了。
进入pod
在pod重启kafka。
bin/kafka-server-stop.sh 关闭
进入pod,执行
bin/zookeeper-shell.sh 10.233.61.237:2181 <<< "get /brokers/ids/0" 使用的是zookeeper的集群ip