我正在使用部署一个面向外的服务,该服务暴露在一个节点端口后面,然后是一个 istio 入口。部署使用手动边车注入。一旦部署、nodeport 和 ingress 运行起来,我就可以向 istio ingress 发出请求。
由于某些未知原因,该请求不会路由到我的部署,而是显示文本“上游不健康”。为什么会这样,是什么原因造成的?
我可以在 http 响应中看到状态码是 503(服务不可用),服务器是“特使”。部署正在运行,因为我可以将端口映射到它,并且一切都按预期工作。
我正在使用部署一个面向外的服务,该服务暴露在一个节点端口后面,然后是一个 istio 入口。部署使用手动边车注入。一旦部署、nodeport 和 ingress 运行起来,我就可以向 istio ingress 发出请求。
由于某些未知原因,该请求不会路由到我的部署,而是显示文本“上游不健康”。为什么会这样,是什么原因造成的?
我可以在 http 响应中看到状态码是 503(服务不可用),服务器是“特使”。部署正在运行,因为我可以将端口映射到它,并且一切都按预期工作。
尽管这是由于不正确的 Istio 设置中的路由问题导致的一般性错误,但我将为遇到相同问题的任何人提供一般性解决方案/建议。
在我的情况下,问题是由于路由规则配置不正确,Kubernetes 原生服务正在运行,但是 Istio 路由规则配置不正确,因此 Istio 无法从入口路由到服务。
以防万一,像我一样,你会好奇......即使在我的场景中,错误的情况很明显......
错误原因: 我有两个版本的相同服务(v1 和 v2),以及一个使用权重配置了流量路由目标的 Istio VirtualService。然后,95% 进入 v1,5% 进入 v2。由于我还没有部署 v1,当然,错误“503 - no healthy upstream”显示了 95% 的请求。
好吧,即便如此,我知道问题以及如何解决它(只需部署 v1),我想知道......但是,我怎样才能获得有关此错误的更多信息?我怎样才能更深入地分析这个错误以找出发生了什么?
这是使用 Istio 的配置命令行实用程序 istioctl 进行调查的一种方式:
# 1) Check the proxies status -->
$ istioctl proxy-status
# Result -->
NAME CDS LDS EDS RDS PILOT VERSION
...
teachstore-course-v1-74f965bd84-8lmnf.development SYNCED SYNCED SYNCED SYNCED istiod-86798869b8-bqw7c 1.5.0
...
...
# 2) Get the name outbound from JSON result using the proxy (service with the problem) -->
$ istioctl proxy-config cluster teachstore-course-v1-74f965bd84-8lmnf.development --fqdn teachstore-student.development.svc.cluster.local -o json
# 2) If you have jq install locally (only what we need, already extracted) -->
$ istioctl proxy-config cluster teachstore-course-v1-74f965bd84-8lmnf.development --fqdn teachstore-course.development.svc.cluster.local -o json | jq -r .[].name
# Result -->
outbound|80||teachstore-course.development.svc.cluster.local
inbound|80|9180-tcp|teachstore-course.development.svc.cluster.local
outbound|80|v1|teachstore-course.development.svc.cluster.local
outbound|80|v2|teachstore-course.development.svc.cluster.local
# 3) Check the endpoints of "outbound|80|v2|teachstore-course..." using v1 proxy -->
$ istioctl proxy-config endpoints teachstore-course-v1-74f965bd84-8lmnf.development --cluster "outbound|80|v2|teachstore-course.development.svc.cluster.local"
# Result (the v2, 5% of the traffic route is ok, there are healthy targets) -->
ENDPOINT STATUS OUTLIER CHECK CLUSTER
172.17.0.28:9180 HEALTHY OK outbound|80|v2|teachstore-course.development.svc.cluster.local
172.17.0.29:9180 HEALTHY OK outbound|80|v2|teachstore-course.development.svc.cluster.local
# 4) However, for the v1 version "outbound|80|v1|teachstore-course..." -->
$ istioctl proxy-config endpoints teachstore-course-v1-74f965bd84-8lmnf.development --cluster "outbound|80|v1|teachstore-course.development.svc.cluster.local"
ENDPOINT STATUS OUTLIER CHECK CLUSTER
# Nothing! Emtpy, no Pods, that's explain the "no healthy upstream" 95% of time.
当我的 pod 处于ContainerCreating
状态时,我遇到了这个问题。因此,它导致了 503 错误。同样作为@pegaldon,解释它也可能由于不正确的路由配置或用户没有创建网关而发生。
删除 destinationrules.networking.istio.io 并重新创建 virtualservice.networking.istio.io
[root@10-20-10-110 ~]# curl http://dprovider.example.com:31400/dw/provider/beat
no healthy upstream[root@10-20-10-110 ~]#
[root@10-20-10-110 ~]# curl http://10.210.11.221:10100/dw/provider/beat
"该服务节点 10.210.11.221 心跳正常!"[root@10-20-10-110 ~]#
[root@10-20-10-110 ~]#
[root@10-20-10-110 ~]# cat /home/example_service_yaml/vs/dw-provider-service.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: dw-provider-service
namespace: example
spec:
hosts:
- "dprovider.example.com"
gateways:
- example-gateway
http:
- route:
- destination:
host: dw-provider-service
port:
number: 10100
subset: "v1-0-0"
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: dw-provider-service
namespace: example
spec:
host: dw-provider-service
subsets:
- name: "v1-0-0"
labels:
version: 1.0.0
[root@10-20-10-110 ~]# vi /home/example_service_yaml/vs/dw-provider-service.yaml
[root@10-20-10-110 ~]# kubectl -n example get vs -o wide | grep dw
dw-collection-service [example-gateway] [dw.collection.example.com] 72d
dw-platform-service [example-gateway] [dplatform.example.com] 81d
dw-provider-service [example-gateway] [dprovider.example.com] 21m
dw-sync-service [example-gateway] [dw-sync-service dsync.example.com] 34d
[root@10-20-10-110 ~]# kubectl -n example delete vs dw-provider-service
virtualservice.networking.istio.io "dw-provider-service" deleted
[root@10-20-10-110 ~]# kubectl -n example delete d dw-provider-service
daemonsets.apps deniers.config.istio.io deployments.extensions dogstatsds.config.istio.io
daemonsets.extensions deployments.apps destinationrules.networking.istio.io
[root@10-20-10-110 ~]# kubectl -n example delete destinationrules.networking.istio.io dw-provider-service
destinationrule.networking.istio.io "dw-provider-service" deleted
[root@10-20-10-110 ~]# kubectl apply -f /home/example_service_yaml/vs/dw-provider-service.yaml
virtualservice.networking.istio.io/dw-provider-service created
[root@10-20-10-110 ~]# curl http://dprovider.example.com:31400/dw/provider/beat
"该服务节点 10.210.11.221 心跳正常!"[root@10-20-10-110 ~]#
[root@10-20-10-110 ~]#