当前位置:网站首页>Cloud native high availability and Disaster Recovery Series (I): pod break up scheduling
Cloud native high availability and Disaster Recovery Series (I): pod break up scheduling
2022-06-24 06:35:00 【imroc】
This article excerpts from kubernetes Learning notes
summary
take Pod Break up the dispatch to different places , It can avoid hardware and software failure 、 Fiber failure 、 The service is unavailable due to power failure or natural disaster , To achieve high availability deployment of services .
Kubernetes Support two ways to Pod Break up the scheduling :
- Pod Anti affinity (Pod Anti-Affinity)
- Pod Topological distribution constraints (Pod Topology Spread Constraints)
This article introduces the usage examples and comparison summary of the two methods .
Use podAntiAffinity
take Pod Force the decentralized scheduling to different nodes ( Strong anti affinity ), To avoid a single point of failure :
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- topologyKey: kubernetes.io/hostname
labelSelector:
matchLabels:
app: nginx
containers:
- name: nginx
image: nginxlabelSelector.matchLabelsReplace with selected Pod Actually used label.topologyKey: One of the nodes label Of key, It can represent the topology domain of the node , It can be used Well-Known Labels, What is commonly used iskubernetes.io/hostname( Node dimension )、topology.kubernetes.io/zone( Availability zone / Computer room dimension ). You can also manually mark the node with a custom label To define the topology domain , such asrack( Rack dimension )、machine( Physical machine dimension )、switch( Switch dimension ).- If you do not want to use force , Weak anti affinity can be used , Give Way Pod Try to schedule to different nodes :podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: - podAffinityTerm: topologyKey: kubernetes.io/hostname weight: 100
take Pod Forcibly break up scheduling to different availability zones ( Computer room ), To achieve cross machine room disaster tolerance :
take kubernetes.io/hostname Switch to topology.kubernetes.io/zone, The rest is the same as above .
Use topologySpreadConstraints
take Pod To the greatest extent, the scheduling is evenly distributed to all nodes :
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
- matchLabels:
app: nginx
containers:
- name: nginx
image: nginxtopologyKey: And podAntiAffinity Similar configuration in .labelSelector: And podAntiAffinity Similar configuration in , You can select multiple groups here pod Of label.maxSkew: Must be an integer greater than zero , Indicates that it can tolerate... In different topological domains Pod Maximum value of quantity difference . there 1 It means that only the difference is allowed 1 individual Pod.whenUnsatisfiable: Indicates what to do if the condition is not met .DoNotScheduleNo scheduling ( keep Pending), Similar to strong anti affinity ;ScheduleAnywayIndicates that you want to schedule , Similar to weak anti affinity ;
The above configurations are explained together : Will all nginx Of Pod Strictly and uniformly disperse the scheduling to different nodes , On different nodes nginx The maximum number of copies of can only differ by 1 individual , If a node cannot schedule more due to other factors Pod ( For example, insufficient resources ), Then let the rest nginx copy Pending.
therefore , If you want to break up strictly in all nodes , Usually not very desirable , You can add it nodeAffinity, Strictly break up only in some nodes with sufficient resources :
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: io
operator: In
values:
- high
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
- matchLabels:
app: nginxOr similar to weak anti affinity , take Pod Distribute the scheduling to each node as evenly as possible , Don't force (DoNotSchedule Change it to ScheduleAnyway):
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
- matchLabels:
app: nginx If the cluster node supports cross availability , It's fine too take Pod Try to distribute the scheduling to each available area as evenly as possible To achieve a higher level of high availability (topologyKey Change it to topology.kubernetes.io/zone):
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
- matchLabels:
app: nginxFurther , Sure take Pod Try to evenly disperse the scheduling to each available area at the same time , Nodes in the availability zone should also be scattered as much as possible :
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector:
- matchLabels:
app: nginx
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
- matchLabels:
app: nginxSummary
It is obvious from the example that ,topologySpreadConstraints Than podAntiAffinity More powerful , Provides finer scheduling control , We can understand that topologySpreadConstraints yes podAntiAffinity Upgraded version .topologySpreadConstraints Characteristic in K8S v1.18 Enabled by default , So suggest v1.18 And above topologySpreadConstraints To break up Pod To improve service availability .
Reference material
边栏推荐
- Intranet environment request Tencent cloud 3.0 API details
- A cigarette of time to talk with you about how novices transform from functional testing to advanced automated testing
- Provide SFTP connection for Amazon S3
- Station B collapsed. Let's talk to the injured programmers
- Forbid viewing source code in web page (protect source code)
- 【二叉数学习】—— 树的介绍
- When easynvs is deployed on the project site, easynvr cannot view the corresponding channel. Troubleshooting
- Kangaroo cloud: the overall architecture and key technical points of building a real-time computing platform based on Flink
- RS485 serial port wiring description of smart lamp post smart gateway
- Coding and codesign: make design and development easier
猜你喜欢

创客教育给教师发展带来的挑战

35岁危机?内卷成程序员代名词了

A cigarette of time to talk with you about how novices transform from functional testing to advanced automated testing

puzzle(019.1)Hook、Gear
Oracle case: ohasd crash on AIX

Technology is a double-edged sword, which needs to be well kept

解读AI机器人产业发展的顶层设计

Manual for automatic testing and learning of anti stepping pits, one for each tester
Fault analysis | using --force to batch import data leads to partial data loss

【二叉数学习】—— 树的介绍
随机推荐
Fault analysis | using --force to batch import data leads to partial data loss
Replacing human eyes -- visual inspection technology
Record of waic 2021 round table conference 𞓜 cross border dialogue: current situation and future of AI and sustainable development
How to solve the problem that after Tencent cloud sets static DNS, restarting the machine becomes dynamic DNS acquisition
Coding platform project construction guide
How to batch move topics to different categories in discover
Small programs import Excel data in batches, and cloud development database exports CVS garbled code solution
Analysis on the influence of "network security policy issued successively" on Enterprises
Easyscreen live streaming component pushes RTSP streams to easydss for operation process sharing
Domain name, resolution, SSL certificate product selection
What transmission modes does the IOT data gateway support
Analysis and treatment of easydss flash back caused by system time
What I regret most when I learn programming!
Quick reference table of PHP security configuration maintained by OWASP
How to choose CMS website system for website construction
From home to Ali, a year for junior students to apply for jobs
Get the short video! Batch download of Kwai video (with source code)
Easyrtc call error `failed to execute'send'on'rtcdatachannel'
Analysis of official template of wechat personnel recruitment management system (III)
Event delegation