Tuesday 28 July 2020

Kubernetes: Scheduling Pods to specific nodes

Sometimes we may need to run the Pods on nodes of specific type.

 

For example, you may want to run your Pod on a Node with high GPU. You can specify node requirements in a manifest file using node labels and Kubernetes will figure out the node that matches your requirements.

 

How to attach labels to a node?

Using ‘kubectl label’ command, you can attach labels to a node.

 

Let’s get the available nodes by executing the below command.

$kubectl get nodes
NAME       STATUS   ROLES    AGE   VERSION
minikube   Ready    master   35d   v1.18.0

Attach labels to the node ‘minikube’ by executing the below command.

$kubectl label node minikube gpu=true availability=high
node/minikube labelled

You can get labels using the option --show-labels.

$kubectl get nodes --show-labels
NAME       STATUS   ROLES    AGE   VERSION   LABELS
minikube   Ready    master   35d   v1.18.0   availability=high,beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,gpu=true,kubernetes.io/arch=amd64,kubernetes.io/hostname=minikube,kubernetes.io/os=linux,minikube.k8s.io/commit=93af9c1e43cab9618e301bc9fa720c63d5efa393,minikube.k8s.io/name=minikube,minikube.k8s.io/updated_at=2020_05_06T15_25_50_0700,minikube.k8s.io/version=v1.9.2,node-role.kubernetes.io/master=

How can we specify node requirements?

You can specify the node requirements using ‘spec.nodeSelector’.

 

For example, below snippet instruct Kubernetes to deploy the application to a node that labeled with gpu to true.

 

spec:

  nodeSelector:

    gpu: "true"

 

podWithNodeSelector.yml

apiVersion: v1
kind: Pod
metadata:
  name: employee-web-service
  labels:
    app: employee-service
    author: krishna
    serviceType: webservice
spec:
  nodeSelector:
    gpu: "true"
  containers:
    - name: employee-service-container
      image: jboss/wildfly


Previous                                                    Next                                                    Home

No comments:

Post a Comment