Scheduling a pod to a particular node using node-affinity #
This image shows you what you should expect when testing this scenario. You can follow the step-by-step guide after seeing this.
Prerequisites #
- KWOK must be installed on the machine. See installation.
- Install kubectl
Create cluster #
kwokctl create cluster
View clusters #
- This ensures that the cluster was created successfully.
kwokctl get clusters
Create nodes #
kwokctl scale node --replicas 2
Label node-000000
kubectl label node node-000000 region=us-west-2
Scheduling process #
Step 1: Deploy pod #
The pod has a node affinity configured with a key value of region=eu-west-2. This matches the label on node-000000.pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-1
namespace: default
labels:
region: us-west-2
spec:
containers:
- name: fake-container
image: fake-image
ports:
- containerPort: 80
tolerations:
- key: "kwok.x-k8s.io/node"
operator: "Exists"
effect: "NoSchedule"
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: region
operator: In
values:
- us-west-2
kubectl apply -f pod.yaml
Step 2: View the node the pod is scheduled to. #
kubectl get pod -o wide
- Pod 1 is scheduled to node-000000.
Delete the cluster #
kwokctl delete cluster
Conclusion #
This example demonstrates how to use KWOK to simulate a scheduling scenario based on node affinity policy.