Kubectl Cheatsheet - Kubernetes Command Reference

Master Kubernetes with our comprehensive Kubectl cheatsheet. Quickly find commands for namespaces, logging, configmaps, and more. Essential for DevOps engineers.

Kubectl Cheatsheet

Kubernetes Namespaces Management

Efficiently manage your Kubernetes resources by understanding and utilizing namespaces. This section covers commands to view all namespaces and filter resources within specific ones.

Show all namespaces.

kubectl --all-namespaces

Shorthand for viewing all namespaces:

kubectl -A

Kubernetes Pod Logging

Accessing and analyzing pod logs is crucial for debugging and monitoring your Kubernetes applications. Learn how to retrieve logs from specific pods and namespaces.

kubectl --namespace my-namespace get pods

Get logs for a specific pod:

kubectl logs pod-name

Get logs for a pod in a specific namespace, with time constraints and timestamps:

kubectl logs <pod_name> -n <namespace> --since=12h --timestamps

Tail logs in real-time

Stream logs as they are generated:

kubectl logs -f

Retrieve previous logs

Access logs from a previous instance of a pod:

kubectl logs -p

Limit log output

View only the last N lines of logs:

--tail=20

Inspecting Kubernetes ConfigMaps

ConfigMaps are essential for decoupling configuration from application code. This section demonstrates how to view and inspect ConfigMap details using kubectl.

First, confirm the name of the ConfigMap you want to inspect. Here's how to list ConfigMaps in a specific namespace:

kubectl get configmap -n bridge

Example output:

NAME                         DATA   AGE
bridge-conf-configmap        1      144d
bridge-init-conf-configmap   1      567d
bridge-jks-configmap         1      144d
kube-root-ca.crt             1      385d

Now, describe the settings of a specific ConfigMap, filtering for relevant information:

kubectl describe configmaps bridge-conf-configmap -n bridge | grep -C 3 maxQueuedRequests

Example output snippet:

  idleThreadTimeout: 60s
  maxThreads: 2048
  minThreads: 1024
  maxQueuedRequests: 4096
  requestLog:
    appenders:
      - type: console

Kubernetes Resources and Documentation

For further exploration and deeper understanding of Kubernetes and kubectl commands, refer to the following resources:

  1. How to View Kubernetes Pod Logs With Kubectl
  2. Kubectl Command Reference - Kubernetes Official Documentation
  3. Understanding Kubernetes ConfigMaps
  4. Kubernetes Namespaces Explained
  5. MDN Web Docs: Date (Example of a related technical reference)