简体   繁体   English

502 Bad Gateway with Kubernetes Ingress Digital Ocean

[英]502 Bad Gateway with Kubernetes Ingress Digital Ocean

I have a kubernetes setup with the configuration like below:我有一个 kubernetes 设置,配置如下:

I am using this mandatory file:我正在使用这个强制性文件:

https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.26.1/deploy/static/mandatory.yaml https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.26.1/deploy/static/provider/cloud-generic.yaml https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.26.1/deploy/static/mandatory.yaml https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.26.1 /deploy/static/provider/cloud-generic.yaml

My ingress:我的入口:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: api-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
  tls:
    - hosts:
      - api.service.com
      secretName: api-tls
  rules:
  - host: api.service.com
    http:
      paths:
      - backend:
          serviceName: api-service
          servicePort: 80

My service:我的服务:

#########################################################
# Service for API Gateway service
#########################################################
apiVersion: v1
kind: Service
metadata:
  name: api-service
  labels:
    name: api
spec:
  selector:
    app: api
  ports:
  - name: http
    port: 80
    targetPort: 3000
    nodePort: 30000
    protocol: TCP
  - name: https
    port: 443
    targetPort: 3000
    nodePort: 30001
    protocol: TCP
  type: NodePort
  sessionAffinity: ClientIP

My deployment:我的部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    name: api
  name: api
spec:
  replicas: 1
  selector:
    matchLabels:
      name: api
  template:
    metadata:
      labels:
        name: api
        app: api
    spec:
      containers:
      - env:
        - name: CACHER
          value: redis://redis:6379
        - name: LOGLEVEL
          value: info
        - name: NAMESPACE
          value: myName
        - name: PORT
          value: "3000"
        - name: SERVICEDIR
          value: services
        - name: SERVICES
          value: api
        - name: TRANSPORTER
          value: nats://nats:4222
        ports:
          - containerPort: 3000
        image: registry.digitalocean.com/my-registry/my-image:latest
        imagePullPolicy: ""
        name: api
        resources: {}
      imagePullSecrets:
      - name: my-registry
      restartPolicy: Always
      serviceAccountName: ""
      volumes: null
      
status: {}

If I use Service NodePort with port 30001 and its own IP, I don't have any problem, but with LoadBalancer always throws a 502 Bad gateway.如果我将 Service NodePort 与端口 30001 和它自己的 IP 一起使用,我没有任何问题,但使用 LoadBalancer 总是会抛出 502 Bad gateway。

Any idea?任何想法?

Thanks!谢谢!

Please, avoid using these files manually.请避免手动使用这些文件。 This file seems outdated too.这个文件似乎也过时了。 Use helm if you don't like surprises.如果您不喜欢惊喜,请使用 helm。 Because these are managed services.因为这些是托管服务。

First, install Helm on your laptop.首先,在您的笔记本电脑上安装 Helm。 Then log in to your Digitalocean in the command panel.然后在命令面板中登录您的 Digitalocean。 Delete existing Nginx ingress implementations.删除现有的 Nginx 入口实现。 Then run these commands one by one.然后一一运行这些命令。

At first add the ingress controller to the default namespace首先将入口 controller 添加到默认命名空间

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

Then update the helm repo然后更新 helm repo

helm repo update

Then finally run this command然后最后运行这个命令

helm install nginx-ingress ingress-nginx/ingress-nginx --set controller.publishService.enabled=true

To check the installation run this command要检查安装运行此命令

kubectl --namespace default get services -o wide -w nginx-ingress-ingress-nginx-controller

There is also a digital ocean recommended approach.还有一种数字海洋推荐的方法。 You can use Digital Ocean Marketplace to install Nginx-Ingress too.您也可以使用 Digital Ocean Marketplace 安装 Nginx-Ingress。 Digitalocean will then automatically run these aforementioned commands for you, If you check their Github account.如果您检查他们的 Github 帐户,Digitalocean 将自动为您运行这些上述命令。 you will find that they are also using helm for their marketplace services.你会发现他们也在使用 helm 来提供市场服务。 It's time to adopt Helm.是时候采用 Helm 了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kube.netes Ingress 502 错误网关连接被拒绝 - Kubernetes Ingress 502 Bad Gateway Connection Refused nginx / 1.4.6中的502错误网关(Ubuntu14 Digital Ocean) - 502 Bad Gateway in nginx/1.4.6 (Ubuntu14 Digital Ocean) 将 django 应用程序部署到数字海洋失败(502 Bad Gateway) - Deploying django app to digital ocean unsuccessful (502 Bad Gateway) 502错误的网关错误(nginx +独角兽+数字海洋) - 502 bad gateway error (nginx + unicorn + digital ocean) Kubernetes Nginx 入口返回 502 Bad Gateway 使用主机文件 - Kubernetes Nginx Ingress returning 502 Bad Gateway using hosts file 用于Azure Kubernetes Service 502错误网关的Nginx入口控制器 - nginx-ingress controller for Azure Kubernetes Service 502 Bad Gateway 无法修复 NGINX 502:Digital Ocean 液滴上的网关错误 - Ubuntu 20.04 - Unable to fix NGINX 502: Bad Gateway error on a Digital Ocean droplet - Ubuntu 20.04 在数字海洋上部署Django,Gunicorn,Nginx,Virtualenv给了我502 Bad Gateway&Gunicorn无法读取密钥 - Deploying Django, Gunicorn, Nginx, Virtualenv on Digital ocean gives me 502 Bad Gateway & Gunicorn can't read Secret Key Nginx 在 Kubernetes 中返回 Bad Gateway 502 - Nginx returns Bad Gateway 502 in Kubernetes Keycloak Kubernetes GKE NGINX Ingress - 页面重新加载时 pod 重启后会话丢失并返回 502 Bad Gateway - Keycloak Kubernetes GKE NGINX Ingress - Session get lost after pod restart on page reload and returns 502 Bad Gateway
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM