Skip to content

Instantly share code, notes, and snippets.

@runlevel5
Last active June 4, 2020 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runlevel5/dd2a8c043fbc464384fac4a83d06ce6b to your computer and use it in GitHub Desktop.
Save runlevel5/dd2a8c043fbc464384fac4a83d06ce6b to your computer and use it in GitHub Desktop.
K8S Short cut

Get pods by selectors

kubectl get pods --selector <key>=<value>

Count pods by selectors

kubectl get pods --selector <key>=<value> --no-headers=true | wc -l

How to taint a node

kubectl taint nodes <node_name> key=value:<effect>

How to check taint of a node

kubectl describe nodes <node_name> | grep -a Taints

How to remove taint from a node:

kubectl taint node <node_name> key:<effect>-

How to add toleration to a pod

Add following snippet to PodSpec:

...
# must be quoted
spec:
  tolerations:
  - key: "name"
    operator: "Equal"
    value: "value"
    effect: "<effect>"

How to add label to a node

kubectl label nodes <node_name> key=value

How to update existing label of a node

kubectl label nodes <node_name> key=value --overwrite

How to remove label from a node

kubectl label nodes <name_name> key-

How to create a pod with nodeSelector

Add following snippet to PodSpec:

spec:
  nodeSelector:
    <key>: <value>

NOTES on label

  • Existing pod will NOT get evicted should the node's label changed. Solution: Existing pod must be deleted / template updated/applied. OR deployment/ReplicaSet must scale down then up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment