Skip to content

Instantly share code, notes, and snippets.

@DoZator
Last active August 15, 2025 09:34
Show Gist options
  • Save DoZator/61f37d6b41c827ba9f73f55eef527d24 to your computer and use it in GitHub Desktop.
Save DoZator/61f37d6b41c827ba9f73f55eef527d24 to your computer and use it in GitHub Desktop.

Revisions

  1. DoZator revised this gist Aug 15, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -102,7 +102,7 @@ kubectl logs {pod_name} --namespace {ns_name}
    * Stream logs of a pod (stdout)

    ```sh
    kubectl -f logs {pod_name} --namespace {ns_name}
    kubectl logs -f {pod_name} --namespace {ns_name}
    ```

    * Access a running pod's shell
  2. DoZator revised this gist Jul 31, 2025. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -116,3 +116,9 @@ kubectl exec -it {pod_name} -- bash
    ```sh
    kubectl exec -n {ns_name} {pod_name} -- env
    ```

    * Delete pod

    ```sh
    kubectl -n {ns_name} delete pod {pod_name}
    ```
  3. DoZator revised this gist Apr 8, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -114,5 +114,5 @@ kubectl exec -it {pod_name} -- bash
    * Show pod's ENV

    ```sh
    kubectl exec -n {ns_name} liveness-845d996f9c-w6j95 -- env
    kubectl exec -n {ns_name} {pod_name} -- env
    ```
  4. DoZator created this gist Apr 8, 2025.
    118 changes: 118 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,118 @@
    ### Cluster & Context

    * List all available contexts

    ```sh
    kubectl config get-contexts
    ```

    * Show current context

    ```sh
    kubectl config curret-context
    ```

    * Switch to a different context

    ```sh
    kubectl config use-context {ctx_name}
    ```

    * Set default namespace for a context

    ```sh
    kubectl config set-context {ctx_name} --namespace={ns_name}
    ```

    * Show cluster info

    ```sh
    kubectl cluster-info
    ```

    ### Namespaces

    * List all namespaces

    ```sh
    kubectl get namespaces
    ```

    * Create namespace

    ```sh
    kubectl create namespace {ns_name}
    ```

    * Delete namespace

    ```sh
    kubectl delete namespace {ns_name}
    ```

    ### Pods

    * List pods across all namespaces

    ```sh
    kubectl get pods --all-namespaces
    ```
    or

    ```sh
    kubectl get pods --A
    ```

    * List pods in current namespace (default)

    ```sh
    kubectl get pods
    ```

    * List pods for namespace

    ```sh
    kubectl get pods --namespace {ns_name}
    ```

    * List pods for namespace with more details

    ```sh
    kubectl get pods --namespace {ns_name} -o wide
    ```

    * Show details of a specific pod

    ```sh
    kubectl describe pod {pod_name}
    ```

    * Show CPU and memory usage for pods in namespace

    ```sh
    kubectl top pod --namespace {ns_name}
    ```

    * Fetch logs of a pod

    ```sh
    kubectl logs {pod_name} --namespace {ns_name}
    ```

    * Stream logs of a pod (stdout)

    ```sh
    kubectl -f logs {pod_name} --namespace {ns_name}
    ```

    * Access a running pod's shell

    ```sh
    kubectl exec -it {pod_name} -- bash
    ```

    * Show pod's ENV

    ```sh
    kubectl exec -n {ns_name} liveness-845d996f9c-w6j95 -- env
    ```