Kafka在库伯尼特斯的特拉菲克后面

wd2eg0qa  于 2021-06-06  发布在  Kafka
关注(0)|答案(1)|浏览(481)

我试图在traefik后面配置kafka集群,但是我的生产者和客户机(在kubernetes之外)没有连接到引导服务器。他们一直在说:
“给定url中没有可解析的引导服务器”
实际上这里是traefik入口:

{
    "apiVersion": "extensions/v1beta1",
    "kind": "Ingress",
    "metadata": {
        "name": "nppl-ingress",
        "annotations": {
            "kubernetes.io/ingress.class": "traefik",
            "traefik.frontend.rule.type": "PathPrefixStrip"
        }
    },
    "spec": {
        "rules": [
            {
                "host": "" ,
                "http": {
                    "paths": [
                        {
                            "path": "/zuul-gateway",
                            "backend": {
                                "serviceName": "zuul-gateway",
                                "servicePort": "zuul-port"
                            }
                        },                      
                        {
                            "path": "/kafka",
                            "backend": {
                                "serviceName": "kafka-broker",
                                "servicePort": "kafka-port"
                            }

[..]
    }

我给Kafka消费者/生产者的是traefik的公共ip。下面是流程:[kafka producers/consumers]->traefik(作为负载均衡器公开)->[kafka cluster]
有什么解决办法吗?否则我想添加一个kafka rest代理(https://docs.confluent.io/current/kafka-rest/docs/index.html)但我认为这不是一个理想的解决方案。

os8fio9y

os8fio9y1#

是的。您可以在kubernetes中引用它,部署kafka.yaml

env:
    - name: KAFKA_BROKER_ID
      value: "1"
    - name: KAFKA_CREATE_TOPICS
      value: "test:1:1"
    - name: KAFKA_ZOOKEEPER_CONNECT
      value: "zookeeper:2181"
    - name: KAFKA_ADVERTISED_LISTENERS
      value: "INSIDE://:9092,OUTSIDE://kafka-com:30322"
    - name: KAFKA_LISTENERS
      value: "INSIDE://:9092,OUTSIDE://:30322"
    - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
      value: "INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT"
    - name: KAFKA_INTER_BROKER_LISTENER_NAME
      value: "INSIDE"

kafka服务、外部服务调用地址或traefik代理地址

---
kind: Service
apiVersion: v1
metadata:
  name: kafka-com
  namespace: dev
  labels:
    k8s-app: kafka
spec:
  selector:
    k8s-app: kafka
  ports:
  - port: 9092
    name: innerport
    targetPort: 9092
    protocol: TCP
  - port: 30322
    name: outport 
    targetPort: 30322
    protocol: TCP
    nodePort: 30322
  type: NodePort

确保kafka外部端口和nodeport端口一致,其他服务调用kafka-com:30322,我的博客写的这个配置Kafka在Kubernetes,希望对你有所帮助!

相关问题