[英]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.