Logo

Armand.nz

Home / About / Linkedin / Github

Create a Pod That Will Only Be Scheduled on Nodes with a Specific Label

#cka #ckd #kubernetes |

  1. Add the disk=fast label to the worker2 node:
  kubectl label nodes acgk8s-worker2 disk=fast
  1. Create a YAML file named fast-nginx.yml with nodeSelector:
  vim fast-nginx.yml

In the file, paste the following:

  apiVersion: v1
  kind: Pod
  metadata:
    name: fast-nginx
    namespace: dev
  spec:
    nodeSelector:
      disk: fast
    containers:
    - name: nginx
      image: nginx

Save the file

  1. Create the fast-nginx pod:
  kubectl create -f fast-nginx.yml
  1. Check the status of the pod:
  kubectl get pod fast-nginx -n dev -o wide

Create a Pod That Will Only Be Scheduled on Nodes using taints

  1. Add a taint to a node using kubectl taint:
  kubectl taint nodes node1 disk=fast:NoSchedule
  1. Create a YAML file named fast-nginx.yml with tolerations:
  apiVersion: v1
  kind: Pod
  metadata:
    name: fast-nginx
    namespace: dev
  spec:
    containers:
    - name: nginx
      image: nginx
    tolerations:
      - key: "disk"
        operator: "Equal"
        value: "fast"
        effect: "NoSchedule"

Save the file

  1. Create the fast-nginx pod:
  kubectl create -f fast-nginx.yml
  1. Check the status of the pod:
  kubectl get pod fast-nginx -n dev -o wide
comments powered byDisqus

Copyright © Armand