简体   繁体   中英

502 Bad Gateway with Kubernetes Ingress Digital Ocean

I have a kubernetes setup with the configuration like below:

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

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.

Any idea?

Thanks!

Please, avoid using these files manually. This file seems outdated too. Use helm if you don't like surprises. Because these are managed services.

First, install Helm on your laptop. Then log in to your Digitalocean in the command panel. Delete existing Nginx ingress implementations. Then run these commands one by one.

At first add the ingress controller to the default namespace

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

Then update the 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. Digitalocean will then automatically run these aforementioned commands for you, If you check their Github account. you will find that they are also using helm for their marketplace services. It's time to adopt Helm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM