首页 文章

Kubernetes Ingress(GCE)不断回复502错误

提问于
浏览
15

我正在尝试在GCE Kubernetes中设置Ingress . 但是当我访问Ingress中定义的IP地址和路径组合时,我不断收到以下502错误:

Ingress 502 error


这是我跑步时得到的: kubectl describe ing --namespace dpl-staging

Name:           dpl-identity
Namespace:      dpl-staging
Address:        35.186.221.153
Default backend:    default-http-backend:80 (10.0.8.5:8080)
TLS:
  dpl-identity terminates
Rules:
  Host  Path    Backends
  ----  ----    --------
  *
        /api/identity/*     dpl-identity:4000 (<none>)
Annotations:
  https-forwarding-rule:    k8s-fws-dpl-staging-dpl-identity--5fc40252fadea594
  https-target-proxy:       k8s-tps-dpl-staging-dpl-identity--5fc40252fadea594
  url-map:          k8s-um-dpl-staging-dpl-identity--5fc40252fadea594
  backends:         {"k8s-be-31962--5fc40252fadea594":"HEALTHY","k8s-be-32396--5fc40252fadea594":"UNHEALTHY"}
Events:
  FirstSeen LastSeen    Count   From                SubObjectPath   Type        Reason  Message
  --------- --------    -----   ----                -------------   --------    ------  -------
  15m       15m     1   {loadbalancer-controller }          Normal      ADD dpl-staging/dpl-identity
  15m       15m     1   {loadbalancer-controller }          Normal      CREATE  ip: 35.186.221.153
  15m       6m      4   {loadbalancer-controller }          Normal      Service no user specified default backend, using system default

我认为问题是 dpl-identity:4000 (<none>) . 我不应该看到 dpl-identity 服务的IP地址而不是 <none> 吗?

这是我的服务说明: kubectl describe svc --namespace dpl-staging

Name:           dpl-identity
Namespace:      dpl-staging
Labels:         app=dpl-identity
Selector:       app=dpl-identity
Type:           NodePort
IP:             10.3.254.194
Port:           http    4000/TCP
NodePort:       http    32396/TCP
Endpoints:      10.0.2.29:8000,10.0.2.30:8000
Session Affinity:   None
No events.

此外,这是执行的结果: kubectl describe ep -n dpl-staging dpl-identity

Name:       dpl-identity
Namespace:  dpl-staging
Labels:     app=dpl-identity
Subsets:
  Addresses:        10.0.2.29,10.0.2.30
  NotReadyAddresses:    <none>
  Ports:
    Name    Port    Protocol
    ----    ----    --------
    http    8000    TCP

No events.

这是我的deployment.yaml:

apiVersion: v1
kind: Secret
metadata:
  namespace: dpl-staging
  name: dpl-identity
type: Opaque
data:
  tls.key: <base64 key>
  tls.crt: <base64 crt>
---
apiVersion: v1
kind: Service
metadata:
  namespace: dpl-staging
  name: dpl-identity
  labels:
    app: dpl-identity
spec:
  type: NodePort
  ports:
    - port: 4000
      targetPort: 8000
      protocol: TCP
      name: http
  selector:
    app: dpl-identity
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  namespace: dpl-staging
  name: dpl-identity
  labels:
    app: dpl-identity
  annotations:
    kubernetes.io/ingress.allow-http: "false"
spec:
  tls:
  - secretName: dpl-identity
  rules:
  - http:
      paths:
        - path: /api/identity/*
          backend:
            serviceName: dpl-identity
            servicePort: 4000
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  namespace: dpl-staging
  name: dpl-identity
kind: Ingress
metadata:
  namespace: dpl-staging
  name: dpl-identity
  labels:
    app: dpl-identity
  annotations:
    kubernetes.io/ingress.allow-http: "false"
spec:
  tls:
  - secretName: dpl-identity
  rules:
  - http:
      paths:
        - path: /api/identity/*
          backend:
            serviceName: dpl-identity
            servicePort: 4000
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  namespace: dpl-staging
  name: dpl-identity
  labels:
    app: dpl-identity
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: dpl-identity
    spec:
      containers:
      - image: gcr.io/munpat-container-engine/dpl/identity:0.4.9
        name: dpl-identity
        ports:
        - containerPort: 8000
          name: http
        volumeMounts:
        - name: dpl-identity
          mountPath: /data
      volumes:
      - name: dpl-identity
        secret:
          secretName: dpl-identity

5 回答

  • 0

    您的后端 k8s-be-32396--5fc40252fadea594 显示为 "UNHEALTHY" .

    如果后端是不 Health 的,Ingress将不会转发流量,这将导致您看到的502错误 .

    它将被标记为不 Health ,因为它没有通过它的 Health 检查,你可以检查k8s-be-32396--5fc40252fadea594的 Health 检查设置,看看它们是否适合你的pod,它可能是轮询URI或端口这不会返回200响应 . 您可以在Compute Engine> Health Checks下找到这些设置 .

    如果它们是正确的那么你的浏览器和容器之间有很多步骤可能会错误地传递流量,你可以尝试 kubectl exec -it PODID -- bash (如果你使用的是Alpine,则使用ash),然后尝试卷曲localhost以查看容器是否响应为预期,如果是,并且运行状况检查也正确配置,那么这可能会将问题缩小到您的服务范围,然后您可以尝试将服务从NodePort类型更改为LoadBalancer,并查看是否直接从服务IP更新你的浏览器工作 .

  • 0

    我有同样的问题,并且在我启用 livenessProbe 以及 readinessPorbe 之后它仍然存在 . 这转变为与基本认证有关 . 我已经为 livenessProbereadinessPorbe 添加了基本身份验证,但结果显示GCE HTTP(S)负载均衡器没有配置选项 .

    似乎还有一些其他类型的问题,例如将容器端口设置为8080,将服务端口设置为80不能与GKE入口控制器一起工作(但我不会清楚地指出问题是什么) . 从广义上讲,在我看来,可见性非常低,在可视性方面运行自己的入口容器是一个更好的选择 .

    我为我的项目选择了Traefik,它开箱即用,并且我加密了集成 . 我必须对Traefik清单进行的唯一更改是调整服务对象以禁止从集群外部访问UI,并通过外部负载均衡器(GCE TCP LB)公开我的应用程序 . 此外,Traefik更像Kubernetes . 我尝试过Heptio Contour,但有些东西没有开箱即用(下一次当新版本发布时会给它一个机会) .

  • 24

    问题确实是 Health 状况检查,对于我的应用程序而言,我使用基于名称的虚拟主机来反转从入口通过域到两个单独的后端服务的代理请求 . 两者都使用Lets Encrypt和 kube-lego 进行保护 . 我的解决方案是标准化共享入口的所有服务的运行状况检查路径,并在我的 deployment.yml 文件中声明 readinessProbelivenessProbe 配置 .

    我在使用Google Cloud 集群节点版本 1.7.8 时遇到了这个问题,发现这个问题与我的经历非常相似:* https://github.com/jetstack/kube-lego/issues/27

    我正在使用 gcekube-lego ,我的后端服务运行状况检查在 / 上, kube-lego/healthz 上 . 看起来 Health 检查的路径不同 gce ingress 可能是原因所以可能值得更新后端服务以匹配 /healthz 模式,因此所有使用相同(或者作为Github问题中的一个评论者声明他们更新了kube-lego以传递 / ) .

  • 1

    我遇到了同样的问题 . 事实证明,我必须在进入之前等待几分钟才能验证服务运行状况 . 如果有人要做同样的事情并完成所有步骤,如 readinessProbelinvenessProbe ,只需确保您的入口指向一个 NodePort 的服务,并等待几分钟,直到黄色警告图标变为绿色警告图标 . 另外,检查StackDriver上的日志以更好地了解正在发生的事情 . 对于 gce 类,我的 readinessProbelivenessProbe/login 上 . 所以我不认为它必须在 /healthz 上 .

  • 0

    kubernetes 文档的"Limitations"部分指出:

    所有Kubernetes服务必须在'/'或其他任何地方提供200页您通过GLBC的--health-check-path参数指定的自定义值 .

    https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/cluster-loadbalancing/glbc#limitations

相关问题