【问题标题】:Why is this Kubernetes Ingress not accepting traffic?为什么这个 Kubernetes Ingress 不接受流量?
【发布时间】:2019-09-25 20:06:37
【问题描述】:

我正在尝试在 Kubernetes 上设置一个简单的 HTTP Web 服务器,并使用临时外部 IP 公开它。但是,当启动它并尝试访问 x.x.x.x/something 的 URL 之一时,我得到:

Error: Server Error
The server encountered a temporary error and could not complete your request.
Please try again in 30 seconds.

我的配置很简单:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  labels:
    app: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: web
        image: gcr.io/my-repo-name
        ports:
        - containerPort: 8080
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
        readinessProbe:
          initialDelaySeconds: 10
          httpGet:
            path: /healthz
            port: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: web-balancer-service
spec:
  selector:
    app: web
  type: NodePort
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 32111
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress-app
spec:
  backend:
    serviceName: web-balancer-service
    servicePort: 8080

如果我描述 入口,我会看到后端是“未知”。我的规格有问题吗?

Name:             my-ingress-app
Namespace:        default
Address:          x.x.x.x
Default backend:  web-balancer-service:8080 (10.60.0.57:32111)
Rules:
  Host  Path  Backends
  ----  ----  --------
  *     *     web-balancer-service:8080 (10.60.0.57:32111)
Annotations:
  ingress.kubernetes.io/backends:         {"k8s-be-30330--f4bbd8cbe40f4567":"Unknown"}
  ingress.kubernetes.io/forwarding-rule:  k8s-fw-default-my-ingress-app--f4bbd8cbe40f4567
  ingress.kubernetes.io/target-proxy:     k8s-tp-default-my-ingress-app--f4bbd8cbe40f4567
  ingress.kubernetes.io/url-map:          k8s-um-default-my-ingress-app--f4bbd8cbe40f4567
Events:
  Type    Reason  Age    From                     Message
  ----    ------  ----   ----                     -------
  Normal  ADD     7m18s  loadbalancer-controller  default/my-ingress-app
  Normal  CREATE  6m12s  loadbalancer-controller  ip: x.x.x.x

【问题讨论】:

    标签: ssl kubernetes kubernetes-ingress


    【解决方案1】:

    您收到的错误消息是来自 Google Kubernetes Engine (GKE) 的错误,因此我假设您在 GKE on Google Cloud 中运行。

    首先,确保容器(部署的 pod)实际上正在侦听端口 32111。您将其作为服务上的targetPort,这意味着服务将在端口8080 上接收流量,但将它们发送到它匹配的pod 的端口32111。看起来像:

    --(traffic)---> :8080 (service) ---> :32111 (pods)
    

    我怀疑这一点,因为在您的 pod 规范中,您有 containerPort: 8080,这表明该 pod 实际上也侦听了8080,而不是32111

    因此,首先尝试将Service的targetPort也改为8080

    经过一段时间后,如果它没有开始工作,请检查您的集群中是否真的启用了 HTTP 负载平衡。当您在 Google Cloud Console 上创建集群时,它看起来像这样:

    在现有集群上,在 GCP 控制台上转到其详细信息,然后检查插件部分:

    【讨论】:

    • 谢谢你的问题确实是目标端口 - 在健康之前还要等待大约 10 分钟。
    猜你喜欢
    • 2015-12-11
    • 1970-01-01
    • 2021-05-18
    • 2012-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多