Skip to content

Instantly share code, notes, and snippets.

@b4nst
Last active June 16, 2022 17:44
Show Gist options
  • Save b4nst/123cdddf306024231c85bcd9d4621d01 to your computer and use it in GitHub Desktop.
Save b4nst/123cdddf306024231c85bcd9d4621d01 to your computer and use it in GitHub Desktop.
[Kubectl cheat sheet] Kubectl useful stuff #docker #kubectl #kubernetes

Kubectl cheat sheet

TOC

Node management

Show node info

kubectl get node

Mark node as unschedulable (preparing for reboot or shutdown)

kubectl cordon $NODENAME

Reserve resources on a node**

apiVersion: v1
kind: Pod
metadata:
  name: resource-reserver
spec:
  containers:
  - name: sleep-forever
    image: gcr.io/google_containers/pause:0.8.0
    resources:
      requests:
        cpu: 100m
        memory: 100Mi

Set the cpu and memory values to the amount of resources you want to reserve. Place the file in the manifest directory (--config=DIR flag of kubelet).

Pods management

Label filtering

Pods can be filtered by their label with (in)equality (=|==, !=), by presence/abscence of value in set (in, notin) or by presence/abscence of the key. This filters can be aggregate by separing all filter with a comma, acting like an AND logical operator.

e.g.

kubectl get pods -l 'environment in (production, qa),tier=backend,partition'

will process the folowing filter

["production", "qa"].includes(pod_labels.environment) && pod_labels.tier=="backend" && pod_labels.hasOwnProperty("partition")

Controllers

Which controller does I need for my pod?

Usage Controllers
Oneshot pods, batch computations Job
Web service, listenner Deployments
Machine-specific service, one pod per machine DaemonSet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment