diff --git a/pod_affinity.yaml b/pod_affinity.yaml new file mode 100644 index 0000000..9432189 --- /dev/null +++ b/pod_affinity.yaml @@ -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" ] } diff --git a/pod_affinityPod.yaml b/pod_affinityPod.yaml new file mode 100644 index 0000000..3daf6b3 --- /dev/null +++ b/pod_affinityPod.yaml @@ -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 diff --git a/pod_nodeLabel.yaml b/pod_nodeLabel.yaml new file mode 100644 index 0000000..c4bde7b --- /dev/null +++ b/pod_nodeLabel.yaml @@ -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 \ No newline at end of file diff --git a/pod_nodeName.yaml b/pod_nodeName.yaml new file mode 100644 index 0000000..77da8b9 --- /dev/null +++ b/pod_nodeName.yaml @@ -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 \ No newline at end of file diff --git a/pods_diff_labels.yaml b/pods_diff_labels.yaml new file mode 100644 index 0000000..28a9260 --- /dev/null +++ b/pods_diff_labels.yaml @@ -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 \ No newline at end of file