Using node selectors and node name
Node selectors are a very simple type of placement control in Kubernetes. Each Kubernetes node can be labeled with one or more labels in the metadata block, and Pods can specify a node selector.
To label an existing node, you can use the kubectl label
command:
> kubectl label nodes node1 cpu_speed=fast
In this example, we're labeling our node1
node with the label cpu_speed
and the value fast
.
Now, let's assume that we have an application that really needs fast CPU cycles to perform effectively. We can add a nodeSelector
to our workload to ensure that it is only scheduled on nodes with our fast CPU speed label, as shown in the following code snippet:
pod-with-node-selector.yaml
apiVersion: v1 kind: Pod metadata:   name: speedy-app spec:   containers:   - name: speedy-app     image: speedy-app:latest     imagePullPolicy: IfNotPresent   nodeSelector...