kubernetes labels

Pod labels

To organize pods, we can use labels, that can be used to organize and select groups of objects.

Some recommended labels: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/

Using labels to restrict scheduling

You can use the nodeSelector directive in the spec section to restrict the scheduling, e.g.:

---
apiVersion: v1
kind: Pod
metadata:
  name: elastic-on-ssd
  labels:
    app: search-engine
    stack: elastic
  spec:
    nodeSelector:
      ssd: "true"
  containers:
    - name: elastic
      image: elasticsearch:5

kubernetes nodes labels

It’s also possible to add labels on kubernetes nodes.

# show node labels
kubectl get nodes --show-labels
 
# show labels "ssh" and "GPU"
kubectl get nodes --label-columns ssd,GPU