개요
Pod 배포 중 STATUS가 ContainerCreating 상태에서 넘어가지 않아 kubectl describe 커맨드로 이벤트 조회해보니 아래와 같은 에러가 발생 중이었음.
$ kubectl describe pod/pod1 | grep -A5 "Events"
Events:
  Type     Reason                  Age                   From               Message
  ----     ------                  ----                  ----               -------
  Normal   Scheduled               5m47s                 default-scheduler  Successfully assigned default/pod1 to k8s-node2
  Warning  FailedCreatePodSandBox  5d1h                  kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox "129c8367ced36381a568a2afb3ff943a86bf2e64dd60b3d742b28517e9e2b5c5": plugin type="calico" failed (add): error getting ClusterInformation: connection is unauthorized: Unauthorized
  Normal   SandboxChanged          5d1h (x25 over 5d1h)  kubelet            Pod sandbox changed, it will be killed and re-created.찾아보니 Calico를 사용하는 경우 종종 발생하는 에러라고 한다.
참고로 FailedCreatePodSandBox 오류는 다음과 같은 종류가 있음.
(failed-to-create-pod-sandbox-error)
- Failed Find Plugin
- Failed To assign IP
- Can not allocated Memory
하지만 오늘 내가 발생한 오류는 위 종류의 에러가 아닌 다음과 같은 에러가 발생하였음 - Unauthorized
현상
Calico Pod가 정상적으로 Running 상태인지 확인.
$ kubectl get pod -n calico-system
NAME                                       READY   STATUS    RESTARTS        AGE
calico-kube-controllers-789dc4c76b-ckxh8   1/1     Running   1 (7d11h ago)   8d
calico-node-5s97x                          1/1     Running   0               25h
calico-node-7rfkc                          0/1     Running   1 (14h ago)     25h
calico-node-k745m                          1/1     Running   0               25h
calico-typha-7ddc4b78fd-k95l2              1/1     Running   10 (14h ago)    8d
calico-typha-7ddc4b78fd-qbmnn              1/1     Running   0               8d
csi-node-driver-f9rsx                      2/2     Running   0               8d
csi-node-driver-h27wm                      2/2     Running   0               8d
csi-node-driver-s7xwr                      2/2     Running   2 (7d11h ago)   8d모두 정상적임에도 불구하고 위와 같은 에러는 계속 되고있음.
해결 방법
- Calico를 삭제하고 재설치한다
- Kubernetes Calico를 재기동 시킨다.
위 두 방법을 모두 다뤄볼거다.
1번 방법 (Calico 재설치)
먼저 calico를 삭제하자 (calico.yaml 주소의 경우 나는 누군가 커스텀 해놓은 것을 apply 한 것이기에 calico 공식 주소와 다름)
[Calico 공식]
kubectl delete -f https://raw.githubusercontent.com/k8s-1pro/install/main/ground/k8s-1.27/calico-3.25.1/calico.yaml
kubectl delete -f https://raw.githubusercontent.com/k8s-1pro/install/main/ground/k8s-1.27/calico-3.25.1/calico-custom.yaml대부분 정상적으로 지워졌으면 다시 재설치
kubectl create -f https://raw.githubusercontent.com/k8s-1pro/install/main/ground/k8s-1.27/calico-3.25.1/calico.yaml
kubectl create -f https://raw.githubusercontent.com/k8s-1pro/install/main/ground/k8s-1.27/calico-3.25.1/calico-custom.yaml2번 방법 (Calico 재기동)
calico-node 재시작
kubectl rollout restart ds -n calico-system calico-node문제가 됐던 Pod 다시 조회
kubectl describe pod/pod1 | grep -A5 "Events"
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Pulling    15d   kubelet            Pulling image "kubetm/app"
  Normal  Pulled     15d   kubelet            Successfully pulled image "kubetm/app" in 1.674339968s (1.67434596s including waiting)
  Normal  Created    15d   kubelet            Created container container성공적으로 배포되었음.
