0


k8s部署kafka,并使用zookeeper做注册中心

kafka在3.x版本后增加KRaft作为自己的注册中心,可以不依赖外部的zk;这里上一篇已经部署好了zk,kafka依然使用zk作为注册中心。
这里使用kafka是为集成zipkin收发微服务接口链路日志数据,只需要部署1个实列即可够用。

编写脚本yaml
vi kafka.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kafka
  namespace: default
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      project: kafka
      app: kafka
  template:
    metadata:
      labels:
        project: kafka
        app: kafka
    spec:
      containers:
        - name: kafka
          image: bitnami/kafka:3.4.0
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 9092
              name: web
              protocol: TCP
          env:
            - name: MY_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
            - name: MY_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
#            # 已zookeeper方式启动注释开始
            - name: KAFKA_ENABLE_KRAFT
              value: "no"
            - name: KAFKA_CFG_ZOOKEEPER_CONNECT
              value: zk-cs:2181/kafka  # 这里使用zk的service
            - name: KAFKA_PORT_NUMBER
              value: "9092"
            - name: KAFKA_BROKER_ID
              value: "1"            
            - name: KAFKA_CFG_ADVERTISED_LISTENERS
              # 注意必须是监听 service:端口 否则会成为实列:端口 如:kafka-974d87ccf-gnsg9:9092 导致应用不能通过service找到kafka 提示 unknowhost
              value: "PLAINTEXT://kafka:$(KAFKA_PORT_NUMBER)"
            - name: KAFKA_CFG_LISTENERS
              value: "PLAINTEXT://:$(KAFKA_PORT_NUMBER)"#            - name: KAFKA_ADVERTISED_LISTENERS#              value: PLAINTEXT://:9092#            - name: KAFKA_LISTENERS#              value: PLAINTEXT://:9092
            - name: KAFKA_CONFLUENT_TOPIC_REPLICATION_FACTOR
              value: "1"# 已zookeeper方式启动注释结束# 默认已KRaft方式启动#            - name: KAFKA_CFG_ADVERTISED_LISTENERS# 需配置hosts域名映射#              value: PLAINTEXT://kafka-server:30092#- name: KAFKA_HEAP_OPTS#  value: -Xmx2048m -Xms2048m
            - name: ALLOW_PLAINTEXT_LISTENER
              value: "yes"
---
apiVersion: v1
kind: Service
metadata:
  name: kafka
  namespace: default
  labels:
    app: kafka
spec:
  type: NodePort
  selector:
    project: kafka
    app: kafka
  ports:
    - port: 9092
      targetPort: 9092
      nodePort: 30092

执行部署
kubectl apply -f kafka.yaml

查看是否注册到ZK中,登录zk的pod
zkCli.sh
查看kafka是否注册成功
ls /
查看到 [kafka,zookeeper],kafka节点已经注册成功
get /kafka

标签: docker kubernetes kafka

本文转载自: https://blog.csdn.net/yxt625520/article/details/134013024
版权归原作者 杨豆芽 所有, 如有侵权,请联系我们删除。

“k8s部署kafka,并使用zookeeper做注册中心”的评论:

还没有评论