kind: Deployment apiVersion: v1 metadata: name: kafka-deployment spec: replicas: 1 selector: matchLabels: name: kafka template: metadata: labels: name: kafka app: kafka spec: containers: - name: kafka image: wurstmeister/kafka:2.12-2.3.0 imagePullPolicy: IfNotPresent ports: - containerPort: 9092 env: - name: KAFKA_ADVERTISED_PORT value: "9092" - name: KAFKA_ADVERTISED_HOST_NAME value: "[kafka的service的clusterIP]" - name: KAFKA_ZOOKEEPER_CONNECT value: [zookeeper的service的clusterIP]:2181 - name: KAFKA_BROKER_ID value: "1" --- apiVersion: v1 kind: Service metadata: name: kafka-service labels: app: kafka spec: type: NodePort ports: - port: 9092 name: kafka-port targetPort: 9092 nodePort: 39092 protocol: TCP selector: app: kafka