使用限制性出口网络策略访问服务/ kubernetes

时间:2019-08-07 15:03:21

标签: kubernetes google-kubernetes-engine istio

设置:

gke: 1.13.7-gke.8
istio: 1.1.7-gke.0 with ingress and egress gateways
Istio mTLS: Strict

我有2个名称空间:

  • 默认
  • 发展

我所拥有的:

  • 服务A部署到名称空间development
  • 服务A除进入白名单的域外,不应具有群集外的出口流量(因此应能够与名称空间default和development和example.com通信)
  • 服务A需要访问kubernetes.default.svc.cluster.local
  • 我有example.com的出口规则(工作正常)

没有政策,我可以访问kubernetes.default.svc.cluster.local

/app # curl -I kubernetes.default.svc.cluster.local:443
curl: (8) Weird server reply

/app # curl -I example.com
HTTP/1.1 200 OK

Default标签为default-namespace=true的命名空间

我的政策

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: egress-policy
  namespace: development
spec:
  podSelector: {}
  policyTypes:
    - Egress
  egress:
    - to:
        - namespaceSelector:
            matchLabels:
              kube-system: 'true'
      ports:
        - protocol: UDP
          port: 53
    - to:
        - namespaceSelector:
            matchLabels:
              istio: system
    - to:
        - namespaceSelector:
            matchLabels:
              environment: development
    - to:
        - namespaceSelector:
            matchLabels:
              default-namespace: 'true'

应用此政策后:

/app # curl -I kubernetes.default.svc.cluster.local:443
curl: (56) Recv failure: Connection reset by peer

/app # curl -I example.com
HTTP/1.1 200 OK

可以访问default命名空间中的其他服务。

如何通过istio出口和限制性出口网络策略使kubernetes.default.svc.cluster.local工作?

已添加

kubectl get ns --show-labels
NAME           STATUS   AGE    LABELS
default        Active   42d    default-namespace=true,istio-injection=enabled
development    Active   2d2h   environment=development,istio-injection=enabled
istio-system   Active   2d2h   addonmanager.kubernetes.io/mode=Reconcile,istio-injection=disabled,istio=system,k8s-app=istio
kube-public    Active   42d    <none>
kube-system    Active   42d    kube-system=true

Istio mTLS (beta)设置为Permissive并没有帮助

0 个答案:

没有答案