Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

전공공부

Traffic 본문

Study/K8S

Traffic

monitor 2023. 4. 2. 15:30

1. Traffic

Ingress & Egress

Ingress : Traffic이 해당 서버 또는 서비스로 들어오는 곳 / Egress : Traffic이 해당 서버 또는 서비스 나가는 것

 

 

 

Network Security

 

예제) 웹에서 바로 DB 서버로 접근 하는 것을 막기 위해서 필요하다.

 

only allow ingress traffic from api Pod on Port 3306 을 적용 할 수 있어야 한다.

 

Network Policy - Selector, Rules

selector로 Label에 따른 접근 제어

podSelector:
 matchLabels:
  role: db #이런식으로 role이 DB 인 것만 접근 가능하게 할 수 있다.

어떤 포트 번호로 어떤 포드 이름으로 들어올 지 지

policyTypes:
- Ingress
ingress:
- from:
  - podSelector:
      matchLabels:
        name: api-pod
  ports:
  - protocol: TCP
    port: 3306

최종

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: db-policy
spec:
  podSelector:
    matchLabels:
      role: db # Label role이 db로 지정된 것만 접근 가능
  policyTypes: #서비스 기준 안으로 들어오는 Ingress에서의 network 정책임
  - Ingress
  ingress:
  - from:
    - podSelector: 
        matchLabels:
          name: api-pod #해당 api포드에서 들어오는 3306 포드만 허가 하겠다는 것임
      namespaceSelector:
        matchLabels:
          name: prod #prod의 네임스페이스에서만 접근가능함
    ports:
    - protocol: TCP
      port: 3306

 

 

백업 서버가 쿠버네티스 클러스터 외부에 존재 할 때의 네트워크 설정

백업 서버의 IP : 192.168.5.10

 

의 상황으로 가정하면

 

 

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: db-policy
spec:
  podSelector:
    matchLabels:
      role: db # Label role이 db로 지정된 것만 접근 가능
  policyTypes: #서비스 기준 안으로 들어오는 Ingress에서의 network 정책임
  - Ingress
  ingress:
  - from:
    - podSelector: 
        matchLabels:
          name: api-pod #해당 api포드에서 들어오는 3306 포드만 허가 하겠다는 것임
      namespaceSelector:
        matchLabels:
          name: prod #prod의 네임스페이스에서만 접근가능함
    - ipBlock:
        cidr: 192.168.5.10/32 #허용된 IP를 설정 할 수 있다.
    ports:
    - protocol: TCP
      port: 3306

 

이렇게 지정 가능하다.( IP Block은 다른 배열이니 pod,namespace의 설정과 별개로 접근 가능하다.)

 

Egress

Egress로 백업 서버에서 들어오는 Network 설정은 아래와 같이 할 수 있다.

 

 

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: db-policy
spec:
  podSelector:
    matchLabels:
      role: db # Label role이 db로 지정된 것만 접근 가능
  policyTypes: #서비스 기준 안으로 들어오는 Ingress에서의 network 정책임
  - Ingress
  - Egress
  ingress:
  - from:
    - podSelector: 
        matchLabels:
          name: api-pod #해당 api포드에서 들어오는 3306 포드만 허가 하겠다는 것임
      namespaceSelector:
        matchLabels:
          name: prod #prod의 네임스페이스에서만 접근가능함
    - ipBlock:
        cidr: 192.168.5.10/32 #허용된 IP를 설정 할 수 있다.
    ports:
    - protocol: TCP
      port: 3306
  egress: #나가는 부분 설정
  - to:
    - ipBlock:
        cidr: 192.168.5.10/32
    ports:
    - protocol: TCP
      port: 80

 

'Study > K8S' 카테고리의 다른 글

Docker로 이미지 만들기  (0) 2023.04.02
Volumes & Persistent Volumes & Persistent Volumes Claim  (0) 2023.04.02
Ingress  (0) 2023.04.02
Services  (0) 2023.04.01
Jobs & Cronjob  (1) 2023.03.28