⚡
usefultools.dev
k8s

kubectl-Spickzettel

NEU

kubectl-Spickzettel für Kubernetes: Kontexte, get und describe, apply, logs, exec, port-forward, rollout, scale, Secrets, Fehlersuche und Ausgabeformate. Die Befehle sind auf Englisch.

Läuft zu 100 % in deinem Browser — deine Eingaben werden nie hochgeladen oder auf unseren Servern gespeichert.

95 Einträge in 11 Abschnitten

Context & config

  • kubectl config get-contexts

    List the contexts (cluster, user, namespace) in your kubeconfig.

  • kubectl config current-context

    Show the context you are using now.

  • kubectl config use-context <name>

    Switch to another context.

  • kubectl config set-context --current --namespace=<ns>

    Set the default namespace of the current context.

  • kubectl config view --minify

    Show the kubeconfig settings of the current context only.

  • kubectl cluster-info

    Show the addresses of the control plane and core services.

  • kubectl version

    Show client and server versions.

Get & describe

  • kubectl get pods

    List pods in the current namespace.

  • kubectl get pods -A

    List pods in all namespaces.

  • kubectl get pods -o wide

    List pods with node and IP columns.

  • kubectl get pods -w

    Watch pods and print changes as they happen.

  • kubectl get pods -l app=web

    Filter by label.

  • kubectl get all

    List the common resource types (pods, services, deployments, ...).

  • kubectl get deploy,svc,ing

    List several resource types at once.

  • kubectl describe pod <name>

    Show details and recent events of a pod.

  • kubectl get events --sort-by=.lastTimestamp

    List recent events, oldest first.

  • kubectl explain deployment.spec.strategy

    Show the documentation of a field in a resource.

Create, apply & delete

  • kubectl apply -f manifest.yaml

    Create or update resources from a file.

  • kubectl apply -f ./dir/

    Apply every manifest in a folder.

  • kubectl apply -k <dir>

    Apply a Kustomize directory.

  • kubectl apply -f manifest.yaml --dry-run=server

    Validate against the cluster without changing anything.

  • kubectl diff -f manifest.yaml

    Show what would change if you applied the file.

  • kubectl create deployment web --image=nginx

    Create a deployment from the command line.

  • kubectl create namespace <name>

    Create a namespace.

  • kubectl run web --image=nginx

    Start a single pod.

  • kubectl expose deployment web --port=80

    Create a service in front of a deployment.

  • kubectl edit deployment <name>

    Edit a live resource in your editor.

  • kubectl delete -f manifest.yaml

    Delete the resources defined in a file.

  • kubectl delete pod <name>

    Delete a pod (a controller will usually recreate it).

Logs, exec, port-forward & cp

  • kubectl logs <pod>

    Show a pod's logs.

  • kubectl logs -f <pod>

    Follow the log.

  • kubectl logs <pod> -c <container>

    Logs of one container in a multi-container pod.

  • kubectl logs <pod> --previous

    Logs of the previous container instance, useful after a crash.

  • kubectl logs -l app=web --tail=50

    Last 50 lines from every pod matching a label.

  • kubectl exec -it <pod> -- sh

    Open a shell in a pod (use bash if available).

  • kubectl exec <pod> -- env

    Run one command in a pod.

  • kubectl port-forward <pod> 8080:80

    Forward local port 8080 to port 80 of the pod.

  • kubectl port-forward svc/<name> 8080:80

    Forward a local port to a service.

  • kubectl cp <pod>:/path/file ./file

    Copy a file from a pod (needs tar in the container).

  • kubectl cp ./file <pod>:/path/file

    Copy a local file into a pod.

Rollout & scale

  • kubectl rollout status deployment/<name>

    Wait for a rollout and report its progress.

  • kubectl rollout history deployment/<name>

    List the revisions of a deployment.

  • kubectl rollout undo deployment/<name>

    Go back to the previous revision.

  • kubectl rollout restart deployment/<name>

    Restart all pods of a deployment one by one.

  • kubectl set image deployment/<name> <container>=<image>:<tag>

    Change the image of a container and trigger a rollout.

  • kubectl scale deployment/<name> --replicas=3

    Set the number of replicas.

  • kubectl autoscale deployment <name> --min=2 --max=10 --cpu-percent=80

    Create a horizontal pod autoscaler.

Namespaces

  • kubectl get namespaces

    List namespaces.

  • kubectl get pods -n <namespace>

    Run a command against a specific namespace.

  • kubectl delete namespace <name>

    Delete a namespace and everything inside it.

  • kubectl get all -n <namespace>

    List common resources in a namespace.

  • kubectl api-resources --namespaced=true

    List resource types that live inside namespaces.

Nodes

  • kubectl get nodes

    List nodes and their status.

  • kubectl describe node <name>

    Show capacity, allocated resources and conditions of a node.

  • kubectl top nodes

    CPU and memory use per node (needs metrics-server).

  • kubectl cordon <node>

    Mark a node as unschedulable.

  • kubectl drain <node> --ignore-daemonsets

    Evict pods from a node before maintenance.

  • kubectl uncordon <node>

    Allow scheduling on a node again.

  • kubectl taint nodes <node> key=value:NoSchedule

    Add a taint so pods without a matching toleration are not scheduled.

