본문 바로가기

Kubernetes(k8s)/트러블 슈팅 기본 프로세스

쿠버네티스 트러블 슈팅의 기본 프로세스

1.        쿠버네티스 트러블 슈팅의 기본 프로세스

 

         1.1.        디버깅 프로세스

쿠버네티스의 여러 장점 중 하나는 에러 메시지가 굉장히 직관적이라 이해하기 쉽다는 것이다. 또한 기존 가상 머신 환경과 달리 컨테이너 기반이라 이식성(portabiliy)이 뛰어나다. 따라서 호스트의 운영체제나 환경설정 등에 관계없이 컨테이너는 대부분의 환경에서 동일하게 동작하며, 에러 상황 및 관련 조치도 마찬가지로 다양한 환경에서 동일한 방법으로 처리할 수 있다.

 

쿠버네티스 환경에서 발생하는 대부분의 문제는 아래와 같은 순서의 디버깅 프로세스로 해결할 수 있다.

 

Apply -> Get -> Describe -> Logs -> Get Event

 

1)    Apply : Yaml 파일을 이용해 오브젝트 생성

2)    Get : 생성한 오브젝트 리스트 확인

3)    Describe : Pod가 정상적으로 생성되지 않았을 경우 describe 명령어를 통해 상세한 정보 확인

4)    logs : 애플리케이션 관련 에러 로그 확인

5)    Get Event : 쿠버네티스 클러스터 관련 메시지 확인

                 

1)    Apply - Pod 생성

[admin@ubu22-01 Documents (kubernetes-admin@cluster.local:kube-system)]$
 k apply -f test.yml

 

2)    Get - 리스트 확인

[admin@ubu22-01 Documents (kubernetes-admin@cluster.local:kube-system)]$
 
k get pod web02
NAME    READY   STATUS             RESTARTS   AGE
web02   0/1    
ImagePullBackOff   0          119s

 

3)    Describe - 에러 확인

[admin@ubu22-01 Documents (kubernetes-admin@cluster.local:kube-system)]$
 
k describe pod web02


Events:
  Type     Reason     Age                    From               Message
  ----     ------     ----                   ----               -------
  Normal   Scheduled  5m15s                  default-scheduler  Successfully assigned happy/web02 to ubu22-02
  Normal   Pulling    3m29s (x4 over 5m15s)  kubelet            Pulling
image "ngin"
  Warning  Failed
     3m25s (x4 over 5m11s)  kubelet            Failed to pull image "ngin": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/library/ngin:latest": failed to resolve reference "docker.io/library/ngin:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
  Warning  Failed     3m25s (x4 over 5m11s)  kubelet            Error: ErrImagePull
  Warning  Failed     3m13s (x6 over 5m10s)  kubelet            Error: ImagePullBackOff
  Normal   BackOff    14s (x19 over 5m10s)   kubelet            Back-off pulling image "ngin"

# 오타로 인해 이미지를 다운받지 못함. (ngin -> nginx)

 

4)    에러 수정 및 재실행

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: web02
  name: web02
spec:
  containers:
  - image: nginx:1.20
    name: web02
~

[
admin@ubu22-01 Documents (kubernetes-admin@cluster.local:kube-system)]$ kgp

web02                   1/1    
Running   0          75s    10.233.88.102   ubu22-02   <none>           <none>