I want to apply a yaml file which will add a node selector to a pod matching k8s-app=metrics-server
label. What should I put in the yaml file to this?
The Node should be labelled with the label k8s-app: metrics-server in order for pods to be scheduled on it.
Check if you have the labels added to the nodes of your cluster: kubectl get nodes --show-labels
And the label should be k8s-app: metrics-server.
apiVersion: v1
kind: Pod
metadata:
name: testpod
spec:
containers:
- name: nginx
image: nginx:latest
nodeSelector:
k8s-app: metrics-server
Also to check if the pod was scheduled on that node run the following command: kubectl get pods -o wide
Then looking at the “NODE” that the Pod was assigned to.
Following is an excercise again from the kubernetes docs https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector
Also before you post up a question please try and check online if your question's answer is available. The more you dig, the deeper you will know. Kubernetes docs are too detailed and very easy to understand.