Secrets & ConfigMaps

  • kubectl create configmap app-config --from-literal=KEY=value

    Create a ConfigMap from a key and value.

  • kubectl create configmap app-config --from-file=config.properties

    Create a ConfigMap from a file.

  • kubectl create secret generic db-pass --from-literal=password=<value>

    Create a generic secret.

  • kubectl get secret db-pass -o yaml

    Show a secret. Values are base64-encoded, not encrypted.

  • kubectl get secret db-pass -o jsonpath='{.data.password}' | base64 -d

    Read and decode one secret value.

  • kubectl create secret docker-registry regcred --docker-server=<host> --docker-username=<user> --docker-password=<pass>

    Create credentials for pulling private images.

Debugging

  • kubectl get pods --field-selector=status.phase!=Running

    Find pods that are not running.

  • kubectl get events --field-selector involvedObject.name=<pod>

    Events for one pod: pull errors, scheduling issues, probe failures.

  • kubectl top pods

    CPU and memory use per pod (needs metrics-server).

  • kubectl debug -it <pod> --image=busybox --target=<container>

    Attach a temporary debug container to a pod.

  • kubectl run tmp --rm -it --image=busybox --restart=Never -- sh

    Start a throwaway pod with a shell and remove it on exit.

  • kubectl auth can-i create deployments

    Check whether you are allowed to do something.

  • kubectl get endpoints <service>

    Check which pod IPs back a service; empty means no ready pods match.

Output formats

  • kubectl get pod <name> -o yaml

    Full resource as YAML.

  • kubectl get pod <name> -o json

    Full resource as JSON.

  • kubectl get pods -o name

    Only resource names, like pod/web-1.

  • kubectl get pods -o jsonpath='{.items[*].metadata.name}'

    Extract fields with JSONPath.

  • kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'

    JSONPath loop: one node name per line.

  • kubectl get pods -o custom-columns=NAME:.metadata.name,NODE:.spec.nodeName

    Pick your own columns.

  • kubectl get pods --sort-by=.metadata.creationTimestamp

    Sort by a field.

  • kubectl get pods --show-labels

    Add a column with all labels.

Resource short names

Use these in place of the full type name, e.g. kubectl get po.

  • po

    pods

  • svc

    services

  • deploy

    deployments

  • rs

    replicasets

  • ds

    daemonsets

  • sts

    statefulsets

  • cm

    configmaps

  • ns

    namespaces

  • no

    nodes

  • pv

    persistentvolumes

  • pvc

    persistentvolumeclaims

  • ing

    ingresses

  • hpa

    horizontalpodautoscalers

  • cj

    cronjobs

  • sa

    serviceaccounts

⚡

Schnelle Beispiele

Typische Eingaben und die Ergebnisse, die dieses Tool liefert.

Get
Pods aus allen Namespaces
kubectl get pods -A
Netzwerk
Lokalen Port 8080 an einen Pod weiterleiten
kubectl port-forward <pod> 8080:80
Rollout
Zur vorherigen Revision zurückkehren
kubectl rollout undo deployment/<name>
Ausgabe
Nur die Pod-Namen, per JSONPath
kubectl get pods -o jsonpath='{.items[*].metadata.name}'
📖

Überblick

kubectl ist das Kommandozeilenwerkzeug, um mit einem Kubernetes-Cluster zu sprechen. Dieser kubectl-Spickzettel listet auf, was du täglich brauchst: Kontexte und Namespaces wechseln, get und describe, apply und delete, logs, exec und port-forward, Rollouts und Skalierung, Nodes, Secrets und ConfigMaps sowie die Fehlersuche.

Ein Abschnitt zu Ausgabeformaten zeigt -o yaml, JSONPath und benutzerdefinierte Spalten, und eine Tabelle mit Kurznamen von Ressourcen (po, svc, deploy und weitere) spart Tipparbeit. Befehle, die etwas ändern oder entfernen, etwa delete und drain, werden klar beschrieben.

Befehle, Optionen und ihre kurzen Beschreibungen werden auf Englisch angezeigt; übersetzt sind nur die Oberfläche und der Seitentext. Filtere die Liste, kopiere einen Befehl und ersetze Platzhalter wie <pod>. Alles läuft in deinem Browser und nichts, was du eingibst, wird hochgeladen.

Warum dieses Tool?

  • kubectl-Syntax in Sekunden nachschlagen
  • Befehle zur Fehlersuche gebündelt
  • Beispiele für JSONPath und custom-columns
  • Kurznamen für alle gängigen Ressourcen
  • Jeden Befehl mit einem Klick kopieren
⭐

Funktionen

🧭

Kontexte

Kontexte auflisten, wechseln und den Standard-Namespace eines Kontexts festlegen.

📄

Apply und delete

Manifeste, Probeläufe, diff und Kustomize.

🪵

Logs und exec

Logs verfolgen, eine Shell öffnen, Ports weiterleiten und Dateien kopieren.

🚀

Rollouts

Status, Verlauf, undo, restart, set image und Skalierung.

🧰

Fehlersuche

Events, top, Debug-Container und Wegwerf-Pods.

🔤

Kurznamen

Eine kurze Tabelle: po, svc, deploy, ing, pvc und weitere.

🛠️

So funktioniert’s

1

Abschnitt wählen

Scrolle zu Rollout, Debugging, Output formats oder dem gewünschten Thema (die Abschnittstitel sind auf Englisch).

2

Oder filtern

Tippe ein Wort wie „logs“ oder „jsonpath“ in das Feld „Diesen Spickzettel filtern“.

3

Beschreibung lesen

Jeder Befehl hat eine kurze Erklärung auf Englisch, was er ändert oder anzeigt.

4

Kopieren und ausführen

Klicke auf Kopieren, füge den Befehl im Terminal ein und ersetze Platzhalter wie <pod>.

🤔

Häufig gestellte Fragen