Example of Deployment where pods are pinned to a specific node by name
I was testing a simple deployment that has only one node. Specifically I was testing if the pods, when deploying, could pull the image.
Looking at the pods I see that it was on node4:
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
test-pod-866bc57c6c-l46vk 1/1 Running 0 42s xxxxx node4 <none> <none>
Checking the pod, shows that the image already exists on the machine:
$ kubectl describe pod metabase-6d4c89846f-h5s94 | tail -n 6
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Pulled 5m14s kubelet Container image "test/test-pod:v0.46.8" already present on machine
Normal Created 5m14s kubelet Created container test-pod
Normal Started 5m14s kubelet Started container test-pod
So to get it to run on another node, I just added a node name into the deployment description:
$ kubectl edit deployment test-pod
apiVersion: apps/v1
kind: Pod
metadata:
<... removed some stuff as it is not necessary for the blog post ...>
labels:
component: test-pod
pod-template-hash: 6d4c89846f
name: metabase-6d4c89846f-h5s94
namespace: test-namespace
<... removed some stuff as it is not necessary for the blog post ...>
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
component: test-pod
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
component: test-pod
spec:
containers:
- env:
- name: DB_PASS
value: <... you wish ...>
envFrom:
- configMapRef:
name: test-config
image: test/test-pod:v0.46.8
imagePullPolicy: IfNotPresent
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
nodeName: node4
restartPolicy: Always
<... removed other stuff not necessary for blog post ...>
adding in the nodeName worked fine. This allowed me to pick a node that it wasn't used on and then check to ensure the deployment pulled the image.
Another solution would be to change the imagePullPolicy to Always