19.06.2021 Views

148422597X Kubernetes Management Design Patterns [Vohra 2017-01-29] {E559F6BB}

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9 ■ Scheduling Pods on Nodes

The another-annotation-key: another-annotation-value setting implies that from the

nodes found suitable with the nodeAffinity condition, the node with the another-annotationkey:

another-annotation-value label should be preferred, which again is a hint for a preference

that may or may not be implemented. The another-annotation-key: another-annotation-value

is found to be implemented with requiredDuringSchedulingIgnoredDuringExecution and not with

preferredDuringSchedulingIgnoredDuringExecution. In addition to the In operator, the other supported

operators are NotIn, Exists, DoesNotExist, Gt and Lt.

Next, we shall discuss each of the node affinities with an example.

Setting requiredDuringSchedulingIgnoredDuringExecution

Create a pod definition file pod-node-affinity.yaml for a pod named with-labels and set the

nodeAffinity to requiredDuringSchedulingIgnoredDuringExecution with matching expressions for

nodeSelectorTerms to be a label kubernetes.io/image-name with value as one of nginx2 or hello-world2.

The another-annotation-key: another-annotation-value is kubernetes.io/image-name: nginx. The

container image is nginx.

apiVersion: v1

kind: Pod

metadata:

name: with-labels

annotations:

scheduler.alpha.kubernetes.io/affinity: >

{

"nodeAffinity": {

"requiredDuringSchedulingIgnoredDuringExecution": {

"nodeSelectorTerms": [

{

"matchExpressions": [

{

"key": "kubernetes.io/image-name",

"operator": "In",

"values": ["nginx2", "hello-world2"]

}

]

}

]

}

}

}

kubernetes.io/image-name: nginx

spec:

containers:

- name: with-labels

image: nginx

List the nodes, including labels. The resulting labels on nodes should not include the required labels

nginx2 or hello-world2, as shown in Figure 9-35.

222

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!