728x90
반응형
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-port-from-namespace
namespace: devops
spec:
podSelector: {}
policyTypes:
- Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
project: llm
ports:
- protocol: TCP
port: 80
위와 같은 NetworkPolicy는
"project= llm 이라는 레이블이 있는 네임스페이스에서 속한 pod들만 devops 네임스페이스의 모든 pod에 대해 TCP 80번 포트로 접근할 수 있도록 설정한 것"
테스트
kubectl create namespace test-ns
kubectl run test-wget --rm -it --image=busybox --namespace=test-ns --command -- sh
wget -qO- http://web-server.devops.svc.cluster.local:80
-> 안됨
kubectl label namespace test-ns project=llm
kubectl get ns --show-labels
kubectl run test-wget --rm -it --image=busybox --namespace=test-ns --command -- sh
wget -qO- http://web-server.devops.svc.cluster.local:80
-> 레이블을 설정 한 후 가능
728x90
'자질구레' 카테고리의 다른 글
git 레포지토리 이동 (0) | 2025.06.16 |
---|---|
[kubernetes] 서비스(Service)가 필요한 이유 (0) | 2025.02.02 |
[Linux] "Warning: The unit file, source configuration file or drop-ins of XXX.service changed on disk. Run 'systemctl daemon-reload' to reload units." (0) | 2025.01.30 |
맥북 시간 이상할 때 (1) | 2024.12.15 |
시간복잡도, Big O, 점근적 표기법 (0) | 2024.12.12 |