使用NodePort服务时,可以进入我的应用程序。但是,当我尝试通过Ingress进行访问时,我总是会收到HTTP 404。
对于我有回应的这张图片中的测试图片gcr.io/google-samples/hello-app:1.0
,这不会发生。
这是我的部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-backend-deployment
labels:
app: app-backend
spec:
replicas: 1
selector:
matchLabels:
app: app-backend
template:
metadata:
labels:
app: app-backend
spec:
containers:
- name: app-backend
image: go-app-backend
ports:
- containerPort: 8100
imagePullPolicy: Never
我的NodePort服务:
apiVersion: v1
kind: Service
metadata:
labels:
app: app-backend-deployment
name: app-backend-svc-nodeport
spec:
type: NodePort
ports:
- port: 8020
protocol: TCP
targetPort: 8100
selector:
app: app-backend
从那时起,当我致电$ minikube service church-backend-svc-nodeport --url
时,我会得到我的应用运行所在的地址。
但是当我尝试配置我的应用以在Ingress上获取路由时,它不起作用:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
name: app-backend-ingress
spec:
rules:
- host: app-backend.io
http:
paths:
- backend:
serviceName: app-backend-svc-nodeport
servicePort: 8020
path: /backend
但是,当我使用示例问候词应用程序(https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/)进行配置并替换ingress.yml中的所有内容时,一切正常。谁能看看这个,告诉我我做错了什么?
答案 0 :(得分:2)
如果我没记错的话,您需要将ingress放入后端path: /backend(/|$)(.*)
和元数据nginx.ingress.kubernetes.io/rewrite-target: /$2
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
name: app-backend-ingress
spec:
rules:
- host: app-backend.io
http:
paths:
- backend:
serviceName: app-backend-svc-nodeport
servicePort: 8020
path: /backend(/|$)(.*)