当前位置:网站首页>Istio FAQ: sidecar stop sequence
Istio FAQ: sidecar stop sequence
2022-06-24 16:14:00 【imroc】
This article excerpts from istio Learning notes
background
Istio stay 1.1 There was a problem before version : Pod At the time of destruction , If the process continues to call other services during the exit process ( For example, notify another service to clean up ), Fail to call .
For more details, please refer to issue #7136: Envoy shutting down before the thing it's wrapping can cause failed requests .
reason
Kubernetes In the process of destruction Pod In the process of , Will send to all containers at the same time SIGTERM The signal , therefore Envoy Start and stop at the same time as the business container ,Envoy No new traffic will be accepted during the stop process , And because of Istio Traffic hijacking , All outgoing flows will pass through Envoy Forward , If Envoy Do not accept new traffic , It will cause the business to call other services to fail .
Community solutions
If Kubernetes Self support container dependency management , Then this problem can be solved naturally . The community also proposed Sidecar Container Characteristics of , Unfortunately, it was finally abandoned , The new plan has not yet been implemented , Details available This note .
Later, along with istio Community promotion , Some optimizations have been made for elegant termination scenarios :
- 2019-02: Liam White Submit PR Envoy Graceful Shutdown , Give Way Pod In the process of stopping Envoy Can achieve graceful stop ( Keep the stock connection and continue processing , But reject all new connections ), wait for
terminationDrainDurationStop after a long time envoy example . The PR Finally it is merged into istio 1.1. - 2019-11: Rama Chavali Submit PR move to drain listeners admin endpoint , take Envoy The graceful stop method is changed from hot restart to calling Envoy Later, it provided by itself admin Interface (/drain_listeners?inboundonly) , The point is to bring
inboundonlyParameters , That is, just refuse inbound New connection of direction ,outbound The new connection can still be initiated normally , It also makes Pod During the stopping process, the business process continues to call other services to realize . The PR Finally it is merged into istio 1.5.
So in istio 1.5 And above , stay Pod A short period of time during a stop ( Default 5s), Business processes can still make requests to other services .
Best practices
Customize elegant duration
If your business needs to call other services during the stop process , Use istio 1.5 There is usually no problem with the above versions without any additional configuration , Because it will default to 5s Elegant end time , This duration is sufficient for most scenarios . If the business is special , It may take a long time to stop ( exceed 5s), And you need to initiate calls to other services , In this case, it is recommended to use istio 1.7 And above , Support use proxy.istio.io/config This Resource Annotation To configure the service that needs to customize the graceful termination time 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" It should be noted that , If terminationDrainDuration Greater than 30s, Need to explicitly Pod Appoint terminationGracePeriodSeconds, 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 that terminationGracePeriodSeconds Greater than or equal to terminationDrainDuration Only in this way can the elegant termination duration take full effect .
Use preStop To avoid
If the time required to stop the business is not fixed , It is not easy to use a fixed elegant duration , 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 to really quit .
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 ( Tencent cloud service grid ), 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"]
},
},
},边栏推荐
- Global and Chinese market of insect proof clothing 2022-2028: Research Report on technology, participants, trends, market size and share
- clang: warning: argument unused during compilation: ‘-no-pie‘ [-Wunused-command-line-argument]
- Here comes Wi Fi 7. How strong is it?
- Parameterized tests guide in junit5
- Implement Domain Driven Design - use ABP framework - domain logic & application logic
- 2021-05-01: given an ordered array arr, it represents the points located on the X axis. Given a positive number k
- Step by step import RHEL image to Tencent cloud
- [cloud native | kubernetes chapter] Introduction to kubernetes Foundation (III)
- #夏日挑战赛# HarmonyOS - 实现带日期效果的待办事项
- Several characteristics of pharmaceutical industry
猜你喜欢
![[interview high frequency questions] sequential DP questions with difficulty of 3/5 and direct construction](/img/32/720ffa63a90cd5d37460face3fde38.png)
[interview high frequency questions] sequential DP questions with difficulty of 3/5 and direct construction

Solution of intelligent all in one machine in expressway service area

The catch-up of domestic chips has scared Qualcomm, the leader of mobile phone chips in the United States, and made moves to cope with the competition

Build go command line program tool chain

一文详解JackSon配置信息

One article explains Jackson configuration information in detail

Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021

Understanding openstack network

Solution to the problem that FreeRTOS does not execute new tasks

Three solutions for Jenkins image failing to update plug-in Center
随机推荐
MySQL進階系列:鎖-InnoDB中鎖的情况
2021-05-01: given an ordered array arr, it represents the points located on the X axis. Given a positive number k
Enterprise security attack surface analysis tool
Goby+AWVS 实现攻击面检测
Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021
2021-04-25: given an array arr and a positive number m, the
MySQL Advanced Series: Locks - Locks in InnoDB
【面试高频题】难度 3/5,可直接构造的序列 DP 题
我与“Apifox”的网络情缘
CAP:多重注意力机制,有趣的细粒度分类方案 | AAAI 2021
Product level design of a project in SAP mm
2021-04-29: given an array arr, it represents a row of balloons with scores. One for each blow
CAP:多重注意力机制,有趣的细粒度分类方案 | AAAI 2021
Several common DoS attacks
Global and Chinese market for commercial barbecue smokers 2022-2028: Research Report on technology, participants, trends, market size and share
Detailed explanation of estab of Stata regression table output
安装ImageMagick7.1库以及php的Imagick扩展
C. Three displays(动态规划)Codeforces Round #485 (Div. 2)
构建Go命令行程序工具链
[log service CLS] Tencent cloud log4j/logback log collection best practices