[EKS] Network Policy

Hyun-Sung Kim·2025년 1월 5일

Kubernetes

목록 보기
15/24

Calico

< Calico란? >

  • K8S용 네트워크 정책 엔진으로서, 특정 namespace 및 pod에서 network 트래픽을 제어
  • pod 및 container에 대한 방화벽 역할을 함
  • kube-system에 demonset으로 설치 -> node 당 하나씩 들어감

특정 namespace의 모든 객체에 대한 트래픽을 거부하기

```
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny
  namespace: web
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress
  • Ingress, Egress, 및 podSelector 섹션이 모두 비어 있기 때문에 구성 파일은 web 네임스페이스 내의 모든 트래픽을 거부
  • 특정 pod label을 정의하면 특정 pod 또는 pod 집합에 대한 엑세스를 거부할 수도 있다.

특정 pod에 대한 inbound 트래픽 허용하기

```
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: nginx-allow-external
  namespace: web
spec:
  podSelector:
    matchLabels:
      app: nginx
  ingress:
  - ports:
    - port: 80
    from: []
  • podSelector 및 ingress 섹션에 모든 source에서 port 80을 통해 app=nginx 태그가 지정된 모든 pod로 들어오는 트래픽을 허용
profile
Cloud Engineer

0개의 댓글