背景
IP | 角色 | 中间件 |
---|---|---|
172.16.16.108 | k8s-master-1 | kafka, zookeeper |
172.16.16.109 | k8s-node-1 | kafka, zookeeper |
172.16.16.110 | k8s-node-2 | kafka, zookeeper |
部署 kafka
mkdir -p /data/yaml/klvchen/kafka && cd /data/yaml/klvchen/kafka
# 添加 bitnami charts 仓库
helm repo add bitnami https://charts.bitnami.com/bitnami
# 查看
helm repo list
# 搜索
helm search repo kafka
wget https://charts.bitnami.com/bitnami/kafka-20.0.2.tgz
tar zxvf kafka-20.0.2.tgz
# 创建命名空间
kubectl create ns klvchen
# 确认自己的 storageClass
kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
nfs-client k8s-sigs.io/nfs-subdir-external-provisioner Delete Immediate true 16d
# 根据自己的要求更改配置
cat my-valuse.yaml
replicaCount: 3 # kafka 副本数
global:
storageClass: nfs-client # kafka 和 zookeeper 使用的存储
heapOpts: "-Xmx1024m -Xms1024m" # kafka 启动的 jvm 参数
persistence: # kafka 每个副本的存储空间
size: 10Gi
zookeeper:
replicaCount: 3 # zookeeper 的副本数
persistence:
size: 10Gi # zookeeper 每个副本的存储空间
externalAccess:
enabled: true # 开启外部访问
autoDiscovery:
enabled: true
service:
type: NodePort # 开启 nodeport
ports:
external: 9094
nodePorts: # nodeport 对应的端口,多少个 kafka 副本对应多少个端口
- 30001
- 30002
- 30003
# 启动
helm install --namespace klvchen kafka -f my-valuse.yaml --set rbac.create=true kafka
# 检查
helm -n klvchen ls
kubectl -n klvchen get pod
部署 kafka-console-ui
mkdir -p /data/yaml/klvchen/kafka-console-ui && cd /data/yaml/klvchen/kafka-console-ui
cat >> deployment.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: kafka-console-ui
namespace: klvchen
spec:
replicas: 1
selector:
matchLabels:
app: kafka-console-ui
template:
metadata:
labels:
app: kafka-console-ui
spec:
containers:
- name: kafka-console-ui
image: wdkang/kafka-console-ui:latest
volumeMounts:
- mountPath: /etc/localtime
readOnly: true
name: time-data
volumes:
- name: time-data
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
EOF
cat >> svc.yaml << EOF
kind: Service
apiVersion: v1
metadata:
labels:
app: kafka-console-ui
name: kafka-console-ui
namespace: klvchen
spec:
ports:
- port: 7766
targetPort: 7766
nodePort: 30088
selector:
app: kafka-console-ui
type: NodePort
EOF
kubectl apply -f deployment.yaml -f svc.yaml
访问 http://172.16.16.108:30088/
新建集群名字 kafka
地址:172.16.16.108:30001,172.16.16.108:30002,172.16.16.108:30003
参考:
https://artifacthub.io/packages/helm/bitnami/kafka