gpt4 book ai didi

kubernetes - 重写入口nginx的问题

转载 作者:行者123 更新时间:2023-12-02 12:36:14 24 4
gpt4 key购买 nike

我是新手,正在尝试使用minikube和ingress-nginx在本地使用kubernetes部署整个应用程序。面对下面的重写问题

以下是我的ingress-service.yml配置文件

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: client-cluster-ip-service
servicePort: 3000
- path: /api/
backend:
serviceName: server-cluster-ip-service
servicePort: 5000

我的快速路由代码是
app.get('/', (req, res) => {
res.send('index');
});

app.get('/values/all', async (req, res) => {
res.send('all values');
});

app.get('/values/current', async (req, res) => {
res.send('current values');
});

通过我对所有路由的应用程序,它仅用于索引路由。

我需要的是,当我的React应用程序调用路由“/ api / values / all”时,我应该从相应的路由获取响应,即
app.get('/values/all', async (req, res) => {
res.send('all values');
});

我该如何解决 ???

最佳答案

您的rewrite-target术语似乎是问题所在。查看有关 rewrite-target 的文档。尝试创建2个入口资源:

Front.yaml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /*
backend:
serviceName: client-cluster-ip-service
servicePort: 3000

Back.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /api
spec:
rules:
- http:
paths:
- path: /api/*
backend:
serviceName: server-cluster-ip-service
servicePort: 5000

关于kubernetes - 重写入口nginx的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55530265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com