istio里边另外一个概念就是 Ingress Gateways 了,我们先说一下为什么需要这个东西
前边说的VirtualService可以来控制说发送到我们service的流量,10%, 90%之类的,但是,前边说的例子是一个后端服务
也就是说,请求这个后端的也是pod,如下:
但是如果是前端的pod, 不经过任何pod直接发动到service对应的pod话,我们前边的traffic 流量控制就会失效(因为少了一个proxy)
解决办法也很简单,就是在我们的流量到达具体的pod之前,让他先经过一个有proxy的pod
其实我们在istio namespace下已经有一个专门做这个pod了,我们只需要创建一个新的ingress gateway 就可以了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: ingress-gateway-configuration spec: selector: istio: ingressgateway # use Istio default gateway implementation servers: - port: number: 80 name: http protocol: HTTP hosts: - "*" # Domain name of the external website --- |
也就是说,如果你直接请求我们这个ingressgateway的svc地址的话,我们的pod 就会是ingress nginx的角色,会帮我们转发我们的流量到具体的service
但是上边的例子中,我们只定义了接受的域名,并没有定义后端抓发到哪去,所以仅仅有这个还是不够的,我们需要在VirtualService 做相应的配置,也就是把VirtualService 和ingress gateway串联起来,这样就可以到达我们的pod里了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
--- kind: VirtualService apiVersion: networking.istio.io/v1alpha3 metadata: name: fleetman-webapp namespace: default spec: hosts: # which incoming host are we applying the proxy rules to??? - "*" # Copy the value in the gateway hosts - usually a Domain Name gateways: - ingress-gateway-configuration http: - route: - destination: host: fleetman-webapp subset: original weight: 90 - destination: host: fleetman-webapp subset: experimental weight: 10 --- kind: DestinationRule apiVersion: networking.istio.io/v1alpha3 metadata: name: fleetman-webapp namespace: default spec: host: fleetman-webapp subsets: - labels: version: original name: original - labels: version: experimental name: experimental |
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021