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

As discussed earlier, NodeAffinity is a priority function; and priority functions have weight allocated

to them in ranking nodes. Create a pod definition file podNodeAffinity.yaml and allocate a weight of 75

for a pod using node affinity preferredDuringSchedulingIgnoredDuringExecution. Set the expressions to

match to the label key kubernetes.io/image-name to be either nginx or hello-world.

apiVersion: v1

kind: Pod

metadata:

name: with-labels

annotations:

scheduler.alpha.kubernetes.io/affinity: >

{

"nodeAffinity": {

"preferredDuringSchedulingIgnoredDuringExecution": [

{

"weight": 75,

"preference":

{

"matchExpressions": [

{

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

"operator": "In",

"values": ["nginx", "hello-world"]

}

]

}

}

]

}

}

kubernetes.io/image-name: hello-world

spec:

containers:

- name: with-labels

image: nginx

The pod definition file podNodeAffinity.yaml is shown in a vi editor in Figure 9-53.

231

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

Saved successfully!

Ooh no, something went wrong!