两个pod之间的istio路由

问题描述 投票:2回答:2

试图进入kubernetes的istio,但似乎我缺少一些基本面,或者我正在做的事情回到前面。我在kubernetes方面很有经验,但istio和它的虚拟服务让我感到困惑。

我创建了2个部署(helloworld-v1 / helloworld-v2)。两者都有相同的图像,唯一不同的是环境变量 - 输出版本:“v1”或版本:“v2”。我正在使用我写的一个小测试容器,它基本上返回我进入应用程序的标头。名为“helloworld”的kubernetes服务可以同时达到。

我创建了一个Virtualservice和一个Destinationrule

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: helloworld
spec:
  hosts:
  - helloworld
http:
  - route:
     - destination:
       host: helloworld
       subset: v1
     weight: 90
     - destination:
       host: helloworld
       subset: v2
     weight: 10
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: helloworld
spec:
  host: helloworld
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2

根据文档不提及任何网关应该使用内部“网格”之一。 Sidecar容器成功连接:

kubectl -n demo get all
NAME                                 READY     STATUS    RESTARTS   AGE
pod/curl-6657486bc6-w9x7d            2/2       Running   0          3h
pod/helloworld-v1-d4dbb89bd-mjw64    2/2       Running   0          6h
pod/helloworld-v2-6c86dfd5b6-ggkfk   2/2       Running   0          6h

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/helloworld   ClusterIP   10.43.184.153   <none>        80/TCP     6h

NAME                            DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/curl            1         1         1            1           3h
deployment.apps/helloworld-v1   1         1         1            1           6h
deployment.apps/helloworld-v2   1         1         1            1           6h

NAME                                       DESIRED   CURRENT   READY     AGE
replicaset.apps/curl-6657486bc6            1         1         1         3h
replicaset.apps/helloworld-v1-d4dbb89bd    1         1         1         6h
replicaset.apps/helloworld-v2-6c86dfd5b6   1         1         1         6h

当我从“外部”(istio-ingressgateway)访问应用程序时,一切正常,v2被调用一次,v1 9次被调用九次:

curl --silent -H 'host: helloworld' http://localhost
{"host":"helloworld","user-agent":"curl/7.47.0","accept":"*/*","x-forwarded-for":"10.42.0.0","x-forwarded-proto":"http","x-envoy-internal":"true","x-request-id":"a6a2d903-360f-91a0-b96e-6458d9b00c28","x-envoy-decorator-operation":"helloworld:80/*","x-b3-traceid":"e36ef1ba2229177e","x-b3-spanid":"e36ef1ba2229177e","x-b3-sampled":"1","x-istio-attributes":"Cj0KF2Rlc3RpbmF0aW9uLnNlcnZpY2UudWlkEiISIGlzdGlvOi8vZGVtby9zZXJ2aWNlcy9oZWxsb3dvcmxkCj8KGGRlc3RpbmF0aW9uLnNlcnZpY2UuaG9zdBIjEiFoZWxsb3dvcmxkLmRlbW8uc3ZjLmNsdXN0ZXIubG9jYWwKJwodZGVzdGluYXRpb24uc2VydmljZS5uYW1lc3BhY2USBhIEZGVtbwooChhkZXN0aW5hdGlvbi5zZXJ2aWNlLm5hbWUSDBIKaGVsbG93b3JsZAo6ChNkZXN0aW5hdGlvbi5zZXJ2aWNlEiMSIWhlbGxvd29ybGQuZGVtby5zdmMuY2x1c3Rlci5sb2NhbApPCgpzb3VyY2UudWlkEkESP2t1YmVybmV0ZXM6Ly9pc3Rpby1pbmdyZXNzZ2F0ZXdheS01Y2NiODc3NmRjLXRyeDhsLmlzdGlvLXN5c3RlbQ==","content-length":"0","version":"v1"}
"version": "v1",
"version": "v1",
"version": "v2",
"version": "v1",
"version": "v1",
"version": "v1",
"version": "v1",
"version": "v1",
"version": "v1",

但是,一旦我从一个吊舱内进行卷曲(在这种情况下只是byrnedo / alpine-curl)对服务的事情开始变得混乱:

curl --silent -H 'host: helloworld' http://helloworld.demo.svc.cluster.local
{"host":"helloworld","user-agent":"curl/7.61.0","accept":"*/*","version":"v1"}
"version":"v2"
"version":"v2"
"version":"v1"
"version":"v1"
"version":"v2"
"version":"v2"
"version":"v1"
"version":"v2“
"version":"v1"

不仅我错过了所有的istio属性(我在服务通信中理解这一点,因为我理解它们是在请求首次通过网关进入网格时设置的),但我的余额看起来像默认50:50 kubernetes服务的平衡。

我需要做些什么才能在服务间通信上实现相同的1:9平衡?我是否必须创建第二个“内部”网关来代替服务fqdn?我错过了一个定义吗?应该从pod中调用服务fqdn尊重虚拟服务路由吗?

使用的istio版本是1.0.1,使用kubernetes版本v1.11.1。

UPDATE按照建议部署了睡眠窗口(这次不依赖于演示命名空间的自动注入),而是按照睡眠示例中的描述手动完成

kubectl -n demo get deployment sleep -o wide
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS          IMAGES                                     SELECTOR
sleep     1         1         1            1           2m        
sleep,istio-proxy   tutum/curl,docker.io/istio/proxyv2:1.0.1   app=sleep

还将Virtualservice更改为0/100以查看它是否乍一看。不幸的是,这并没有太大变化:

export SLEEP_POD=$(kubectl get -n demo pod -l app=sleep -o jsonpath={.items..metadata.name})
kubectl -n demo exec -it $SLEEP_POD -c sleep curl http://helloworld
{"user- agent":"curl/7.35.0","host":"helloworld","accept":"*/*","version":"v2"}
kubectl -n demo exec -it $SLEEP_POD -c sleep curl http://helloworld
{"user-agent":"curl/7.35.0","host":"helloworld","accept":"*/*","version":"v1"}
kubectl -n demo exec -it $SLEEP_POD -c sleep curl http://helloworld
{"user-agent":"curl/7.35.0","host":"helloworld","accept":"*/*","version":"v2"}
kubectl -n demo exec -it $SLEEP_POD -c sleep curl http://helloworld
{"user-agent":"curl/7.35.0","host":"helloworld","accept":"*/*","version":"v1"}
kubectl -n demo exec -it $SLEEP_POD -c sleep curl http://helloworld
{"user-agent":"curl/7.35.0","host":"helloworld","accept":"*/*","version":"v2"
kubernetes istio
2个回答
1
投票

找到解决方案,其中一个先决条件(我忘了)是正确的路由需要命名端口:@see https://istio.io/docs/setup/kubernetes/spec-requirements/

错误:

spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 3000

对:

spec:
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 3000

使用名称http后,一切都像魅力


0
投票

路由规则在客户端进行评估,因此您需要确保运行curl的pod有一个Istio sidecar连接到它。如果它只是直接调用服务,则无法评估您设置的90-10规则,而是直接进入默认的kube循环路由。

Istio sleep sample是一个很好的用作测试客户端pod。

© www.soinside.com 2019 - 2024. All rights reserved.