Menu Close

Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

16.8.3. 示例

以下示例演示了节点关联性。

16.8.3.1. 具有匹配标签的节点关联性

以下示例演示了具有匹配标签的节点与 pod 的节点关联性:

  • Node1 节点具有标签 zone:us

    $ oc label node node1 zone=us
  • pod pod-s1 在节点关联性必要规则下具有 zoneus 键/值对:

    $ cat pod-s1.yaml
    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-s1
    spec:
      containers:
        - image: "docker.io/ocpqe/hello-pod"
          name: hello-pod
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                - key: "zone"
                  operator: In
                  values:
                  - us
  • 使用标准命令创建 pod:

    $ oc create -f pod-s1.yaml
    pod "pod-s1" created
  • pod pod-s1 可以调度到 Node1 上:

    $ oc get pod -o wide
    NAME     READY     STATUS       RESTARTS   AGE      IP      NODE
    pod-s1   1/1       Running      0          4m       IP1     node1