gpt4 book ai didi

kubernetes - Kubernetes在Rancher上-入口路径问题

转载 作者:行者123 更新时间:2023-12-02 11:49:04 26 4
gpt4 key购买 nike

我已经创建了一个带有Ingress Controller 的nod​​ejs / express应用程序,该 Controller 正在Rancher的Kubernetes上运行。只有默认后端才能完美运行,并且我可以到达用express创建的任何路线,例如http://1.2.3.4/apihttp://1.2.3.4/api/districts

我定义的路径不起作用,例如http://1.2.3.4/gg1/apihttp://1.2.3.4/gg2/api/districts。在Pod日志中,每当我在定义的路径之一上发出请求时,我都可以看到404。

我一直在寻找解决方案失败了几个小时。我看到很多人似乎出于不同的原因而在入口和路径方面遇到了问题,但是我还没有找到解决问题的方法。也许有人在这里知道解决此问题的方法?

为了使入侵起作用,我在这里使用了以下示例:Using Kubernetes Ingress Controller from scratch

这些就是我部署所有内容的方式:

kubectl create -f deployment1-config.yaml
kubectl create -f deployment2-config.yaml



kubectl expose deployment test-ingress-node-1 --target-port=5000 --type=NodePort
kubectl expose deployment test-ingress-node-2 --target-port=5000 --type=NodePort



kubectl run nginx --image=nginx --port=80
kubectl expose deployment nginx --target-port=80 --type=NodePort



kubectl create -f ingress.yaml


所有请求仅到达默认后端的pod,带有/ gg1或/ gg2的路径在pod日志中仅提供404或在浏览器中无法获取/ gg1。

ingress-config.yaml:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-node-adv-ingress
annotations:
kubernetes.io/ingress.class: "rancher"
ingress.kubernetes.io/rewrite-target: /
spec:
backend:
serviceName: test-ingress-node-1
servicePort: 5000
rules:
- host:
http:
paths:
- path: /gg1
backend:
serviceName: test-ingress-node-1
servicePort: 5000
- path: /gg2
backend:
serviceName: test-ingress-node-2
servicePort: 5000

deployment-1.config.yaml:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
generation: 2
labels:
run: test-ingress-node-1
name: test-ingress-node-1
namespace: default
resourceVersion: "123456"
selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/test-ingress-node-1
spec:
replicas: 1
selector:
matchLabels:
run: test-ingress-node-1
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
run: test-ingress-node-1
spec:
containers:
- image: myProject-service-latest
imagePullPolicy: Always
name: test-ingress-node-1
ports:
- containerPort: 5000
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 1
observedGeneration: 2
replicas: 1
updatedReplicas: 1

deployment-2.config.yaml:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
generation: 2
labels:
run: test-ingress-node-2
name: test-ingress-node-2
namespace: default
resourceVersion: "123456"
selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/test-ingress-node-2
spec:
replicas: 1
selector:
matchLabels:
run: test-ingress-node-2
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
run: test-ingress-node-2
spec:
containers:
- image: myProject-service-latest
imagePullPolicy: Always
name: test-ingress-node-2
ports:
- containerPort: 5000
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 1
observedGeneration: 2
replicas: 1
updatedReplicas: 1

最佳答案

正确的路径与节点js资源端点相同!查看入口Kubernetes文档。

“在负载均衡器将流量定向到后端之前,主机和路径都必须匹配传入请求的内容。”

https://kubernetes.io/docs/concepts/services-networking/ingress/

关于kubernetes - Kubernetes在Rancher上-入口路径问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48567304/

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