当前位置:网站首页>Istio best practice: graceful termination
Istio best practice: graceful termination
2022-06-24 11:08:00 【imroc】
This article excerpts from istio Learning notes
summary
This article is introduced in istio The key points to be paid attention to when implementing elegant termination in the scenario , For some common concerns of container scenarios, please refer to Kubenretes Best practices : End gracefully .
envoy Being forcibly killed leads to abnormal traffic
When the business is istio after , Traffic volume sidecar hijacked , There is no direct connection between processes , But after sidecar This layer of agent :
When Pod Start and stop , It will start from the endpoints Remove... From , No longer forward traffic to it , meanwhile Sidecar I will also receive SIGTERM The signal , Stop accepting at once inbound new connection , But it will keep the stock inbound Connection continues ,outbound Directional flow can still be initiated normally .
But there's one notable detail , if Pod Not quitting soon ,istio The default is to start at the stop 5s After forced killing envoy, When envoy When the process is gone, it cannot forward any traffic ( Whether it's inbound still outbound Direction ), So there may be some problems :
- If the interface provided by the stopped service takes a long time ( For example, text to speech ), The stock of inbound The request may be disconnected without being processed .
- If the stopped process needs to call other services ( For example, notify other services to clean up ),outbound The request may fail to invoke .
Customize terminationDrainDuration
istio Provides terminationDrainDuration The custom configuration of the graceful termination time of this connection , Express sleep How long does it take to force the killing envoy, The default is 5s, have access to proxy.istio.io/config This Resource Annotation To configure the service that needs to customize the graceful termination time of the connection terminationDrainDuration, Usage examples :
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
annotations:
proxy.istio.io/config: |
terminationDrainDuration: 60s # Custom here Envoy Elegant end time
labels:
app: nginx
spec:
terminationGracePeriodSeconds: 60 # if terminationDrainDuration Overtime 30s Is specified explicitly terminationGracePeriodSeconds
containers:
- name: nginx
image: "nginx"- If
terminationDrainDurationGreater than 30s, Need to explicitly Pod AppointterminationGracePeriodSeconds, Because this value defaults to 30s, namely 30s After that, the process in the container will send a message before exiting SIGKILL The signal will force it to kill . So make sure thatterminationGracePeriodSecondsGreater than or equal toterminationDrainDurationOnly in this way can the elegant termination duration take full effect . terminationDrainDurationThe larger the setting is , It also means Pod The slower it will stop , Therefore, it is recommended to customize according to business scenarios , Only reasonably customize the services you need , In other cases, the default values can be used .
Use preStop
If the time required to stop the business is not fixed , Hard to use fixed terminationDrainDuration To control the sidecar Stop time , In fact, you can also give sidecar Add one more preStop Script , In the script, you can indirectly judge whether the application has exited by judging whether it still needs to be connected , After the app exits envoy Just started to quit ( Default wait 5s).
add to preStop It can be modified by sidecar injector Overall situation configmap To achieve :
kubectl -n istio-system edit configmap istio-sidecar-injector
If you use TCM, Managed grid add preStop Background operation of work order is required , The independent grid can modify the configmap, but configmap The name is different from here , Will be suffixed with version .
stay values Inside global.proxy Add the following lifecycle Field :
"lifecycle": {
"preStop": {
"exec": {
"command": ["/bin/sh", "-c", "while [ $(netstat -plunt | grep tcp | grep -v envoy | wc -l | xargs) -ne 0 ]; do sleep 1; done"]
},
},
},Reference material
边栏推荐
- First acquaintance with string+ simple usage (I)
- Learn how to use PHP to filter special symbols in strings
- 2008R2 precautions for configuring L2TP pre shared key VPN
- 如何开发短信通知和语音功能医院信息系统(HIS系统)
- What is a compressed file? What are the advantages of different methods of compressing files?
- Go basic series | 4 Environment construction (Supplement) - gomod doubts
- Svg+js drag slider round progress bar
- ≥ 2012r2 configure IIS FTP
- 使用Process Monitor工具监测进程对注册表和文件的操作
- Virtual CD-ROM function how to use and install virtual CD-ROM
猜你喜欢

喜欢就去行动

math_等比数列求和推导&等幂和差推导/两个n次方数之差/

Programmers spend most of their time not writing code, but...

Today's sleep quality record 76 points

齐次坐标的理解

SQL Server about like operator (including the problem of field data automatically filling in spaces)

Understanding of homogeneous coordinates

【毕业季·进击的技术er】绕树三匝,何枝可依?

Canvas infinite scan JS special effect code

Apple's legendary design team disbanded after jobs refused to obey cook
随机推荐
喜歡就去行動
Group counting_ Structure and workflow of CPU
“一次编写,运行各端”,高通重磅发布 AI 软件栈!
How to improve the quality of Baidu keyword?
I just did it! Visualization of character relationships in Douluo continent
Code is really - omnipotent! Refuse to fight
Give you a server. Can you deploy your code online?
System design: key features of distributed systems
SQL Server about like operator (including the problem of field data automatically filling in spaces)
Centripetalnet: more reasonable corner matching, improved cornernet | CVPR 2020 in many aspects
When the data security law comes, how can enterprises prepare for a rainy day? Tencent security has something to say
What is the function of the graphics card driver? Do you want to update the graphics card driver
Step 3: access the API interface for inquiry of SF express doc No. [express 100api interface]
Moving Tencent to the cloud cured their technical anxiety
突然想到老家的木屋
Can text pictures be converted to word? How to extract text from pictures
【毕业季·进击的技术er】绕树三匝,何枝可依?
Canvas pipe animation JS special effect
Any 与 TypeVar,让 IDE 的自动补全更好用
喜欢就去行动