Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ssup2 committed Jan 5, 2025
1 parent 5e20153 commit d6a1133
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ title: Istio Pod Termination
draft: true
---

## 1. Istio Pod Termination
## 1. Istio Pod Gracefully Termination

{{< figure caption="[Figure 1] Istio Pod Component" src="images/istio-pod-component.png" width="600px" >}}

Istio 환경에서 App Container가 안정적으로 Request를 처리하며 Gracefully Termination을 수행하기 위해서는, Istio 환경에서의 Pod의 종료 과정을 완전히 이해하고 적절하게 Pod를 설정해야 한다. [Figure 1]은 Istio 환경에서의 App Pod의 구성 요소를 나타내고 있다. App Pod에는 App을 동작시키는 Container와 함께 App Container에서 발생하는 모든 Traffic을 송수신하는 Sidecar Container인 Envoy Proxy Container가 같이 동작한다.

Envoy Proxy Container 내부에는 **pilot-agent**와 Envory Proxy와 동작하며, pilot-agent가 Init Process로 동작하며 가장 먼져 실행되고 이후에 pilot-agent는 Envoy Proxy를 실행한다. pilot-agent는 Istio의 Control Plane 역할을 수행하는 **istiod**와 통신하며 Envoy Proxy를 제어하는 역할을 수행하며, App Pod가 종료될때 kubelet으로부터 `SIGTERM` Singal을 수신하여 Envoy Proxy를 종료시키는 역할도 수행한다. Envoy Proxy Container의 Init Process가 pilot-agent이기 때문에 `SIGTERM` Signal은 pilot-agent만 수신하며, Envoy Proxy는 수신하지 않는다.

Istio 환경에서 App Pod의 종료 과정은 App Container와 Envoy Proxy Container로 구분할 수 있다.
Istio 환경에서 App Pod의 Grace 과정은 App Container와 Envoy Proxy Container로 구분할 수 있다.

### 1.1. App Container Termination

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
PreStop Hook은 App Container가 `SIGTERM` Signal을 늦게 받기 위한 용도로 활용되기 때문에 일반적으로는 [File 1]의 내용과 같이 `sleep` 명령어를 활용하여 구성한다. 따라서 App Container Image에는 `sleep` 명령어와, Shell이 설치되어 있어야 한다. 일반적으로는 **5초** 정도로 설정하며, 너무 큰 값을 설정하면 Pod 종료가 늦어져 배포 속도가 느려지기 때문에 적절한 값을 설정해야 한다. 추후에는 Kubernetes 자체에서 Sleep 기능을 제공할 예정이며 자세한 내용은 [Link](https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/3960-pod-lifecycle-sleep-action/README.md)에서 확인할 수 있다.

### 1.2. App Container의 SIGTERM 처리
### 1.2. App Container의 SIGTERM Signal 처리

{{< figure caption="[Figure 3] Kubernetes Pod Termination without PreStop Hook" src="images/kubernetes-pod-termination-without-sigterm-handler.png" width="1000px" >}}

Expand All @@ -55,7 +55,7 @@ SpringBoot 뿐만이 아니라 대부분의 App Server Framework에서는 Gracef

App Container가 `SIGTERM` Signal을 처리하지 않는 상태에서 Gracefully Termination을 수행하기 위해서는 PreStop Hook의 지속 시간을 App Container의 Request 처리 시간 이상으로 늘리는 방법이 존재한다. PreStop Hook이 길어질 수록 App Container가 `SIGTERM` Signal을 받는 시간이 늘어나고 그만큼 현재 처리중인 Request를 완료할 수 있는 시간을 얻을 수 있기 때문이다. 하지만 PreStop Hook이 길어질 수록 Pod 종료 시간도 길어지고 그 만큼 Pod 배포 시간도 증가하기 때문에 가능하면 App Container에서 `SIGTERM` Signal Handler를 설정하는 방법이 권장된다.

### 1.3. SIGKILL 설정
### 1.3. terminationGracePeriodSeconds 설정

{{< figure caption="[Figure 4] Kubernetes Pod Termination with SIGKILL" src="images/kubernetes-pod-termination-with-sigkill.png" width="1000px" >}}

Expand Down

0 comments on commit d6a1133

Please sign in to comment.