使用k8s部署的kafka集群,没有外网访问权限时
添加

        - name: KAFKA_ADVERTISED_LISTENERS
          value: "PLAINTEXT://[外网ip]:[svc上nodePort端口号]"

如下所示

---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: kafka-deployment-3
spec:
  replicas: 1
  selector:
  selector:
    matchLabels:
      name: kafka-service-3
  template:
    metadata:
      labels:
        name: kafka-service-3
        app: kafka-service-3
    spec:
      containers:
      - name: kafka-3
        image: wurstmeister/kafka
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9092
        env:
        - name: KAFKA_ADVERTISED_PORT
          value: "9092"
        - name: KAFKA_ADVERTISED_HOST_NAME
          value: 10.0.0.16
        - name: KAFKA_ZOOKEEPER_CONNECT
          value: zoo1:2181,zoo2:2181,zoo3:2181
        - name: KAFKA_BROKER_ID
          value: "3"
        - name: KAFKA_ADVERTISED_LISTENERS
          value: "PLAINTEXT://x.x.x.x:30903"
        - name: KAFKA_CREATE_TOPICS
          value: mytopic:2:1


重新部署
kubectl apply -f …

Logo

开源、云原生的融合云平台

更多推荐