我知道这个问题以前被问过,但前一个不适用于我的情况。我有2个部署和2个服务,我正在使用ingress资源和nginx ingress controller
ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: frontend-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- http:
paths:
- path: /api
backend:
serviceName: frontend-svc
servicePort: 3000
- path: /
backend:
serviceName: static-svc
servicePort: 80
并且这两种服务定义如下,services.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: frontend
name: frontend-svc
spec:
ports:
- port: 3000
protocol: TCP
targetPort: 3000
selector:
app: frontend
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
labels:
app: static
name: static-svc
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: static
type: ClusterIP
部署如下所示,
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: frontend
name: frontend
spec:
replicas: 2
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- image: magalixcorp/sample-api:v1
imagePullPolicy: IfNotPresent
name: frontend
env:
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redis-password
key: redis-password
volumeMounts:
- name: config-volume
mountPath: /app/config.json
subPath: config.json
volumes:
- name: config-volume
configMap:
name: app-config
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: static
name: static
spec:
replicas: 2
selector:
matchLabels:
app: static
template:
metadata:
labels:
app: static
spec:
containers:
- image: magalixcorp/static:v1
imagePullPolicy: IfNotPresent
name: static
我已经部署了一个nginx控制器使用helm到AKS。路线根本不起作用。当我检查nginx控制器日志时,我得到了这个
W1109 16:30:33.892443 6 controller.go:849] Error obtaining Endpoints for Service "default/frontend-svc": no object matching key "default/frontend-svc" in local store
W1109 16:30:33.892478 6 controller.go:849] Error obtaining Endpoints for Service "default/static-svc": no object matching key "default/static-svc" in local store
I1109 16:30:33.929583 6 main.go:112] "successfully validated configuration, accepting" ingress="frontend-ingress/default"
W1109 16:30:33.935904 6 controller.go:849] Error obtaining Endpoints for Service "default/frontend-svc": no object matching key "default/frontend-svc" in local store
W1109 16:30:33.935930 6 controller.go:849] Error obtaining Endpoints for Service "default/static-svc": no object matching key "default/static-svc" in local store
I1109 16:30:33.935973 6 controller.go:144] "Configuration changes detected, backend reload required"
I1109 16:30:33.936084 6 event.go:282] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"frontend-ingress", UID:"efde0161-c03f-49d4-8f2b-38e2ceaaf8a7", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"7945", FieldPath:""}): type: 'Normal' reason: 'Sync' Scheduled for sync
I1109 16:30:34.005219 6 controller.go:161] "Backend successfully reloaded"
I1109 16:30:34.005615 6 event.go:282] Event(v1.ObjectReference{Kind:"Pod", Namespace:"nginx", Name:"nginx-ingress-nginx-controller-68f45f49f6-slnv7", UID:"7880b0be-a1ff-450d-b1c1-4cee11722a6b", APIVersion:"v1", ResourceVersion:"3538", FieldPath:""}): type: 'Normal' reason: 'RELOAD' NGINX reload triggered due to a change in configuration
I1109 16:30:37.269565 6 controller.go:144] "Configuration changes detected, backend reload required"
I1109 16:30:37.342929 6 controller.go:161] "Backend successfully reloaded"
I1109 16:30:37.343677 6 event.go:282] Event(v1.ObjectReference{Kind:"Pod", Namespace:"nginx", Name:"nginx-ingress-nginx-controller-68f45f49f6-slnv7", UID:"7880b0be-a1ff-450d-b1c1-4cee11722a6b", APIVersion:"v1", ResourceVersion:"3538", FieldPath:""}): type: 'Normal' reason: 'RELOAD' NGINX reload triggered due to a change in configuration
I1109 16:31:01.926983 6 status.go:290] "updating Ingress status" namespace="default" ingress="frontend-ingress" currentValue=[] newValue=[{IP: Hostname:a596c83cb03464004bcced0767dd5aa9-1681194742.us-east-1.elb.amazonaws.com}]
I1109 16:31:01.937928 6 event.go:282] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"frontend-ingress", UID:"efde0161-c03f-49d4-8f2b-38e2ceaaf8a7", APIVersion:"networking.k8s.io/v1beta1", ResourceVersion:"8081", FieldPath:""}): type: 'Normal' reason: 'Sync' Scheduled for sync
10.0.1.165 - - [09/Nov/2020:16:32:18 +0000] "GET / HTTP/1.1" 200 1313 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0" 396 0.002 [default-static-svc-80] [] 10.0.3.144:80 1313 0.000 200 750627c05c4ca98a2bcd60ae8bbb8828
10.0.1.165 - - [09/Nov/2020:16:32:19 +0000] "GET /js/script.js HTTP/1.1" 200 314 "http://a596c83cb03464004bcced0767dd5aa9-1681194742.us-east-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0" 397 0.001 [default-static-svc-80] [] 10.0.1.175:80 314 0.000 200 af72c4fdc493a489064307872636b662
10.0.1.165 - - [09/Nov/2020:16:32:20 +0000] "GET /favicon.ico HTTP/1.1" 404 153 "http://a596c83cb03464004bcced0767dd5aa9-1681194742.us-east-1.elb.amazonaws.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0" 407 0.002 [default-static-svc-80] [] 10.0.3.144:80 153 0.000 404 ba36f92120a41720842ba95e24b9975c
10.0.2.31 - - [09/Nov/2020:16:32:47 +0000] "GET /.env HTTP/1.1" 404 555 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36" 231 0.001 [default-static-svc-80] [] 10.0.1.175:80 555 0.000 404 d8ec13faad1d46c13401b397e2d80ad0
10.0.2.31 - - [09/Nov/2020:16:32:48 +0000] "POST / HTTP/1.1" 405 559 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36" 317 0.001 [default-static-svc-80] [] 10.0.1.175:80 559 0.000 405 567a4b2499fc816d72135445076bafda
10.0.1.165 - - [09/Nov/2020:16:32:53 +0000] "GET /api HTTP/1.1" 200 3 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0" 399 0.003 [default-frontend-svc-3000] [] 10.0.1.26:3000 3 0.000 200 8a92b9829d26dccb60f11a9c8537d831
10.0.3.231 - - [09/Nov/2020:16:34:37 +0000] "POST /api HTTP/1.1" 204 0 "-" "curl/7.64.1" 211 0.002 [default-frontend-svc-3000] [] 10.0.1.26:3000 0 0.000 204 cf837f8bc89c29f2d2b07ac317120220
10.0.2.31 - - [09/Nov/2020:16:34:55 +0000] "GET /api HTTP/1.1" 200 3 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0" 425 0.006 [default-frontend-svc-3000] [] 10.0.2.98:3000 3 0.004 200 a5757323ff32d8c4dbc56ef476798954
当我尝试:3000/API无论是POST还是GET都不起作用。什么可能是错的。我做错了什么。
2条答案
按热度按时间7cwmlq891#
把这里清理一下。因此,为您的前端创建一个部署。所以这个文件你可以调用
frontend-depl.yml
,然后像这样写:我建议这样做是为了保持你的
yml
文件的整洁,因为这一切都可能很快失控,你可以告诉和故障排除可能是一个痛苦。我也会进入你的终端并运行:
也就是看看你有什么端点。
这个问题也可能是你的标签选择器,这就是为什么我提供了你的
yml
文件的一个更干净的版本,至少是frontend-depl
,我会对你的其他yml
文件使用相同的模式。要了解有关标签选择器的详细信息,请执行以下操作:https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
zte4gxcn2#
我也遇到了同样的问题,结果发现我瞄准了错误的IP地址。我将流量从我的VNet外部发送到我在这里找到的(外部)IP地址:
我很困惑,因为当我测试一个临时运行的Pod时,这个地址工作正常,它只是从我的VNet中发出一个HTTP调用,然后终止。
然而,当我阅读Ingress Pod的日志时,我发现解析到的IP地址不同。然后我通过这个命令检查端点
事实证明,这里列出的IP地址是我的Ingress控制器正在监听的正确IP地址。所以,我配置了我的私人DNS使用该IP地址并解决了问题。