반응형

 

Kubernetes를 사용하다보면, Pod가 Terminating 상태에서 종료(즉, Pod의 삭제)되지 않고 계속 머물러있는 경우가 종종 발생한다.

이렇게 Pod의 Terminating 교착 상태가 된 원인은 정확히 알 수는 없고, 

단지 이런 경우에 Pod를 종료시킬 수 없어서 당혹스럽다.

 

Ian Miell 이라는 사람이 상황별로 교착 상태에 빠진 Pod를 종료하는 방법을 정리한 Web Docs가  있어서 나한테 맞게 다시 메모를 해봤다.

 

$  kubectl  delete  -n istio-system  deployment  grafana

##
## 위 delete 명령을 수행 후, 1분이 넘도록 Pod가 Terminating 상태라면
## 이 Pod는 계속 Terminating 상태로 남고, 아래 예시처럼 Delete되지 않을 것이다.
##

$  kubectl  get -A pod

NAMESPACE      NAME                                       READY   STATUS        RESTARTS       AGE
istio-system   grafana-68cc7d6d78-7kjw8                   1/1     Terminating   0              37d

... 중간 생략 ...

$

 

 

위 현상을 세분화해서 해결 방법을 설명해보겠다.

 

 

Pod의 상세 정보를 확인

 

##
## (A) 강제로 Pod를 삭제하는 방법
##

$  kubectl  delete  pods <pod>  --grace-period=0  --force

## 웬만하면, 위 명령으로 Pod가 삭제되지만
## 만약 계속 Pod의 찌끄러기가 남아 있다면, 아래 (B) 절차를 추가로 수행해야 한다.



##
## (B) 위 명령을 수행하고도 Pod이 Stuck 상태 또는 Unknown 상태로 남아 있다면
##     아래의 방법으로 Pod를 끝장낼 수 있다.
##

$  kubectl  patch  pod <pod>  -p '{"metadata":{"finalizers":null}}'

 

 

 

Reference

 

Kubernetes.io에 Pod의 강제 종료에 대한 상세한 설명을 있으니, 시간이 있다면 꼼꼼히 읽어보면 도움이 된다.

 

https://kubernetes.io/docs/tasks/run-application/force-delete-stateful-set-pod/

 

Force Delete StatefulSet Pods

This page shows how to delete Pods which are part of a stateful set, and explains the considerations to keep in mind when doing so. Before you begin This is a fairly advanced task and has the potential to violate some of the properties inherent to Stateful

kubernetes.io

 

 

그리고 위에서 finalizers를 강제로 null로 patch했는데, finalizers에 관한 상세한 설명이 궁금하면 아래 kubernetes web docs를 읽어보는 것이 좋다.

 

https://kubernetes.io/docs/concepts/overview/working-with-objects/finalizers/

 

Finalizers

Finalizers are namespaced keys that tell Kubernetes to wait until specific conditions are met before it fully deletes resources marked for deletion. Finalizers alert controllers to clean up resources the deleted object owned. When you tell Kubernetes to de

kubernetes.io

 

 

게시물 작성자: sejong.jeonjo@gmail.com

 

반응형

 

작성일: 2024년 3월 1일

 

Pod 생성 방법 - A

급하게 Pod만 생성해서 Kubernetes 기능을 확인해야 할 경우가 있다.

이럴 때, 아래와 같이 명령 한번 실행해서 Pod를 deploy할 수 있다.

$ kubectl  create  deployment  nginx  --image=nginx

 

또는 아래와 같이  YAML 형식으로 Pod 배포가 가능하다.

 

Pod 생성 방법 - B

$  kubectl  create  namespace  andrew
$  kubectl  apply  -n andrew  -f -  <<EOF

apiVersion: v1
kind: Pod
metadata:
  name: almighty
  labels:
    app: almighty
spec:
  terminationGracePeriodSeconds: 3
  containers:
  - name: almighty
    image: docker.io/andrewloyolajeong/almighty:0.2.4
    
EOF

 

 

[ 참고 ]
docker.io/andrewloyolajeong/almighty 컨테이너 이미지 내부 동작에 대한 설명
    - NGINX 서버 구동 (TCP 80 포트를 Listening)
    - SSHD 서버 구동 (TCP 22 포트를 Listening)
    - Golang으로 구현한 Simple HTTP Server 구동 (TCP 8080 포트를 Listeing)
    - Golang으로 구현한 UDP 서버 구동 (UDP 9090, 9091, 9092 포트를 사용)

 

 

그런 후에 아래와 같이 Service Resource도 만들 수 있다.

 

Service 리소스 생성 방법

$  kubectl  apply  -n andrew  -f -  <<EOF

apiVersion: v1
kind: Service
metadata:
  name: almighty
  annotations:
    ## 아래 nlb 타입은 UDP 패킷을 LB 처리하기 위한 설정이다.
    ## 만약, UDP 패킷을 처리할 일이 없다면, "nlb" 타입을 지정하지 않아도 된다.
    oci.oraclecloud.com/load-balancer-type: "nlb"  ## Oracle Cloud를 사용하는 경우 설정
spec:
  type: LoadBalancer
  externalTrafficPolicy: Local     ## Public Cloud를 사용하는 경우 설정
  selector:
    app: almighty
  ports:
    - name: myweb
      protocol: TCP
      port: 8080
      targetPort: 8080
    - name: yourweb
      protocol: TCP
      port: 1080
      targetPort: 80
    - name: myudp
      protocol: UDP
      port: 9090
      targetPort: 9090
  
EOF

 

PV 생성

진짜 간단하게 PV, PVC 생성에 관해서 작성하려고 했는데 Private Cloud 환경과 Public Cloud 환경에 따라 생성 방법이 다르고,

Public Cloud Infra를 제공하는 회사마다 Manifest 작성 방법이 다 달라서 이 부분은 아래와 같이 해당 Public Cloud Infra의 Web Docs 주소를 남기는 것으로 마무리하겠다.

가장 많이 사용되는 CSI[Cluster Storage Interface] 몇 가지 사례만 사용법을 익히면 될듯하다.

 

Oracle Cloud Infra를 사용한다면, 아래 Web Docs를 읽고 예제를 따라하면 잘 동작한다.

https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengcreatingpersistentvolumeclaim.htm

 

Creating a Persistent Volume Claim (PVC)

When a PVC is created using the CSI volume plugin (provisioner: blockvolume.csi.oraclecloud.com), you can expand the volume size online. By doing so, you make it possible to initially deploy applications with a certain amount of storage, and then subsequen

docs.oracle.com

 

 

 

 

+ Recent posts