如何使用 Istio Ingress 隔离内部和外部负载?
How do I segregate internal and external loads using Istio Ingress?
在我的 Kubernetes 集群上,我想隔离对内部和外部应用程序的访问。在下面的示例中,我将 app1 和 app2 都暴露在互联网上,但希望只有 app1 暴露在互联网上,而 app2 仅供内部 vnet 中的用户使用。
我最初的想法是只创建一个新服务(蓝框)并使用 "internal=true" 属性,我的云提供商会创建内部 IP,我很好。问题是网关指向部署 (pods),因此似乎要创建一个内部入口,我需要复制所有 3 个蓝色框。
有没有一种简单的方法可以在没有新部署(蓝框)的情况下绑定新服务和网关,或者可以通过策略限制外部访问?
根据我的知识,您可以创建 virtual service 来做到这一点
The reserved word mesh is used to imply all the sidecars in the mesh. When this field is omitted, the default gateway (mesh) will be used, which would apply the rule to all sidecars in the mesh. If a list of gateway names is provided, the rules will apply only to the gateways. To apply the rules to both gateways and sidecars, specify mesh as one of the gateway names.
你可以在 Whosebug 上查看我的另一个答案,这里完全再现了我使用网关从外部访问的虚拟服务(例如只是一个卷曲)的问题,如果你想要要使其仅在网格内,只需删除此网关并仅保留网格一,如下例所示。
特别是虚拟服务
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: nginxvirt
spec:
gateways:
- mesh #inside cluster
hosts:
- nginx.default.svc.cluster.local #inside cluster
http:
- name: match-myuid
match:
- uri:
prefix: /
rewrite:
uri: /
route:
- destination:
host: nginx.default.svc.cluster.local
port:
number: 80
以及一些外部和内部测试
外部
使用额外的网关来允许外部流量
curl -v -H "host: nginx.com" loadbalancer_istio_ingress_gateway_ip/
HTTP/1.1 200 OK
没有额外的网关来允许外部流量,只有网状网络
curl -v -H "host: nginx.com" loadbalancer_istio_ingress_gateway_ip/
HTTP/1.1 404 Not Found
内部
Created some basic ubuntu pod for tests
kubectl exec -ti ubu1 -- /bin/bash
有网状网关
curl -v nginx/
HTTP/1.1 200 OK
没有网状网关
curl -v nginx/
HTTP/1.1 404 Not Found
基于此,您可以使用网关 "mesh",它只能在网格内部工作,不允许外部请求。
如果你想测试,我可以给你带来一包 yaml 来测试。
如果这回答了您的问题或者您还有其他问题,请告诉我。
在我的 Kubernetes 集群上,我想隔离对内部和外部应用程序的访问。在下面的示例中,我将 app1 和 app2 都暴露在互联网上,但希望只有 app1 暴露在互联网上,而 app2 仅供内部 vnet 中的用户使用。
我最初的想法是只创建一个新服务(蓝框)并使用 "internal=true" 属性,我的云提供商会创建内部 IP,我很好。问题是网关指向部署 (pods),因此似乎要创建一个内部入口,我需要复制所有 3 个蓝色框。
有没有一种简单的方法可以在没有新部署(蓝框)的情况下绑定新服务和网关,或者可以通过策略限制外部访问?
根据我的知识,您可以创建 virtual service 来做到这一点
The reserved word mesh is used to imply all the sidecars in the mesh. When this field is omitted, the default gateway (mesh) will be used, which would apply the rule to all sidecars in the mesh. If a list of gateway names is provided, the rules will apply only to the gateways. To apply the rules to both gateways and sidecars, specify mesh as one of the gateway names.
你可以在 Whosebug 上查看我的另一个答案,这里完全再现了我使用网关从外部访问的虚拟服务(例如只是一个卷曲)的问题,如果你想要要使其仅在网格内,只需删除此网关并仅保留网格一,如下例所示。
特别是虚拟服务
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: nginxvirt
spec:
gateways:
- mesh #inside cluster
hosts:
- nginx.default.svc.cluster.local #inside cluster
http:
- name: match-myuid
match:
- uri:
prefix: /
rewrite:
uri: /
route:
- destination:
host: nginx.default.svc.cluster.local
port:
number: 80
以及一些外部和内部测试
外部
使用额外的网关来允许外部流量
curl -v -H "host: nginx.com" loadbalancer_istio_ingress_gateway_ip/
HTTP/1.1 200 OK
没有额外的网关来允许外部流量,只有网状网络
curl -v -H "host: nginx.com" loadbalancer_istio_ingress_gateway_ip/
HTTP/1.1 404 Not Found
内部
Created some basic ubuntu pod for tests
kubectl exec -ti ubu1 -- /bin/bash
有网状网关
curl -v nginx/
HTTP/1.1 200 OK
没有网状网关
curl -v nginx/
HTTP/1.1 404 Not Found
基于此,您可以使用网关 "mesh",它只能在网格内部工作,不允许外部请求。
如果你想测试,我可以给你带来一包 yaml 来测试。
如果这回答了您的问题或者您还有其他问题,请告诉我。