gpt4 book ai didi

kubernetes - 默认后端 - 使用 dns 时从 nginx-controller 返回 404

转载 作者:行者123 更新时间:2023-12-02 11:30:18 29 4
gpt4 key购买 nike

一点背景是我已经设置了一个 Azure Kubernetes 服务集群并部署了一个基本的 .Net Core api 作为部署对象。然后我部署了一个 nodeport 服务来公开 api,然后部署了一个 nginx-controller 和一个 ingress 对象来配置它。我使用入口 Controller 的 IP 来路由请求,例如工作。 http://1.2.3.4/hello-world-one/api/values .
但是当我用生成的 dns 替换 Ip 时,不知何故忽略了路径,我得到了默认后端 - 从 nginx Controller 返回的 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

关于kubernetes - 默认后端 - 使用 dns 时从 nginx-controller 返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54085119/

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