> ## Content Index
> Fetch the complete content index at: https://blog.hacking.pub/llms.txt
> Use this file to discover other available public pages before exploring further.

# k8s 平滑重启
- URL: https://blog.hacking.pub/2019/07/03/k8s-ping-hua-zhong-qi/
- Published: 2019-07-03T12:15:36.000Z
- Updated: 2019-07-03T12:15:36.000Z
- Author: chainhelen

```
package main

import (
	"fmt"
	"log"

	"net/http"
	"time"
)

func handler(w http.ResponseWriter, r *http.Request) {
    time.Sleep(time.Millisecond * time.Duration(500))
    fmt.Fprintf(w, "ok")
}

func main() {
	http.HandleFunc("/A", handler)
	log.Fatal(http.ListenAndServe(":8082", nil))
}

ab -n 10000 -c 100 -H "host:xxx.xxx.xxx.xxx" "http://xxx.xxx.xxx.xx/tracingc/c"

```

```
1.用户删除 Pod
2.1 Pod 进入 Terminating 状态;
2.2.与此同时，k8s 会将 Pod 从对应的 service 上摘除;
2.3.与此同时，针对有 preStop hook 的容器，kubelet 会调用每个容器的 preStop hook，假如 preStop hook 的运行时间超出了 grace period，kubelet 会发送 SIGTERM 并再等 2 秒;
2.4.与此同时，针对没有 preStop hook 的容器，kubelet 发送 SIGTERM
3.grace period 超出之后，kubelet 发送 SIGKILL 干掉尚未退出的容器

```