[英]502 Bad Gateway with Kubernetes Ingress Digital Ocean
我有一个 kubernetes 设置,配置如下:
我正在使用这个强制性文件:
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
我的入口:
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
我的服务:
#########################################################
# 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
我的部署:
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: {}
如果我将 Service NodePort 与端口 30001 和它自己的 IP 一起使用,我没有任何问题,但使用 LoadBalancer 总是会抛出 502 Bad gateway。
任何想法?
谢谢!
请避免手动使用这些文件。 这个文件似乎也过时了。 如果您不喜欢惊喜,请使用 helm。 因为这些是托管服务。
首先,在您的笔记本电脑上安装 Helm。 然后在命令面板中登录您的 Digitalocean。 删除现有的 Nginx 入口实现。 然后一一运行这些命令。
首先将入口 controller 添加到默认命名空间
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
然后更新 helm repo
helm repo update
然后最后运行这个命令
helm install nginx-ingress ingress-nginx/ingress-nginx --set controller.publishService.enabled=true
要检查安装运行此命令
kubectl --namespace default get services -o wide -w nginx-ingress-ingress-nginx-controller
还有一种数字海洋推荐的方法。 您也可以使用 Digital Ocean Marketplace 安装 Nginx-Ingress。 如果您检查他们的 Github 帐户,Digitalocean 将自动为您运行这些上述命令。 你会发现他们也在使用 helm 来提供市场服务。 是时候采用 Helm 了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.