默认后端 - 使用 dns 时从 nginx-controller 返回 404
default backend - 404 returned from nginx-controller when dns is used
一些背景知识是我已经设置了一个 Azure Kubernetes 服务集群并部署了一个基本的 .Net Core api 作为部署对象。然后我部署了一个 nodeport 服务来公开 api,然后部署了一个 nginx-controller 和一个入口对象来配置它。我使用入口控制器的 IP 来路由请求并且有效,例如 http://1.2.3.4/hello-world-one/api/values。
但是当我用生成的 dns 替换 Ip 时,不知何故路径被忽略,我得到默认后端 - 从 nginx 控制器返回 404。预期的行为是 dns 将解析然后路径 "api/values" 将发送到我的服务。
谁能帮我解决这个问题?
提前致谢。
我的部署、服务和入口配置如下。
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: test-deployment
labels:
app: test
spec:
replicas: 1
selector:
matchLabels:
app: test
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
template:
metadata:
labels:
app: test
spec:
containers:
- name: test-service
image: <my-repo>.azurecr.io/testservice
imagePullPolicy: Always
ports:
- name: tcp
containerPort: 80
imagePullSecrets:
- name: regsecret
---
apiVersion: v1
kind: Service
metadata:
name: frontend
spec:
type: NodePort
selector:
app: test
ports:
- name: http
port: 32768
targetPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-world-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.global-static-ip-name: dev-pip-usw-qa-aks
kubernetes.io/ingress.class: addon-http-application-routing
spec:
rules:
- host: hello-world-ingress.be543d4af69d4c7ca489.westus.aksapp.io
- http:
paths:
- path: /
backend:
serviceName: frontend
servicePort: http
- path: /hello-world-one
backend:
serviceName: frontend
servicePort: http
- path: /hello-world-two
backend:
serviceName: frontend
servicePort: http
很确定 rules
应该是这样的:
rules:
- host: hello-world-ingress.be543d4af69d4c7ca489.westus.aksapp.io
http:
paths:
- path: /
backend:
serviceName: frontend
servicePort: http
- path: /hello-world-one
backend:
serviceName: frontend
servicePort: http
- path: /hello-world-two
backend:
serviceName: frontend
servicePort: http
阅读:https://kubernetes.io/docs/concepts/services-networking/ingress/#types-of-ingress
一些背景知识是我已经设置了一个 Azure Kubernetes 服务集群并部署了一个基本的 .Net Core api 作为部署对象。然后我部署了一个 nodeport 服务来公开 api,然后部署了一个 nginx-controller 和一个入口对象来配置它。我使用入口控制器的 IP 来路由请求并且有效,例如 http://1.2.3.4/hello-world-one/api/values。 但是当我用生成的 dns 替换 Ip 时,不知何故路径被忽略,我得到默认后端 - 从 nginx 控制器返回 404。预期的行为是 dns 将解析然后路径 "api/values" 将发送到我的服务。
谁能帮我解决这个问题? 提前致谢。
我的部署、服务和入口配置如下。
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: test-deployment
labels:
app: test
spec:
replicas: 1
selector:
matchLabels:
app: test
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
template:
metadata:
labels:
app: test
spec:
containers:
- name: test-service
image: <my-repo>.azurecr.io/testservice
imagePullPolicy: Always
ports:
- name: tcp
containerPort: 80
imagePullSecrets:
- name: regsecret
---
apiVersion: v1
kind: Service
metadata:
name: frontend
spec:
type: NodePort
selector:
app: test
ports:
- name: http
port: 32768
targetPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-world-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.global-static-ip-name: dev-pip-usw-qa-aks
kubernetes.io/ingress.class: addon-http-application-routing
spec:
rules:
- host: hello-world-ingress.be543d4af69d4c7ca489.westus.aksapp.io
- http:
paths:
- path: /
backend:
serviceName: frontend
servicePort: http
- path: /hello-world-one
backend:
serviceName: frontend
servicePort: http
- path: /hello-world-two
backend:
serviceName: frontend
servicePort: http
很确定 rules
应该是这样的:
rules:
- host: hello-world-ingress.be543d4af69d4c7ca489.westus.aksapp.io
http:
paths:
- path: /
backend:
serviceName: frontend
servicePort: http
- path: /hello-world-one
backend:
serviceName: frontend
servicePort: http
- path: /hello-world-two
backend:
serviceName: frontend
servicePort: http
阅读:https://kubernetes.io/docs/concepts/services-networking/ingress/#types-of-ingress