找不到Kubernetes Ingress Nginx控制器



Ingress Nginx控制器正在为React应用程序返回404 Not Found。我将其缩小到React应用程序,因为如果我尝试访问posts.com/posts,它实际上会返回现有帖子的JSON列表,但对于前端应用程序,它会不断显示得到http://posts.com/404(未找到(

我看了看其他一些堆叠式的问题,但遗憾的是没有用。

入口srv.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-srv
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "use"
spec:
rules:
- host: posts.com
http:
paths:
- path: /posts/create
pathType: Prefix
backend:
service:
name: posts-clusterip-srv
port:
number: 4000
- path: /posts
pathType: Prefix
backend:
service:
name: query-srv
port:
number: 4002
- path: /posts/?(.*)/comments
pathType: Prefix
backend:
service:
name: comments-srv
port:
number: 4001
- path: /?(.*)
pathType: Prefix
backend:
service:
name: client-srv
port:
number: 3000

客户端depl.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: client-depl
spec: 
replicas: 1
selector:
matchLabels:
app: client
template:
metadata:
labels:
app: client
spec:
containers:
- name: client
image: brachikaa/client
imagePullPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
name: client-srv
spec:
selector: 
app: client
ports: 
- name: client
protocol: TCP
port: 3000
targetPort: 3000

前端Dockerfile

FROM node:alpine
ENV CI=true
WORKDIR /app
COPY package.json ./
RUN npm install
COPY ./ ./ 
CMD ["npm", "start"]

记录吊舱:

Events:
Type    Reason     Age   From               Message
----    ------     ----  ----               -------
Normal  Scheduled  11m   default-scheduler  Successfully assigned default/client-depl-f7cf996cf-cvh6m to minikube
Normal  Pulling    11m   kubelet            Pulling image "brachikaa/client"
Normal  Pulled     11m   kubelet            Successfully pulled image "brachikaa/client" in 42.832431635s
Normal  Created    11m   kubelet            Created container client
Normal  Started    11m   kubelet            Started container client

如果您需要任何其他日志,我很乐意提供。谢谢

在您的yamls中,有一个路径"/"用于处理查询参数,但该路径将不接收来自"查询"的业务/"路径,因为没有匹配的前缀。所以你必须创建一条路径"/"使用类型前缀来解决问题。然后您可以忽略当前的"/"路径,因为它将匹配前缀为"0"/"路径

请尝试这个:

ingress-srv.yaml
__________________
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-srv
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "use"
spec:
rules:
- host: posts.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: client-srv
port:
number: 3000
- path: /posts/create
pathType: Prefix
backend:
service:
name: posts-clusterip-srv
port:
number: 4000
- path: /posts
pathType: Prefix
backend:
service:
name: query-srv
port:
number: 4002
- path: /posts/?(.*)/comments
pathType: Prefix
backend:
service:
name: comments-srv
port:
number: 4001
- path: /?(.*)
pathType: Prefix
backend:
service:
name: client-srv
port:
number: 3000

所以这个问题真的很愚蠢-我实际上设置了nginx.ingress.kubernetes.io/use-regex:"使用";代替nginx.ingress.kubernetes.io/use-regex:";真的";。。。经过三天的文档检查,我终于找到了它。如果有人遇到类似的问题,你就知道了。

您必须在规范中添加以下规则

- path: /
pathType: Prefix
backend:
service:
name: client-srv
port:
number: 3000

这匹配所有路径。

参考-https://kubernetes.io/docs/concepts/services-networking/ingress/#examples

相关内容

  • 没有找到相关文章

最新更新