쿠버네티스 클러스터의 네트워크 구성에 문제가 생기면
다음과 같은 에러를 만날 수 있습니다.
root@controlplane:/# k get all -n triton
NAME READY STATUS RESTARTS AGE
pod/mysql 0/1 ContainerCreating 0 67s
pod/webapp-mysql-54db464f4f-5jtq2 0/1 ContainerCreating 0 67s
...
...
root@controlplane:/# k describe pod/webapp-mysql-54db464f4f-5jtq2
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 14m default-scheduler Successfully assigned triton/webapp-mysql-54db464f4f-648sr to controlplane
Warning FailedCreatePodSandBox 14m kubelet Failed to create pod sandbox: rpc error: code = Unknown desc = [failed to set up sandbox container "7fba1fad2f3e8297e080cfd1ab1d75615f1d036acf0eb6182514dcebbf2cf089" network for pod "webapp-mysql-54db464f4f-648sr": networkPlugin cni failed to set up pod "webapp-mysql-54db464f4f-648sr_triton" network: unable to allocate IP address: Post "http://127.0.0.1:6784/ip/7fba1fad2f3e8297e080cfd1ab1d75615f1d036acf0eb6182514dcebbf2cf089": dial tcp 127.0.0.1:6784: connect: connection refused, failed to clean up sandbox container "7fba1fad2f3e8297e080cfd1ab1d75615f1d036acf0eb6182514dcebbf2cf089" network for pod "webapp-mysql-54db464f4f-648sr": networkPlugin cni failed to teardown pod "webapp-mysql-54db464f4f-648sr_triton" network: Delete "http://127.0.0.1:6784/ip/7fba1fad2f3e8297e080cfd1ab1d75615f1d036acf0eb6182514dcebbf2cf089": dial tcp 127.0.0.1:6784: connect: connection refused]
Normal SandboxChanged 4m (x47 over 14m) kubelet Pod sandbox changed, it will be killed and re-created.
에러 메세지를 보면 CNI 문제인 것처럼 보입니다.
이때 클러스터가 사용중인 CNI 를 확인할 필요가 있겠죠?
/opt/cni/bin 경로 확인
/opt/cni/bin 경로에서 클러스터에 설치된 CNI 플러그인을 확인할 수 있습니다.
root@controlplane:/# ls /opt/cni/bin/ -al
total 81676
drwxrwxr-x 2 root root 4096 Sep 4 00:52 .
drwxr-xr-x 3 root root 4096 Aug 25 2021 ..
-rwxr-xr-x 1 root root 4159518 May 13 2020 bandwidth
-rwxr-xr-x 1 root root 4671647 May 13 2020 bridge
-rwxr-xr-x 1 root root 12124326 May 13 2020 dhcp
-rwxr-xr-x 1 root root 5945760 May 13 2020 firewall
-rwxr-xr-x 1 root root 3069556 May 13 2020 flannel
-rwxr-xr-x 1 root root 4174394 May 13 2020 host-device
-rwxr-xr-x 1 root root 3614480 May 13 2020 host-local
-rwxr-xr-x 1 root root 4314598 May 13 2020 ipvlan
-rwxr-xr-x 1 root root 3209463 May 13 2020 loopback
-rwxr-xr-x 1 root root 4389622 May 13 2020 macvlan
-rwxr-xr-x 1 root root 3939867 May 13 2020 portmap
-rwxr-xr-x 1 root root 4590277 May 13 2020 ptp
-rwxr-xr-x 1 root root 3392826 May 13 2020 sbr
-rwxr-xr-x 1 root root 2885430 May 13 2020 static
-rwxr-xr-x 1 root root 3356587 May 13 2020 tuning
-rwxr-xr-x 1 root root 4314446 May 13 2020 vlan
lrwxrwxrwx 1 root root 18 Sep 4 00:52 weave-ipam -> weave-plugin-2.8.1
lrwxrwxrwx 1 root root 18 Sep 4 00:52 weave-net -> weave-plugin-2.8.1
-rwxr-xr-x 1 root root 11437320 Sep 4 00:52 weave-plugin-2.8.1
/etc/cni/net.d/ 경로에서 CNI 플러그인 설정 확인하기
그러면 사용중인 CNI 플러그인의 설정은 어디 있을까요?
바로 /etc/cni/net.d/ 경로에 있습니다.
weave 설정 파일만 존재하고 /opt/cni/bin 경로의 내용을 미루어 봤을 때
이 클러스터는 CNI로 weave를 쓰도록 구성되어 있다는 추론이 가능합니다.
root@controlplane:/# ls -al /etc/cni/net.d/
total 12
drwxr-xr-x 2 root root 4096 Sep 4 00:52 .
drwxr-xr-x 3 root root 4096 Sep 4 00:52 ..
-rw-r--r-- 1 root root 318 Sep 4 00:52 10-weave.conflist
weave pod 존재 유무 확인
그렇다면 왜 에러가 발생했고 어플리케이션 pod 가 구동되지 않은 것일까요?
weave는 CNI 플러그인이고 설치 및 동작되고 있는 경우
weave pod이 kube-system 네임스페이스에서 확인되어야 합니다.
root@controlplane:/# k get all -n kube-system
NAME READY STATUS RESTARTS AGE
pod/coredns-74ff55c5b-s8jgh 1/1 Running 0 33m
pod/coredns-74ff55c5b-vnsv7 1/1 Running 0 33m
pod/etcd-controlplane 1/1 Running 0 34m
pod/kube-apiserver-controlplane 1/1 Running 0 34m
pod/kube-controller-manager-controlplane 1/1 Running 0 34m
pod/kube-proxy-6jssm 1/1 Running 0 33m
pod/kube-scheduler-controlplane 1/1 Running 0 34m
어라?
그런데 시험 환경에는 weave 관련된 이름이 보이지 않습니다.
weave.works 웹 사이트에서 아래 경로를 방문하여
커스텀 k8s용 설치 manifest 파일을 확인해 봅시다.
https://www.weave.works/docs/net/latest/kubernetes/kube-addon/
Integrating Kubernetes via the Addon
The following topics are discussed: Installation Before installing Weave Net, you should make sure the following ports are not blocked by your firewall: TCP 6783 and UDP 6783/6784. For more details, see the FAQ. Weave Net can be installed onto your CNI-ena
www.weave.works
$ kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
위 명령을 수행하여 weave CNI 플러그인을 설치합시다.
weave pod 실행상태 확인
이제 weave plugin이 설치되었으니 pod가 구동되는지 확인해 보겠습니다.
root@controlplane:/# k get all -n kube-system
NAME READY STATUS RESTARTS AGE
pod/coredns-74ff55c5b-s8jgh 1/1 Running 0 40m
pod/coredns-74ff55c5b-vnsv7 1/1 Running 0 40m
pod/etcd-controlplane 1/1 Running 0 40m
pod/kube-apiserver-controlplane 1/1 Running 0 40m
pod/kube-controller-manager-controlplane 1/1 Running 0 40m
pod/kube-proxy-6jssm 1/1 Running 0 40m
pod/kube-scheduler-controlplane 1/1 Running 0 40m
pod/weave-net-9kbqw 2/2 Running 0 43s
아까 보이지 않던 pod/weave-net-xxxxx가 보입니다.
이제 서비스 클러스터의 pod 상태를 보겠습니다.
root@controlplane:/# k get all -n triton
NAME READY STATUS RESTARTS AGE
pod/mysql 1/1 Running 0 12m
pod/webapp-mysql-54db464f4f-5jtq2 1/1 Running 0 12m
pod의 상태가 Running으로 바뀌었습니다.
describe로 상태를 보면 특별히 CNI 이슈가 해소된 것에 대한 메세지는 남지 않는 것 같습니다.
다만 pod가 잘 동작하는 것으로 이슈가 해소된 것을 알 수 있겠네요!
k8s 관리자라면 꼭 공부해야 하는 CKA는 아래 강의를 추천드립니다.
강사가 제공하는 별도 Lab 환경이 정말 진국인 강의입니다!
Certified Kubernetes Administrator (CKA) Practice Exam Tests
Prepare for the Certified Kubernetes Administrators Certification with live practice tests right in your browser - CKA
www.udemy.com
조금더 개발자에게 필요한 내용을 담은 CKAD를 준비한다면 역시 아래 강의가 좋겠습니다!
Kubernetes Certified Application Developer (CKAD) Training
Learn concepts and practice for the Kubernetes Certification with hands-on labs right in your browser - DevOps - CKAD
www.udemy.com
본 포스팅은 제휴마케팅을 통해 소정의 수수료를 지급 받을 수 있습니다.