我有安装了 Istio 的 Kubernetes 集群。我有两个 pod,例如 sleep1 和 sleep2(安装了 curl 的容器)。我想将 istio 配置为允许从 sleep1 到 www.google.com 的流量,并禁止从 sleep2 到 www.google.com 的流量。
所以,我创建了 ServiceEntry:
---
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: google
spec:
hosts:
- www.google.com
- google.com
ports:
- name: http-port
protocol: HTTP
number: 80
resolution: DNS
网关
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: istio-egressgateway
spec:
selector:
istio: egressgateway
servers:
- port:
number: 80
name: http-port
protocol: HTTP
hosts:
- "*"
两个虚拟服务(mesh->egress,egress->google)
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: mesh-to-egress
spec:
hosts:
- www.google.com
- google.com
gateways:
- mesh
http:
- match:
- gateways:
- mesh
port: 80
route:
- destination:
host: istio-egressgateway.istio-system.svc.cluster.local
port:
number: 80
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: egress-to-google-int
spec:
hosts:
- www.google.com
- google.com
gateways:
- istio-egressgateway
http:
- match:
- gateways:
- istio-egressgateway
port: 80
route:
- destination:
host: google.com
port:
number: 80
weight: 100
结果,我可以从两个 pod 卷曲 google。
又是一个问题:我可以允许从 sleep1 到 www.google.com 的流量并禁止从 sleep2 到 www.google.com 的流量吗?我知道这可能与 kubernetes NetworkPolicy 和黑/白名单(https://istio.io/docs/tasks/policy-enforcement/denial-and-list/)有关,但这两种方法都禁止(允许)流量到特定的 ips 或者我错过了什么?