We have deployed a new pod called secure-pod and a service called secure-service. Incoming or Outgoing connections to this pod are not working.
Troubleshoot why this is happening.
Make sure that incoming connection from the pod webapp-color are successful.
Important: Don't delete any current objects deployed.
Important: Don't Alter Existing Objects!
Connectivity working?
서비스 확인
controlplane ~ ➜ kubectl get service -A
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 114m
default secure-service ClusterIP 10.96.240.77 <none> 80/TCP 59s
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 114m
파드 확인
controlplane ~ ➜ kubectl get pods
NAME READY STATUS RESTARTS AGE
secure-pod 1/1 Running 0 52s
webapp-color 1/1 Running 0 18m
webapp-color 컨테이너에서 명령 실행
controlplane ~ ➜ kubectl exec -it webapp-color -- sh
/opt # nc -v -z -w 2 secure-service 80
nc: secure-service (10.96.240.77:80): Operation timed out
network policy yaml 파일 생성
controlplane ~ ➜ kubectl get netpol default-deny -o yaml > netpol.yaml
label 확인
controlplane ~ ➜ kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
secure-pod 1/1 Running 0 12m run=secure-pod
webapp-color 1/1 Running 0 29m name=webapp-color
netpol.yaml에서 label 추가 및 Port 추가
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
creationTimestamp: "2023-11-09T05:31:01Z"
generation: 1
name: network-policy
namespace: default
resourceVersion: "9392"
uid: 3a239d1b-ee91-4041-8ebd-beee7d250faa
spec:
podSelector:
matchLabels:
run: secure-pod
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
name: webapp-color
ports:
- protocol: TCP
port: 80
status: {}
controlplane ~ ➜ kubectl apply -f netpol.yaml --force
networkpolicy.networking.k8s.io/network-policy created
'k8s > Kubernates' 카테고리의 다른 글
[k8s] imperative command (0) | 2023.11.09 |
---|---|
kubernetes 커맨드 shortcuts (0) | 2023.11.09 |
[CKAD] rewrite-target 옵션 (0) | 2023.11.02 |
[CKAD/Lab] Imperative commands (0) | 2023.09.25 |
[CKAD/Lab] - namespace (0) | 2023.09.24 |