簡體   English   中英

Kubernetes Ingress-nginx出現502錯誤(錯誤的網關)

[英]Kubernetes ingress-nginx gives 502 error (Bad Gateway)

我有一個我想要的EKS集群:-每個集群1個負載均衡器,-導入規則以定向到正確的名稱空間和正確的服務。

我一直在遵循本指南: 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 Ingress Controller:kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.24.1/deploy/mandatory.yaml

我不確定為什么對於某項服務我暫時無法獲得503服務而對於另一項服務卻無法獲得502服務...我想這是端口或名稱空間的問題? 在指南中,他們沒有為部署定義名稱空間...

每種資源都可以正確創建,我認為入口實際上是有效的,但是到哪里去卻感到困惑。

謝謝你的幫助!

通常,使用externalTrafficPolicy: Cluster而不是Local 通過使用Local可以提高性能(延遲),但是您需要付出很多努力來配置這些pod分配。 這些配置錯誤將導致5xx錯誤。 另外, ClusterexternalTrafficPolicy的默認選項。

ingress ,您將/bleble路由到service bleble ,但是您的服務名稱實際上是bleble-svc 請使它們一致。 另外,當您在服務配置中公開8080時,需要將servicePort設置為8080。

對於諸如bleble-svc類的內部服務,由於您不需要外部訪問,因此Cluster IP足以滿足您的需要。

希望這可以幫助。

找到了! 部署中的containerPort設置為8000,也是服務的目標端口,但是執行代碼Dockerfile的人暴露了端口80。這就是它獲得502 Bad getaway的原因!

也非常感謝@Fei,他一直是一個了不起的助手!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM