0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

KubernetesのPodにインターネットへのアクセスを許可しつつ他の全てのPodへの通信を禁止する方法

Last updated at Posted at 2025-05-29

目的・但し書き

Podにシステム系の通信を許可したくない
あっているかは不確かなので間違っていたらコメントお願いします。
(「多分あってる気がする」程度です)

方法

お馴染みのNetworkPolicyで制限
今回はOutBoundを制限してみた

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: deny-egress2system-np
spec:
  egress:
  - to:
    - ipBlock:
        cidr: 0.0.0.0/0
        except:
        - 172.16.0.0/12 # host network v4
    - ipBlock:
        cidr: ::/0
        except:
        - fc00::/7 # host network v6
  - to:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: kube-system
      podSelector:
        matchLabels:
          k8s-app: kube-dns
  podSelector: {}
  policyTypes:
  - Egress

*多分あっていますがテキトーに検証しただけなので保証できません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?