본문 바로가기
cloud/k8s(문제풀이)

[따배쿠 CKA]30.Network Policy

by mozi2 2022. 9. 1.
반응형
작업 클러스터: hk8s
Create a new NetworkPolicy named allow-port-from-namespace in the exiting namespace devops.

Ensure that the new NetworkPolicy allow pods in namespace migops to connect to port 80 of Pods in namespace devops.
kubectl get namespaces migops --show-labels 

 : 강의에 의하면 labels에는 team=migops

kubectl get namespace devops --show-labels

 : 강의에 의하면 labels에는 team=devops

k get pod -n devops --show-labels

NAME       LABELS

web           app=web

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-port-from-namespace
  namespace: devops
spec:
  podSelector:
    matchLabels:
      app: web
  policyTypes:
    - Ingress
  ingress:
    - from:
        - namespaceSelector:
            matchLabels:
              team: migops
        - podSelector: {}
      ports:
        - protocol: TCP
          port: 80
728x90
반응형