【发布时间】:2021-08-20 12:17:12
【问题描述】:
我正在尝试通过 nginx 入口控制器将微服务与我的前端应用程序一起使用。
kubectl 应用 -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.48.1/deploy/static/provider/aws/deploy.yaml 以上是我们部署 nginx-controller 所遵循的命令。
参考 - https://kubernetes.github.io/ingress-nginx/deploy/#aws
-----我的集成API的deployment.yaml和service.yaml如下-------
'''
apiVersion: apps/v1
kind: Deployment
metadata:
name: integrations-api
labels:
app: integrations-api
spec:
replicas: 1
selector:
matchLabels:
app: integrations-api
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: integrations-api
spec:
containers:
- image: "###imagepath####"
imagePullPolicy: Always
name: integrations-api
ports:
- containerPort: 8083
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: integrations-api
annotations:
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: "tcp,http"
service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "###certpath###"
service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "https"
spec:
type: LoadBalancer
selector:
app: integrations-api
ports:
- name: http
port: 80
targetPort: 8083
protocol: TCP
- name: https
port: 443
targetPort: 8083
protocol: TCP
'''
------我的 ingress.yaml 看起来像这样--------
'''
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: integrations-api
servicePort: 80
- path: /
backend:
serviceName: user-api
servicePort: 80
'''
在我的节点 js 集成 API 代码中,我们添加了测试 API 路径,如下所示 '''
app.get('/camps', (req, res) => {
let obj = {}
res.send(obj);
});
'''
当我访问 nginx-controller 的端点时(这里是负载均衡器端点)https://####NLB-endpoint###/camps 我正在收到回复。
像 deployment.yaml、service.yaml 和 nodejs 代码一样的配置是为用户服务 api 编写的。但我没有得到用户 api 的响应 https://####NLB-endpoint###/users
注意,当我像下面这样改组入口文件时,我得到 https://####NLB-endpoint###/users 的响应,但不是 https://####NLB-endpoint# ##/营地。看起来 inress 正在走上仅在首位提及的道路。
'''
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: user-api
servicePort: 80
- path: /
backend:
serviceName: integrations-api
servicePort: 80
'''
任何线索我该如何解决这个问题? 提前致谢。如果有人指导我们,对您有很大帮助。
【问题讨论】:
标签: kubernetes-ingress amazon-eks nginx-ingress