Kubernetes ingress-nginx 给出 502 错误(坏网关) [英] Kubernetes ingress-nginx gives 502 error (Bad Gateway)

查看:152
本文介绍了Kubernetes ingress-nginx 给出 502 错误(坏网关)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我想要的 EKS 集群:- 每个集群 1 个负载均衡器,- 指向正确命名空间和正确服务的入口规则.

I have an EKS cluster for which I want : - 1 Load Balancer per cluster, - Ingress rules to direct to the right namespace and the right service.

我一直在遵循本指南:https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nginx-ingress-with-cert-manager-on-digitalocean-Kubernetes

我的部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-world
        image: IMAGENAME
        ports:
        - containerPort: 8000
          name: hello-world


---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: bleble
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: bleble
  template:
    metadata:
      labels:
        app: bleble
    spec:
      containers:
      - name: bleble
        image: IMAGENAME
        ports:
        - containerPort: 8000
          name: bleble


那些部署的服务:


apiVersion: v1
kind: Service
metadata: 
  name: hello-world-svc
spec: 
  ports: 
     -  port: 8080
        protocol: TCP
        targetPort: 8000
  selector: 
    app: hello-world
  type: NodePort

---

apiVersion: v1
kind: Service
metadata: 
  name: bleble-svc
spec: 
  ports: 
     -  port: 8080
        protocol: TCP
        targetPort: 8000
  selector: 
    app: bleble
  type: NodePort

我的负载均衡器:

kind: Service
apiVersion: v1
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-internal: "true"
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  externalTrafficPolicy: Local
  type: LoadBalancer
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
  ports:
    - name: http
      port: 80
      targetPort: http

我的入口:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: simple-fanout-example
  namespace : default
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: internal-lb.aws.com
    http:
      paths:
      - path: /bleble
        backend:
          serviceName: bleble-svc
          servicePort: 80
      - path: /hello-world
        backend:
          serviceName: hello-world-svc
          servicePort: 80

我已经设置了 Nginx 入口控制器:kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.24.1/deploy/mandatory.yaml

I've set up the Nginx Ingress Controller with this : kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.24.1/deploy/mandatory.yaml

我不确定为什么我的一项服务得到 503 服务暂时不可用,而另一项服务得到 502 服务......我猜这是端口或命名空间的问题?在指南中,他们没有为部署定义命名空间...

I am unsure why I get a 503 Service Temporarily Unavailable for one service and one 502 for another... I would guess it's a problem of ports or of namespace? In the guide, they don't define namespace for the deployment...

每个资源都正确创建,我认为入口实际上正在工作,但对去哪里感到困惑.

Every resources create correctly, and I think the ingress is actually working but is getting confused where to go.

感谢您的帮助!

推荐答案

一般来说,使用 externalTrafficPolicy: Cluster 而不是 Local.您可以通过使用 Local 来获得一些性能(延迟)改进,但是您需要付出很多努力来配置这些 pod 分配.您将因这些错误配置而遇到 5xx 错误.另外,ClusterexternalTrafficPolicy的默认选项.

In general, use externalTrafficPolicy: Cluster instead of Local. You can gain some performance (latency) improvement by using Local but you need to configure those pod allocations with a lot efforts. You will hit 5xx errors with those misconfigurations. In addition, Cluster is the default option for externalTrafficPolicy.

在您的 ingress 中,您将 /bleble 路由到服务 bleble,但您的服务名称实际上是 bleble-svc.请使它们一致.此外,您需要将 servicePort 设置为 8080,因为您在服务配置中公开了 8080.

In your ingress, you route /bleble to service bleble, but your service name is actually bleble-svc. please make them consistent. Also, you would need to set your servicePort to 8080 as you exposed 8080 in your service configuration.

对于像 bleble-svc 这样的内部服务,Cluster IP 在您的情况下就足够了,因为它不需要外部访问.

For internal service like bleble-svc, Cluster IP is good enough in your case as it does not need external access.

希望这会有所帮助.

这篇关于Kubernetes ingress-nginx 给出 502 错误(坏网关)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