簡體   English   中英

使用帶有 Ingress 控制器的 Kubernetes 的 502 錯誤網關

[英]502 bad gateway using Kubernetes with Ingress controller

我在 Minikube 上使用以下配置進行了 Kubernetes 設置:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myappdeployment
spec:
  replicas: 5
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: custom-docker-image:latest
          ports:
            - containerPort: 3000

---
kind: Service
apiVersion: v1
metadata:
  name: example-service
spec:
  selector:
    app: myapp
  ports:
    - protocol: "TCP"
      # Port accessible inside cluster
      port: 3000
      # Port to forward to inside the pod
      targetPort: 3000
  type: NodePort

---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  - http:
      paths:
      - path: /
        backend:
          serviceName: example-service
          servicePort: 3000

我查看了這篇 Stackoverflow 帖子的解決方案,看起來我的配置是......好嗎?

訪問http://192.xxx.xx.x 時,我的 Minikube 地址出現 502 Bad Gateway,我做錯了什么? nginx-ingress-controller日志說:

...
Connection refused while connecting to upstream
...

另一個奇怪的信息,當我按照本指南在 Kubernetes 上設置基本節點服務時,一切正常,當我打開 Minikube 添加時,我看到一個“Hello world”頁面

采取的步驟:我跑了

kubectl port-forward pods/myappdeployment-5dff57cfb4-6c6bd 3000:3000

然后我訪問了localhost:3000並看到

This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE

我認為原因在日志中更明顯,所以我跑了

kubectl logs pods/myappdeployment-5dff57cfb4-6c6bd 

並得到

Waiting for MySQL...
no destination
Waiting for MySQL...
no destination
Waiting for MySQL...
no destination
Waiting for MySQL...
no destination
...

因此,我推斷我最初得到的是 502,因為由於沒有設置 MySQL,所有 pod 都沒有運行。

暫無
暫無

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

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