在kubernetes部署kafka-ui得到502坏网关

tjrkku2a  于 2023-01-04  发布在  Apache
关注(0)|答案(1)|浏览(162)

我尝试在本地Kubernetes集群中部署Kafka-UI,但ingress-nginx显示502错误(Bad Gateway)。

    • 部署时间:**
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kafka-ui-deployment
  labels:
    app: kafka-ui
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kafka-ui
  template:
    metadata:
      labels:
        app: kafka-ui
    spec:
      containers:
      - name: kafka-ui
        image: provectuslabs/kafka-ui:latest
        env:
        - name: KAFKA_CLUSTERS_0_NAME
          value: "K8 Kafka Cluster"
        - name: KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS
          value: kafka-svc:9093
        imagePullPolicy: Always
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "1024Mi"
            cpu: "1000m"
        ports:
        - containerPort: 8088
          protocol: TCP
    • 服务:**
apiVersion: v1
kind: Service
metadata:
  name: kafka-ui-service
spec:
  selector:
    app: kafka-ui
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8088
    • 入口:**
ingressClassName: public
      rules:
      - host: "localhost"
        http:
          paths:
          - path: /kafka-ui
            pathType: Prefix
            backend:
              service:
                name: kafka-ui-service
                port:
                  number: 80

端口转发目标端口出现以下错误:

Forwarding from 127.0.0.1:8088 -> 8088
Forwarding from [::1]:8088 -> 8088
channel 9: open failed: connect failed: Connection refused
Handling connection for 8088
Handling connection for 8088
E0623 09:18:20.768161   33100 portforward.go:406] an error occurred forwarding 8088 -> 8088: error forwarding port 8088 to pod 75353d54479df5f235c03db1899367dc77e82877986be849761eba6193ca72c0, uid : failed to execute portforward in network namespace "/var/run/netns/cni-a5ed0994-0456-6b6c-5a79-90e582ef09b3": failed to connect to localhost:8088 inside namespace "75353d54479df5f235c03db1899367dc77e82877986be849761eba6193ca72c0", IPv4: dial tcp4 127.0.0.1:8088: connect: connection refused IPv6 dial tcp6: address localhost: no suitable address found
E0623 09:18:20.768994   33100 portforward.go:234] lost connection to pod

如有任何建议,我们将不胜感激。谢谢您的帮助!

nukf8bse

nukf8bse1#

主要的错误是端口。正确的端口是8080。这个yaml对我来说很好用。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kafka-ui-deployment
  labels:
    app: kafka-ui
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kafka-ui
  template:
    metadata:
      labels:
        app: kafka-ui
    spec:
      containers:
      - name: kafka-ui
        image: provectuslabs/kafka-ui:latest
        env:
        - name: KAFKA_CLUSTERS_0_NAME
          value: "K8 Kafka Cluster"
        - name: KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS
          value: kafka-kafka-bootstrap.kafka:9092 # <- service-name.namespace:9092
        imagePullPolicy: Always
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "1024Mi"
            cpu: "1000m"
        ports:
        - containerPort: 8080 # <- Rectify the port
          protocol: TCP
apiVersion: v1
kind: Service
metadata:
  name: kafka-ui-service
  namespace: kafka
spec:
  selector:
app: kafka-ui
  ports:
- protocol: TCP
  port: 8080
  targetPort: 8080 # <- Rectify the port.
ingressClassName: public
      rules:
      - host: "localhost"
        http:
          paths:
          - path: /kafka-ui
            pathType: Prefix
            backend:
              service:
                name: kafka-ui-service
                port:
                  number: 8080

相关问题