Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
chaseSpace committed Nov 12, 2023
1 parent 5e540a4 commit f2add6e
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pod_affinity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: Pod
metadata:
name: go-http
labels:
app: go
version: v1
spec:
containers:
- name: go-http
image: leigg/hellok8s:v1
# nodeSelector: 如果和亲和性同时配置,则必须都满足
affinity:
nodeAffinity: # 不会绕过污点机制
# 下面两项可以二选一,也可以同时存在
# - requiredDuringSchedulingIgnoredDuringExecution
# - preferredDuringSchedulingIgnoredDuringExecution
requiredDuringSchedulingIgnoredDuringExecution: # 硬性调度
nodeSelectorTerms: # 多个 matchExpressions 之间的关系是【或】关系
- matchExpressions: # 单个 matchExpressions 中的多个表达式是【且】关系
# operator 支持 In、NotIn、Exists、DoesNotExist、Gt 和 Lt
- {key: disktype, operator: In, values: ["ssd"]}
# preferredDuringSchedulingIgnoredDuringExecution: # 软性调度
# - weight: 1 # 相比其他 软性调度 策略的权重,范围是1-100
# preference:
# - matchExpressions:
# - { key: disktype, operator: In, values: [ "ssd" ] }
# - weight: 5
# preference:
# - matchExpressions:
# - { key: cpu, operator: In, values: [ "4core" ] }
34 changes: 34 additions & 0 deletions pod_affinityPod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: v1
kind: Pod
metadata:
name: go-http-podaffinity
spec:
containers:
- name: go-http
image: leigg/hellok8s:v1
# nodeSelector: 如果和亲和性同时配置,则必须都满足
affinity:
# podAffinity 可以和 podAntiAffinity 同时存在
podAffinity: # pod亲和性
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- { key: app, operator: In, values: [ "go" ] }
topologyKey: kubernetes.io/os # 必须指定,它是你希望调度Pod的目标节点群共有的标签,亲和性规则也仅会在此节点群生效
# namespaces: ["dev","test"] 允许指定命名空间,不指定则是当前Pod所在的空间
# namespaceSelector: # 或者 使用标签筛选命令空间
# matchExpressions:
# - key:
# operator:
# matchLabels:
# - environment: production
# preferredDuringSchedulingIgnoredDuringExecution:
# - podAffinityTerm:
# topologyKey:
# weight:
podAntiAffinity: # pod反亲和性
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- { key: highcpu, operator: In, values: [ "true" ] }
topologyKey: kubernetes.io/hostname # 反亲和性中,此key的值固定为 kubernetes.io/hostname
13 changes: 13 additions & 0 deletions pod_nodeLabel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Pod
metadata:
name: go-http
labels:
app: go
version: v1
spec:
containers:
- name: go-http
image: leigg/hellok8s:v1
nodeSelector:
disktype: ssd
13 changes: 13 additions & 0 deletions pod_nodeName.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 注意所有的name都只能使用 小写字母 - . 组合
apiVersion: v1
kind: Pod
metadata:
name: go-http
labels:
app: go
version: v1
spec:
containers:
- name: go-http
image: leigg/hellok8s:v1
nodeName: k8s-master
24 changes: 24 additions & 0 deletions pods_diff_labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v1
kind: Pod
metadata:
name: go-http-master
labels:
app: "go"
spec:
nodeName: k8s-master
containers:
- name: go-http
image: leigg/hellok8s:v1
---
apiVersion: v1
kind: Pod
metadata:
name: go-http-node1
labels:
app: "go"
highcpu: "true"
spec:
nodeName: k8s-node1
containers:
- name: go-http
image: leigg/hellok8s:v1

0 comments on commit f2add6e

Please sign in to comment.