실행 중인 Pod 디버깅하기

실행 중인 Pod 디버깅하기 (Debug Running Pods)

이 페이지는 노드에서 실행 중인(또는 충돌하는) Pod를 디버깅하는 방법을 설명해요.

출처: 문서

본문

시작하기 전에 (Before you begin)

  • Pod가 이미 스케줄링되어 실행 중이어야 해요. 아직 실행 중이 아니라면 Debugging Pods부터 시작하세요.
  • 일부 고급 디버깅 단계에서는 Pod가 어느 노드에서 실행되는지 알고 그 노드에서 명령을 실행할 셸 접근 권한이 필요해요. kubectl을 사용하는 표준 디버그 단계를 실행하려면 그런 접근 권한은 필요하지 않아요.

파드에 대한 세부 정보를 가져오기 위해 kubectl describe pod 사용하기 (Using kubectl describe pod to fetch details about pods)

이 예시에서는 앞선 예시와 비슷하게 Deployment를 사용해 두 개의 파드를 만들어요.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 80

다음 명령을 실행해 deployment를 만들어요.

kubectl apply -f https://k8s.io/examples/application/nginx-with-request.yaml
deployment.apps/nginx-deployment created

다음 명령으로 pod 상태를 확인해요.

kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-67d4bdd6f5-cx2nz   1/1     Running   0          13s
nginx-deployment-67d4bdd6f5-w6kd7   1/1     Running   0          13s

kubectl describe pod를 사용해 이 각각의 파드에 대해 훨씬 더 많은 정보를 가져올 수 있어요. 예를 들어:

kubectl describe pod nginx-deployment-67d4bdd6f5-w6kd7
Name:         nginx-deployment-67d4bdd6f5-w6kd7
Namespace:    default
Priority:     0
Node:         kube-worker-1/192.168.0.113
Start Time:   Thu, 17 Feb 2022 16:51:01 -0500
Labels:       app=nginx
              pod-template-hash=67d4bdd6f5
Annotations:  <none>
Status:       Running
IP:           10.88.0.3
IPs:
  IP:           10.88.0.3
  IP:           2001:db8::1
Controlled By:  ReplicaSet/nginx-deployment-67d4bdd6f5
Containers:
  nginx:
    Container ID:   containerd://5403af59a2b46ee5a23fb0ae4b1e077f7ca5c5fb7af16e1ab21c00e0e616462a
    Image:          nginx
    Image ID:       docker.io/library/nginx@sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Thu, 17 Feb 2022 16:51:05 -0500
    Ready:          True
    Restart Count:  0
    Limits:
      cpu:     500m
      memory:  128Mi
    Requests:
      cpu:        500m
      memory:     128Mi
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-bgsgp (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-bgsgp:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   Guaranteed
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  34s   default-scheduler  Successfully assigned default/nginx-deployment-67d4bdd6f5-w6kd7 to kube-worker-1
  Normal  Pulling    31s   kubelet            Pulling image "nginx"
  Normal  Pulled     30s   kubelet            Successfully pulled image "nginx" in 1.146417389s
  Normal  Created    30s   kubelet            Created container nginx
  Normal  Started    30s   kubelet            Started container nginx

여기서 컨테이너와 Pod에 대한 구성 정보(라벨, 리소스 요구 등)와 컨테이너와 Pod에 대한 상태 정보(상태, 준비, 재시작 횟수, 이벤트 등)를 볼 수 있어요.

컨테이너 상태는 Waiting, Running, Terminated 중 하나예요. 상태에 따라 추가 정보가 제공돼요. Running 상태의 컨테이너에 대해 시스템이 컨테이너가 시작된 시점을 알려주는 것을 볼 수 있어요. Ready는 컨테이너가 마지막 준비(rediness) 프로브를 통과했는지 알려줘요. (이 경우 컨테이너에는 준비 프로브가 구성되어 있지 않아요. 준비 프로브가 구성되지 않으면 컨테이너는 준비된 것으로 간주돼요.)

(계속) 다음 섹션들에서 예시 로그 확인, 컨테이너에서 명령 실행, 파드에서의 SHHG 프로세스 단계 등을 다룬다. 자세한 내용은 원문을 참고하세요.

더 알아보기 (Learn more)