Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Kubernetes yaml file transfer stain tolerance

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Basic usage apiVersion: v1kind: Pod# can create resource types: Deployment, Job, Ingress, Service and other metadata:# contain some meta information of Pod, such as name, namespace, tag, etc. Name: ng1 # Podname labels: # tag app: webspec:-name: ng1 # Container name image: hub.c.163.com/library/nginx # Image pull address imagePullPolicy: IfNotPresent # Image pull Policy Always, (regardless of whether there is a local pull every time) Never, (do not pull every time, even if there is no local do not pull) IfNotPresent (local use, do not pull) ports: # Open port-containerPort: 802. Scheduling strategy

Node selector: nodeSelector, nodeName

Scheduling based on node_name

ApiVersion: v1kind: Podmetadata: name: ng2spec: nodeName: cs25 # specifies scheduling to the "cs25" node node containers:-name: ng2 image: hub.c.163.com/library/nginx

Scheduling based on node tags

Kubectl label nodes cs25 disk=ssd

# tag the node cs25

ApiVersion: v1kind: Podmetadata: name: ng2spec: nodeSelector: disk: ssd # means that only "disk=ssd" on the node node can be dispatched to containers:-name: ng2 image: hub.c.163.com/library/nginx

Node affinity scheduling: nodeAffinity

ApiVersion: v1kind: Podmetadata: name: ng2spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: # requiredDuringSchedulingIgnoredDuringExecution hard compatibility must satisfy compatibility. If you don't call # preferredDuringSchedulingIgnoredDuringExecution soft compatibility, you can satisfy it best, and it doesn't matter if you don't. NodeSelectorTerms:-matchExpressions:-key: disk operator: In # indicates that the above field must contain the following two values, and can also be replaced by "NotIn" to reverse values:-jx-ssd # means that only node can be dispatched to have "disk=jx" or "node=ssd" containers:-name: ng2

POD scheduling podAffinity and podAntiAffinity

ApiVersion: v1kind: Podmetadata: name: ng2 labels: app: nginxspec: containers:-name: ng2 image: hub.c.163.com/library/nginx---apiVersion: v1kind: Podmetadata: name: ng3spec: containers:-name: ng3 image: hub.c.163.com/library/nginx affinity: podAntiAffinity: # Anti-affinity means that the two hosts are not running on the same node host if the condition is met Replace it with "podAffinity:" instead of requiredDuringSchedulingIgnoredDuringExecution:-labelSelector: matchExpressions:-{key: app, operator: In, values: ["nginx"]} topologyKey: kubernetes.io/hostname # affinity standard, which means that all node have the key name hostname, just like value, we think they are on the same node

LabelSelector: choose to be compatible with that group of Pod

Namespaces: which namespace to choose

TopologyKey: specify which key on the node

If all hosts have the node tag "topologyKey: type" in the anti-affinity scenario, the second container cannot be dispatched to any host.

3. Stain tolerant scheduling

Kubectl taint nodes cs25 key=value:NoSchedule

NoSchedule: only affects the scheduling process, but does not affect existing Pod objects

NoExecute: affects both the scheduling process and significant Pod objects; intolerant Pod objects will be expelled

PreferNoSchedule: do not schedule as much as possible

Create a stain

Kubectl taint node cs25 rongren=true:NoSchedule

# indicates that the key value of creating a rongren on the cs25 node is "true", and the scheduling policy is NoSchedule

Kubectl taint node cs25 rongren-

# remove the stain and specify the key name plus "-".

ApiVersion: v1kind: Podmetadata: name: ng6spec: containers:-name: ng6 image: nginx tolerations: # set tolerance-key: "rongren" operator: "Equal" # if the operator is Exists, the value attribute can be omitted, indicating that the existence of key is passed. If operator is not specified, Equal,value must be equal to the set value. Otherwise, it cannot pass value: "true" effect: "NoSchedule" # means that the key of the tainted Node to be tolerated by this Pod is "rongren" Equal true, and the effect is NoSchedule. All values under the # tolerations attribute must be in quotation marks, and the tolerated values are all values given when the taints of Node is set.

If you have already run some Pod before setting the Taints of node, can these Pod continue to run on this Node? It depends on the effect (effect) when setting the Taints stain.

If the value of effect is NoSchedule or PreferNoSchedule, the running Pod can still run, but the new Pod (if not tolerated) will not be scheduled up. If the value of effect is NoExecute, then the Pod running on this Node, as long as it is not tolerated, is immediately expelled. Although K8S is expelled immediately, in order to show humanization and stain the effect of NoExecute, K8S has an optional tolerationSeconds field in the tolerance attribute, which is used to set how long these Pod can run on this Node, give them a little grace time, and then expel it. If it is started with Pod, then after Pod is expelled, it will no longer be run, which is tantamount to deleting it. If it is deployment/rc, then the deleted pod will run on other nodes. If DaemonSet starts the Pod on this Node, it will not be run again until the NoExecute stain on the Node is removed or the Pod is tolerated.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 223

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report