从集群内连接到Kafka Kubernetes集群

时间:2020-10-10 23:54:03

标签: kubernetes apache-kafka

我是Kubernetes部署的新手。 我可以从外部连接到kafka集群,但是无法在WITHIN集群中执行相同的操作。

这是我的配置:

kafka-broker:

--- 
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: crd-instrument
  name: kafkaservice
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kafkaservice
  template:
    metadata:
      labels:
        app: kafkaservice
    spec:
      hostname: kafkaservice
      containers:
      - name: kafkaservice
        imagePullPolicy: IfNotPresent
        image: wurstmeister/kafka
        env:
         - name: KAFKA_BROKER_ID
           value: "1"
         - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
           value: "INTERNAL_PLAINTEXT:PLAINTEXT,EXTERNAL_PLAINTEXT:PLAINTEXT"
         - name: KAFKA_LISTENERS
           value: "INTERNAL_PLAINTEXT://0.0.0.0:9092,EXTERNAL_PLAINTEXT://0.0.0.0:9093"
         - name: KAFKA_ADVERTISED_LISTENERS
           value: "INTERNAL_PLAINTEXT://kafkaservice:9092,EXTERNAL_PLAINTEXT://127.0.0.1:30035"
         - name: KAFKA_INTER_BROKER_LISTENER_NAME
           value: "INTERNAL_PLAINTEXT"
         - name: KAFKA_CREATE_TOPICS
           value: "crd_instrument_req:1:1,crd_instrument_resp:1:1,crd_instrument_resol:1:1"
         - name: KAFKA_ZOOKEEPER_CONNECT
           value: "zookeeperservice:2181"
        ports:
        - name: port9092
          containerPort: 9092
        - name: port9093
          containerPort: 9093

kafka服务:

---
apiVersion: v1
kind: Service
metadata:
  namespace: crd-instrument
  name: kafkaservice
  labels:
    app: kafkaservice
spec:
  selector:
    app: kafkaservice
  ports:
  - name: port9092
    port: 9092
    targetPort: 9092
    protocol: TCP

Kafka-service-external

---
apiVersion: v1
kind: Service
metadata:
  namespace: crd-instrument
  name: kafkaservice-external
  labels:
    app: kafkaservice-external
spec:
  selector:
    app: kafkaservice
  ports:
  - name: port9093
    port: 9093
    protocol: TCP
    nodePort: 30035
  type: NodePort

这是在相同名称空间中启动的客户端yml:

---
apiVersion: v1
kind: Pod
metadata:
  name: crd-instrument-client
  labels:
    app: crd-instrument-client
  namespace: crd-instrument
spec:
  containers:
  - name: crd-instrument-client
    image: crd_instrument_client:1.0
    imagePullPolicy: Never

其中的代码试图以“ kafkaservice:9092”的身份与BOOTSTRAP_SERVERS连接

未连接。如果有人可以帮助指出我的意思,我在哪里错了。

0 个答案:

没有答案