我已经在 kubernetes 中部署了应用程序。如果我们在 azure kubernetes 中公开默认负载均衡器服务,它就可以正常工作。但是,在设置与 istio ingress 网关链接的虚拟服务后,它只启动主页,所有链接都不起作用,例如 /admin /login。
我已经在虚拟服务中添加了 /admin 和 /login 的条目,但无法打开这些页面。
kiali 启动使用
istioctl dashboard kiali
当我检查日志时基亚利。
[2021-07-18T08:19:51.304Z] "GET /admin/ HTTP/1.1" 404 NR route_not_found - "-" 0 0 0 - "10.244.1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "bc1ce347-4151-947b-b3d5-4c08003889a2" "20.85.0.248" "-" - - 10.244.1.9:8080 10.244.1.1:4441 - -
[2021-07-18T08:19:53.400Z] "GET /login/ HTTP/1.1" 404 NR route_not_found - "-" 0 0 0 - "10.244.1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "78f9d59e-6126-94f6-99e3-cbffe98e274f" "20.85.0.248" "-" - - 10.244.1.9:8080 10.244.1.1:4441 - -
[2021-07-18T08:19:56.286Z] "GET /login HTTP/1.1" 301 - via_upstream - "-" 0 0 4 4 "10.244.1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "be2ff6b8-751d-9150-9d6a-936a436f7fef" "20.85.0.248" "10.244.1.50:3000" outbound|8080||node-service.default.svc.cluster.local 10.244.1.9:59678 10.244.1.9:8080 10.244.1.1:4441 - -
[2021-07-18T08:19:56.525Z] "GET /login/ HTTP/1.1" 404 NR route_not_found - "-" 0 0 0 - "10.244.1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "f821db0b-cc9d-9b8c-9769-71ac7636a87e" "20.85.0.248" "-" - - 10.244.1.9:8080 10.244.1.1:4441 - -
[2021-07-18T08:20:00.198Z] "GET / HTTP/1.1" 200 - via_upstream - "-" 0 2804 4 4 "10.244.1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "43c37e75-f0ce-9474-bc4d-ea4459772f6d" "20.85.0.248" "10.244.1.50:3000" outbound|8080||node-service.default.svc.cluster.local 10.244.1.9:59678 10.244.1.9:8080 10.244.1.1:4441 - -
[2021-07-18T08:20:00.457Z] "GET /static/todo/logo.png HTTP/1.1" 404 NR route_not_found - "-" 0 0 0 - "10.244.1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "a26d3710-3868-96b6-9d6d-7f6ee05dc131" "20.85.0.248" "-" - - 10.244.1.9:8080 10.244.1.1:4441 - -
[2021-07-18T08:20:34.337Z] "GET /login/ HTTP/1.1" 404 NR route_not_found - "-" 0 0 0 - "10.244.1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "e8e73933-f95e-90a7-bdf4-ad39352982c5" "20.85.0.248" "-" - - 10.244.1.9:8080 10.244.1.1:4441 - -
[2021-07-18T08:20:37.506Z] "GET /login/ HTTP/1.1" 404 NR route_not_found - "-" 0 0 0 - "10.244.1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "bee90116-2d78-99dd-a4b7-fede0641fed8" "20.85.0.248" "-" - - 10.244.1.9:8080 10.244.1.1:4441 - -
[2021-07-18T08:20:40.191Z] "GET /login/ HTTP/1.1" 404 NR route_not_found - "-" 0 0 0 - "10.244.1.1" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36" "f9df634e-743f-9699-a85d-40926db41ca4" "20.85.0.248" "-" - - 10.244.1.9:8080 10.244.1.1:4441 - -
请建议如何修复此问题?
示例应用程序docker关联。
使用的 kubernetes yaml 文件:
部署.yaml
apiVersion: v1
kind: Service
metadata:
name: node-service
labels:
app: nodeapp
service: node-service
spec:
selector:
app: nodeapp
ports:
- name: http
port: 8080
targetPort: 3000 #80
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: nodeapp-details
labels:
account: nodeapp-details
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodeapp-deployment
labels:
app: nodeapp
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: nodeapp
version: v1
template:
metadata:
labels:
app: nodeapp
version: v1
spec:
serviceAccountName: nodeapp-details
containers:
- name: nginx
image: uday1kiran/todoapp:1.0 #nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000 #80
name: nodeapp-port
#securityContext:
#runAsUser: 1000
虚拟服务.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: nodeserver
spec:
hosts:
- "*"
gateways:
- node-gateway
http:
- match:
- uri:
exact: /
- uri:
exact: /admin
- uri:
exact: /login
route:
- destination:
host: node-service
port:
number: 8080
网关.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: node-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
yaml 文件位于此处存储库
答案1
您收到 404 错误是因为您使用了exact
:
http:
- match:
- uri:
exact: /
- uri:
exact: /admin
- uri:
exact: /login
但是,你正在尝试访问其他端点,例如
“获取 /管理员/ HTTP/1.1”
“获取/登录/ HTTP/1.1”
您尝试访问/
末尾带有额外符号的端点。您可以通过更改exact
为 来编辑 yaml,或者您可以添加末尾regex
带有额外字符的其他选项。您还可以阅读有关/
StringMatch
这里。