k8s通过podaffinity调度方式创建pod

k8s通过podaffinity调度方式创建pod

136服务器
/root/demo/pod-affinity.yaml

apiVersion: v1
kind: Pod
metadata:
  name: pod-affinity
spec:
  affinity:
    podAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: testaa
            operator: In
            values:
            - "testbb"
        topologyKey: kubernetes.io/hostname
  containers:
  - name: pod-affinity
    image: nginx

创建

[email protected]:~/demo# kubectl create -f pod-affinity.yaml
pod "pod-affinity" created
[email protected]:~/demo#
[email protected]:~/demo# kubectl get pod
NAME                  READY     STATUS              RESTARTS   AGE
node-affinity         1/1       Running             0          2h
pod-affinity          0/1       ContainerCreating   0          4s
pod-manual-schedule   1/1       Running             0          5h
pod-schedule          1/1       Running             0          5h
[email protected]:~/demo#
[email protected]:~/demo# kubectl get pod
NAME                  READY     STATUS    RESTARTS   AGE
node-affinity         1/1       Running   0          2h
pod-affinity          1/1       Running   0          12s
pod-manual-schedule   1/1       Running   0          5h
pod-schedule          1/1       Running   0          5h