环境信息

本次实战的操作系统和软件的版本信息如下:

env:
Kubernetes:1.18
Kubernetes宿主机:CentOS Linux release 7.7.1908
NFS服务:IP地址192.168.1.43,动态存储卷 storageClass: "nfs-client"
Helm:3.2.2
Kafka:2.0.1
Zookeeper:3.5.5

添加helm仓库并下载

helm repo add incubator http://mirror.azure.cn/kubernetes/charts-incubator/
helm repo update
helm fetch incubator/kafka --untar
cd kafka

example

vi values-dev.yaml

resources:
  limits:
    cpu: 200m
    memory: 1536Mi
  requests:
    cpu: 100m
    memory: 1024Mi

external:
  enabled: true

livenessProbe:
  #由于 kafka 初次启动的时候比较慢,所以尽量将健康检查的初始化时间设置长一点,我们这里设置成 livenessProbe.initialDelaySeconds=60
  initialDelaySeconds: 60

external:
  enabled: true

configurationOverrides:
  "advertised.listeners": |-
    EXTERNAL://192.168.11.11:$((31090 + ${KAFKA_BROKER_ID}))
  #此ip为node节点ip
  "listener.security.protocol.map": |-
    PLAINTEXT:PLAINTEXT,EXTERNAL:PLAINTEXT

persistence:
  enabled: true
  size: "5Gi"
  mountPath: "/opt/kafka/data"
  storageClass: "nfs-client"

zookeeper:
  persistence:
    enabled: false
    size: "2Gi"
    storageClass: "nfs-client"

abstract

安装kafka

helm install -f values-dev.yaml kafka ./ --namespace kafka

example

添加zk的外部访问

vi zookeeper-nodeport-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: zookeeper-nodeport
  namespace: kafka-test
spec:
  type: NodePort
  ports:
       - port: 2181
         nodePort: 32181
  selector:
    app: zookeeper
    release: kafka