Kubernetes Ingress返回502错误的网关

时间:2020-03-02 16:20:13

标签: kubernetes yaml kubernetes-ingress nginx-ingress kubernetes-pod

我一直在设置K8s集群,这是我的配置(如下),并且我遇到了入口返回502错误网关的问题。

我的仪表板上所有的东西都绿了,我只是想不知道这里的交通是怎么阻塞的。

所有图像(dockerfiles)在本地工作100%。

我在这里浏览了大多数类似的问题,但是我还没有发现问题,因此,感谢您的提前帮助。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: moneyapi-deployment
  labels:
    app: moneyapi-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: moneyapi
  template:
    metadata:
      labels:
        app: moneyapi
    spec:
      containers:
      - name: moneyapi
        image: money/api:latest
        ports:
        - containerPort: 8080
      imagePullSecrets:
        - name: projesecret
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: moneyfrontend-deployment
  labels:
    app: moneyfrontend-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: moneyfrontend
  template:
    metadata:
      labels:
        app: moneyfrontend
    spec:
      containers:
      - name: moneyfrontend
        image: money/frontend:latest
        ports:
        - containerPort: 3000
      imagePullSecrets:
        - name: projesecret
---
apiVersion: v1
kind: Service
metadata:
  name: moneyapiservice
spec:
  selector:
    app: moneyapi
  ports:
  - protocol: TCP
    port: 8000
    targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: moneyfrontendservice
spec:
  selector:
    app: moneyfrontend
  ports:
  - protocol: TCP
    port: 3030
    targetPort: 3000
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: moneyingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - http:
      paths: 
      - path: /api
        backend:
          serviceName: moneyapiservice
          servicePort: 8000
      - path: /
        backend:
          serviceName: moneyfrontendservice
          servicePort: 3030

1 个答案:

答案 0 :(得分:3)

连接被拒绝意味着容器未在端口3000上侦听。检查映像的docker文件,也许它正在在其他端口(例如80或8080)上侦听。如果是这种情况,则将服务的targetPort更改为3000正确的端口应使其正常工作。