查看帮助路径
[root@k8smaster4 ns]# kubectl explain pod.spec.affinity.podAffinity
首个运行Pod的Yaml
[root@k8smaster4 ns]# cat pod-required-affinity-demo-1.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-first
labels:
app2: myapp2
tier: frontend
spec:
containers:
- name: myapp
image: docker.io/xianchao/tomcat-8.5-jre8:v1
imagePullPolicy: IfNotPresent
nodeName: k8snode5
亲和性运行Pod的Yaml
[root@k8smaster4 ns]# cat pod-required-affinity-demo-2.yaml标签:name,亲和性,k8smaster4,affinity,pod,ns,root From: https://blog.51cto.com/u_11726705/5992017
apiVersion: v1
kind: Pod
metadata:
name: pod-second
labels:
app: backend
tier: db
spec:
containers:
- name: busybox
image: docker.io/library/busybox:1.28
imagePullPolicy: IfNotPresent
command: ["sh","-c","sleep 3600"]
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app2
operator: In
values:
- myapp2
topologyKey: disk