마구잡

POD netns 보기 본문

Kubernetes

POD netns 보기

MAGUJOB 2023. 11. 21. 14:17
728x90

간단한 nginx 이미지로 생성한 POD

 

해당 파드를 json 형태로 확인 하면 해당 container ID를 확인 할 수 있다.

[root@hi-mn1 /]# kubectl get po nginx -ojson |jq |grep ID
      "cni.projectcalico.org/containerID": "5d124c0ac5dd287a6a87e5b2c845d596d46c614f80656e228b666d106e9d83c9",
        "containerID": "containerd://99182a06eb2a6870683d791048ea6900f47f84ede825162c7a99692818195b74",
        "imageID": "docker.io/library/nginx@sha256:67f9a4f10d147a6e04629340e6493c9703300ca23a2f7f3aa56fe615d75d31ca",

 

해당 container의 info를 확인

[root@hi-wn2 ~]# ctr -n k8s.io c info  99182a06eb2a6870683d791048ea6900f47f84ede825162c7a99692818195b74
                                **"KUBERNETES_SERVICE_HOST=10.96.0.1",**
                "KUBERNETES_SERVICE_PORT=443",
                "KUBERNETES_SERVICE_PORT_HTTPS=443",
                "KUBERNETES_PORT=tcp://10.96.0.1:443",
                "KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443",
...
{
                    "type": "network",
                    "path": "/proc/44765/ns/net"
                }

 

네트워크 네임스페이스 정보를 획득했다!

이제 해당 노드의 /proc/44765/ns/net로 이동하여 확인 해보자.

[root@hi-wn2 ns]# pwd
/proc/1/ns
[root@hi-wn2 ns]# ll
total 0
lrwxrwxrwx. 1 root root 0 Aug  9 15:33 cgroup -> 'cgroup:[4026531835]'
lrwxrwxrwx. 1 root root 0 Aug  9 15:33 ipc -> 'ipc:[4026531839]'
lrwxrwxrwx. 1 root root 0 Aug  9 15:33 mnt -> 'mnt:[4026531840]'
**lrwxrwxrwx. 1 root root 0 Aug  9 15:33 net -> 'net:[4026532184]'**
lrwxrwxrwx. 1 root root 0 Aug  4 15:13 pid -> 'pid:[4026531836]'
lrwxrwxrwx. 1 root root 0 Aug  9 15:33 pid_for_children -> 'pid:[4026531836]'
lrwxrwxrwx. 1 root root 0 Aug  9 15:33 time -> 'time:[4026531834]'
lrwxrwxrwx. 1 root root 0 Aug  9 15:33 time_for_children -> 'time:[4026531834]'
lrwxrwxrwx. 1 root root 0 Aug  9 15:33 user -> 'user:[4026531837]'
lrwxrwxrwx. 1 root root 0 Aug  9 15:33 uts -> 'uts:[4026531838]'

[root@hi-wn2 net]# cd /proc/44765/ns/
[root@hi-wn2 ns]# ll
total 0
lrwxrwxrwx. 1 65535 65535 0 Aug 10 15:16 cgroup -> 'cgroup:[4026531835]'
lrwxrwxrwx. 1 65535 65535 0 Aug  4 15:20 ipc -> 'ipc:[4026532697]'
lrwxrwxrwx. 1 65535 65535 0 Aug 10 15:16 mnt -> 'mnt:[4026532695]'
**lrwxrwxrwx. 1 65535 65535 0 Aug  4 15:20 net -> 'net:[4026532612]'**
lrwxrwxrwx. 1 65535 65535 0 Aug  9 14:11 pid -> 'pid:[4026532698]'
lrwxrwxrwx. 1 65535 65535 0 Aug 10 15:16 pid_for_children -> 'pid:[4026532698]'
lrwxrwxrwx. 1 65535 65535 0 Aug 10 15:16 time -> 'time:[4026531834]'
lrwxrwxrwx. 1 65535 65535 0 Aug 10 15:16 time_for_children -> 'time:[4026531834]'
lrwxrwxrwx. 1 65535 65535 0 Aug 10 15:16 user -> 'user:[4026531837]'
lrwxrwxrwx. 1 65535 65535 0 Aug  4 15:20 uts -> 'uts:[4026532696]'
[root@hi-wn2 ns]#

 

대략 위와 같은 정보를 출력한다. Host의 네임스페이스와 다른 네임스페이스를 사용한다.

해당 POD의 인터페이스를 확인해 실제 IP를 가지고 있는지 보자!

[cocktail@hi-mn1 ~]$ kubectl get po -owide
NAME      READY   STATUS    RESTARTS        AGE     IP           NODE     NOMINATED NODE   READINESS GATES
**busybox   1/1     Running   121 (53m ago)   6d18h   10.4.8.193   hi-wn1   <none>           <none>**
nginx     1/1     Running   0               6d18h   10.4.6.193   hi-wn2   <none>           <none>

 

찾아낸 프로세스의 CNI를 획득한다.

[root@hi-wn2 ~]# ip netns identify 44765
cni-2bfd9b4c-198b-3963-34aa-812bcb90b7b1 

 

그럼 진짜 해당 프로세스의 CNI가 맞는가? 확인해보자.

[root@hi-wn2 ~]# ip netns pids cni-2bfd9b4c-198b-3963-34aa-812bcb90b7b1
44765
44936
44970
44971
44972
44973
[root@hi-wn2 ns]# ip netns identify 44936
cni-2bfd9b4c-198b-3963-34aa-812bcb90b7b1
[root@hi-wn2 ns]# ip netns identify 44970
cni-2bfd9b4c-198b-3963-34aa-812bcb90b7b1
[root@hi-wn2 ns]# ip netns identify 44971
cni-2bfd9b4c-198b-3963-34aa-812bcb90b7b1
[root@hi-wn2 ns]# ip netns identify 44972
cni-2bfd9b4c-198b-3963-34aa-812bcb90b7b1
[root@hi-wn2 ns]# ip netns identify 44973
cni-2bfd9b4c-198b-3963-34aa-812bcb90b7b1

 

nginx pod의 IP를 확인 할 수 있다.

[root@hi-wn2 ~]# ip netns exec cni-2bfd9b4c-198b-3963-34aa-812bcb90b7b1  ip -4 a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
4: eth0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default  link-netnsid 0
    **inet 10.4.6.193/32 scope global eth0**
       valid_lft forever preferred_lft forever

✅ 위와 같은 Calico 인터페이스에 연결 되어있다.

10: calic440f455693@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default
    link/ether ee:ee:ee:ee:ee:ee brd ff:ff:ff:ff:ff:ff link-netns **cni-2bfd9b4c-198b-3963-34aa-812bcb90b7b1**
    inet6 fe80::ecee:eeff:feee:eeee/64 scope link
       valid_lft forever preferred_lft forever
728x90