当前位置:网站首页>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
边栏推荐
- The installation method of apache+mysql+php running environment under Windows
- How to batch move topics to different categories in discover
- Fault analysis | using --force to batch import data leads to partial data loss
- The product layout is strengthened, the transformation of digital intelligence is accelerated, and FAW Toyota has hit 2022million annual sales
- What is Druid
- Coding platform project construction guide
- Tencent cloud VPC machine, no image when installing monitoring components
- Flexible use of distributed locks to solve the problem of repeated data insertion
- Get the short video! Batch download of Kwai video (with source code)
- How to apply 5g smart pole to smart highway
猜你喜欢

Enter the software test pit!!! Software testing tools commonly used by software testers software recommendations

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

【二叉树】——二叉树中序遍历

云上本地化运营,东非第一大电商平台Kilimall的出海经

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

ServiceStack. Source code analysis of redis (connection and connection pool)

The product layout is strengthened, the transformation of digital intelligence is accelerated, and FAW Toyota has hit 2022million annual sales
Oracle case: ohasd crash on AIX
![Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.](/img/2c/d04f5dfbacb62de9cf673359791aa9.png)
Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.

A cigarette of time to talk with you about how novices transform from functional testing to advanced automated testing
随机推荐
Little transparent apprentice's way to go ashore
Word cannot copy and paste processing method
Nature Neuroscience: challenges and future directions of functional brain tissue characterization
How to solve the problem that after Tencent cloud sets static DNS, restarting the machine becomes dynamic DNS acquisition
Domain name, resolution, SSL certificate product selection
Interpreting the new features of Appstore: Customizing product pages and a/b test tools
Application of O & M work order
Use of SAP QM inspection points
The product layout is strengthened, the transformation of digital intelligence is accelerated, and FAW Toyota has hit 2022million annual sales
Kangaroo cloud: the overall architecture and key technical points of building a real-time computing platform based on Flink
Intranet environment request Tencent cloud 3.0 API details
Member management system PC side building tutorial (I)
Nine possibilities of high CPU utilization
Easyrtc call error `failed to execute'send'on'rtcdatachannel'
Microsoft Security, which frequently swipes the network security circle, gives us some enlightenment this time?
Technology is a double-edged sword, which needs to be well kept
Deploy DNS server using dnsmasq
Command ‘[‘where‘, ‘cl‘]‘ returned non-zero exit status 1.
TensorFlow 2 quickstart for beginners
Innovating the security service mode, deeply convinced that the organization has been equipped with a "continuous online expert group"