Skip to content

Instantly share code, notes, and snippets.

@jonashackt
Last active March 13, 2024 13:36
Show Gist options
  • Select an option

  • Save jonashackt/df283eb3f5ed587ee1f93cbcfc23be08 to your computer and use it in GitHub Desktop.

Select an option

Save jonashackt/df283eb3f5ed587ee1f93cbcfc23be08 to your computer and use it in GitHub Desktop.

Revisions

  1. jonashackt revised this gist Mar 13, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    k9s cheatsheet: https://www.hackingnote.com/en/cheatsheets/k9s/

    # CLI enhancements

    https://discuss.kubernetes.io/t/kubectl-tips-and-tricks/192
  2. jonashackt revised this gist Dec 20, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -180,3 +180,5 @@ Bare metal Kubernetes: https://www.siderolabs.com/platform/bare-metal-kubernetes
    K8s simple deployment tooling (simpler than Argo and Flux): https://werf.io/

    KubeCon 2022 Recordings: https://www.youtube.com/playlist?list=PLj6h78yzYM2MCEgkd8zH0vJWF7jdQ-GRR

    VMWare Tanzu on a Laptop: https://tanzu.vmware.com/developer/guides/tanzu-application-platform-local-devloper-install/ (and in GitHub Actions etc.)
  3. jonashackt revised this gist Dec 20, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -177,4 +177,6 @@ Docker Desktop alternatives: https://podman-desktop.io/

    Bare metal Kubernetes: https://www.siderolabs.com/platform/bare-metal-kubernetes-sidero/

    K8s simple deployment tooling (simpler than Argo and Flux): https://werf.io/

    KubeCon 2022 Recordings: https://www.youtube.com/playlist?list=PLj6h78yzYM2MCEgkd8zH0vJWF7jdQ-GRR
  4. jonashackt revised this gist Dec 20, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -177,3 +177,4 @@ Docker Desktop alternatives: https://podman-desktop.io/

    Bare metal Kubernetes: https://www.siderolabs.com/platform/bare-metal-kubernetes-sidero/

    KubeCon 2022 Recordings: https://www.youtube.com/playlist?list=PLj6h78yzYM2MCEgkd8zH0vJWF7jdQ-GRR
  5. jonashackt revised this gist Dec 20, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -175,5 +175,5 @@ Telepresence alternative: https://gefyra.dev/

    Docker Desktop alternatives: https://podman-desktop.io/


    Bare metal Kubernetes: https://www.siderolabs.com/platform/bare-metal-kubernetes-sidero/

  6. jonashackt revised this gist Dec 20, 2022. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -161,3 +161,19 @@ kubectl run hostnames --image=k8s.gcr.io/serve_hostname \
    kubectl describe nodes


    # Awesome tools

    Cluster in cluster: https://www.vcluster.com/ & https://github.com/loft-sh/vcluster

    https://github.com/ahmetb/kubectl-tree

    Deployment abstraction above Helm: https://www.acorn.io/

    https://microk8s.io/

    Telepresence alternative: https://gefyra.dev/

    Docker Desktop alternatives: https://podman-desktop.io/



  7. jonashackt revised this gist Dec 20, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@

    https://discuss.kubernetes.io/t/kubectl-tips-and-tricks/192

    krew as the Kubernetes CLI (kubectl) plugin manager helps to install all the tools: https://krew.sigs.k8s.io/

    #### kubectl autocompletion

    Install kubectl
  8. jonashackt revised this gist Dec 13, 2021. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -67,6 +67,9 @@ Now this could all look like this:

    [![asciicast](https://asciinema.org/a/441785.svg)](https://asciinema.org/a/441785)


    For evaluation tools ee https://learnk8s.io/validating-kubernetes-yaml

    #### kubeval

    Install via homebrew (see https://www.kubeval.com/installation/):
    @@ -79,6 +82,16 @@ brew install kubeval
    Now use `kubeval your-yaml-to-check.yaml`


    #### kubescore

    Install via homebrew (see https://github.com/zegl/kube-score#installation): `brew install kube-score`

    Run with
    ```
    kube-score score your-yaml-to-check.yaml
    ```


    # K8s cluster

    ### See logs of K8s cluster
  9. jonashackt revised this gist Dec 13, 2021. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -67,6 +67,18 @@ Now this could all look like this:

    [![asciicast](https://asciinema.org/a/441785.svg)](https://asciinema.org/a/441785)

    #### kubeval

    Install via homebrew (see https://www.kubeval.com/installation/):

    ```
    brew tap instrumenta/instrumenta
    brew install kubeval
    ```

    Now use `kubeval your-yaml-to-check.yaml`


    # K8s cluster

    ### See logs of K8s cluster
  10. jonashackt revised this gist Oct 14, 2021. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -63,6 +63,10 @@ kubeon
    kubeoff
    ```

    Now this could all look like this:

    [![asciicast](https://asciinema.org/a/441785.svg)](https://asciinema.org/a/441785)

    # K8s cluster

    ### See logs of K8s cluster
  11. jonashackt revised this gist Oct 13, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # CLI enhancements

    https://discuss.kubernetes.io/t/kubectl-tips-and-tricks/192

    #### kubectl autocompletion

    Install kubectl
  12. jonashackt revised this gist Oct 13, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # CLI enhancements

    # kubectl autocompletion
    #### kubectl autocompletion

    Install kubectl

    @@ -39,7 +39,7 @@ $(brew --prefix)/opt/fzf/install

    Now your `kubectx` and `kubens` are super powered as interactive mode :)

    ### kube-ps1
    #### kube-ps1

    https://github.com/jonmosco/kube-ps1:

  13. jonashackt revised this gist Oct 13, 2021. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,18 @@
    # CLI enhancements

    # kubectl autocompletion

    Install kubectl

    then configure autocompletion as stated in the docs: https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/#optional-kubectl-configurations-and-plugins with adding the following to your ~/.zshrc or ~/.bashrc:

    ```
    ### kubectl autocompletion & alias k
    source <(kubectl completion zsh)
    alias k=kubectl
    complete -F __start_kubectl k
    ```

    #### kubectx & kubens

    https://github.com/ahmetb/kubectx: Install via brew: `brew install kubectx`
  14. jonashackt revised this gist Oct 13, 2021. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,19 @@ kubectx
    kubectx k3d
    ```

    #### kubectx interactive mode

    If you want a fancy interactive mode, you need to install https://github.com/junegunn/fzf#using-homebrew

    ```
    brew install fzf
    # To install useful key bindings and fuzzy completion:
    $(brew --prefix)/opt/fzf/install
    ```

    Now your `kubectx` and `kubens` are super powered as interactive mode :)

    ### kube-ps1

    https://github.com/jonmosco/kube-ps1:
  15. jonashackt revised this gist Oct 13, 2021. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # CLI enhancements

    #### kubectx & kubens

    https://github.com/ahmetb/kubectx: Install via brew: `brew install kubectx`

    Now run it and switch with ease:
    @@ -11,6 +13,28 @@ kubectx
    kubectx k3d
    ```

    ### kube-ps1

    https://github.com/jonmosco/kube-ps1:

    install via:

    ```
    brew install kube-ps1
    # now source kube-ps1.sh in your ~/.zshrc or ~/.bashrc. Therefore add the following 2 lines to them:
    source "/usr/local/opt/kube-ps1/share/kube-ps1.sh"
    PS1='$(kube_ps1)'$PS1
    ```

    Now you should already see the current k8s context & namespace inside your prompt:

    ```
    # switch on and off
    kubeon
    kubeoff
    ```

    # K8s cluster

    ### See logs of K8s cluster
  16. jonashackt revised this gist Oct 13, 2021. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,14 @@
    # CLI enhancements

    https://github.com/ahmetb/kubectx: Install via brew:
    https://github.com/ahmetb/kubectx: Install via brew: `brew install kubectx`

    Now run it and switch with ease:

    ```
    brew install kubectx
    # list all contexts
    kubectx
    # switch
    kubectx k3d
    ```

    # K8s cluster
  17. jonashackt revised this gist Oct 13, 2021. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,11 @@
    # CLI enhancements

    https://github.com/ahmetb/kubectx: Install via brew:

    ```
    brew install kubectx
    ```

    # K8s cluster

    ### See logs of K8s cluster
  18. jonashackt revised this gist Aug 31, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -56,6 +56,7 @@ kubectl run hostnames --image=k8s.gcr.io/serve_hostname \
    --replicas=3
    ```

    `kubectl expose deployment hostnames --port=80 --target-port=9376`


    # Worker
  19. jonashackt renamed this gist Aug 31, 2018. 1 changed file with 28 additions and 13 deletions.
    41 changes: 28 additions & 13 deletions kubernetes-cheatsheet.sh → kubernetes-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,51 +1,66 @@
    # See logs of K8s cluster
    # K8s cluster

    ### See logs of K8s cluster
    https://kubernetes.io/docs/tasks/debug-application-cluster/debug-cluster/#looking-at-logs

    # show k8s api-server logging
    ### show k8s api-server logging
    sudo journalctl -u kube-apiserver --follow

    #see https://kubernetes.io/docs/reference/kubectl/cheatsheet/
    see https://kubernetes.io/docs/reference/kubectl/cheatsheet/

    # Retrieve cluster info
    ### Retrieve cluster info
    kubectl cluster-info dump

    # every component with namespace kube-system
    ### every component with namespace kube-system
    kubectl get all --namespace kube-system

    # every component
    ### every component
    kubectl get all --all-namespaces


    # etcd

    ## get all etcd entries
    ### get all etcd entries
    ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/etcd/ca.pem --cert=/etc/etcd/kube-apiserver.pem --key=/etc/etcd/kube-apiserver-key.pem get / --prefix --keys-only


    # Networking
    kubectl get nodes --output json

    # Flannel logging
    ### Flannel logging
    kubectl logs -n kube-system kube-flannel-ds-cw7kf -c kube-flannel

    kubectl get pod kube-flannel-ds-cw7kf --namespace kube-system -o yaml

    # Kube-DNS
    ### Kube-DNS
    kubectl describe pods -l k8s-app=kube-dns -n kube-system

    kubectl get nodes --output=jsonpath='{range .items[*]}{.status.addresses[?(@.type=="InternalIP")].address} {.spec.podCIDR} {"\n"}{end}'

    ## Debug kube-dns
    ## see https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/
    ### Debug kube-dns
    see https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/

    kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name | head -1) -c kubedns
    kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name | head -1) -c dnsmasq
    kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name | head -1) -c sidecar

    # CoreDNS
    ### CoreDNS
    kubectl describe pod/coredns-65db874f4f-lz5hl --namespace kube-system

    ### DNS
    see https://kubernetes.io/docs/tasks/debug-application-cluster/debug-service/#does-the-service-work-by-ip
    ```
    kubectl run hostnames --image=k8s.gcr.io/serve_hostname \
    --labels=app=hostnames \
    --port=9376 \
    --replicas=3
    ```



    # Worker

    ### K8s nodes in State NotReady
    kubectl describe nodes
    kubectl describe nodes


  20. jonashackt revised this gist Aug 26, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions kubernetes-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,8 @@ kubectl get nodes --output=jsonpath='{range .items[*]}{.status.addresses[?(@.typ
    ## see https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/

    kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name | head -1) -c kubedns
    kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name | head -1) -c dnsmasq
    kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name | head -1) -c sidecar

    # CoreDNS
    kubectl describe pod/coredns-65db874f4f-lz5hl --namespace kube-system
  21. jonashackt revised this gist Aug 26, 2018. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion kubernetes-cheatsheet.sh
    Original file line number Diff line number Diff line change
    @@ -33,5 +33,17 @@ kubectl describe pods -l k8s-app=kube-dns -n kube-system

    kubectl get nodes --output=jsonpath='{range .items[*]}{.status.addresses[?(@.type=="InternalIP")].address} {.spec.podCIDR} {"\n"}{end}'

    ## Debug kube-dns
    ## see https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/

    kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name | head -1) -c kubedns

    # CoreDNS
    kubectl describe pod/coredns-65db874f4f-lz5hl --namespace kube-system
    kubectl describe pod/coredns-65db874f4f-lz5hl --namespace kube-system



    # Worker

    ### K8s nodes in State NotReady
    kubectl describe nodes
  22. jonashackt renamed this gist Aug 23, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  23. jonashackt revised this gist Aug 15, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions bash.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # See logs of K8s cluster
    https://kubernetes.io/docs/tasks/debug-application-cluster/debug-cluster/#looking-at-logs

    # show k8s api-server logging
    sudo journalctl -u kube-apiserver --follow

    #see https://kubernetes.io/docs/reference/kubectl/cheatsheet/

    # Retrieve cluster info
  24. jonashackt revised this gist Aug 15, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions bash.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # See logs of K8s cluster
    https://kubernetes.io/docs/tasks/debug-application-cluster/debug-cluster/#looking-at-logs

    #see https://kubernetes.io/docs/reference/kubectl/cheatsheet/

    # Retrieve cluster info
  25. jonashackt revised this gist Aug 14, 2018. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions bash.sh
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,11 @@ kubectl get all --namespace kube-system
    # every component
    kubectl get all --all-namespaces

    # etcd

    ## get all etcd entries
    ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/etcd/ca.pem --cert=/etc/etcd/kube-apiserver.pem --key=/etc/etcd/kube-apiserver-key.pem get / --prefix --keys-only

    # Networking
    kubectl get nodes --output json

  26. jonashackt revised this gist Jun 21, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions bash.sh
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,9 @@ kubectl cluster-info dump
    # every component with namespace kube-system
    kubectl get all --namespace kube-system

    # every component
    kubectl get all --all-namespaces

    # Networking
    kubectl get nodes --output json

  27. jonashackt revised this gist Jun 21, 2018. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion bash.sh
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,7 @@ kubectl get pod kube-flannel-ds-cw7kf --namespace kube-system -o yaml
    # Kube-DNS
    kubectl describe pods -l k8s-app=kube-dns -n kube-system

    kubectl get nodes --output=jsonpath='{range .items[*]}{.status.addresses[?(@.type=="InternalIP")].address} {.spec.podCIDR} {"\n"}{end}'
    kubectl get nodes --output=jsonpath='{range .items[*]}{.status.addresses[?(@.type=="InternalIP")].address} {.spec.podCIDR} {"\n"}{end}'

    # CoreDNS
    kubectl describe pod/coredns-65db874f4f-lz5hl --namespace kube-system
  28. jonashackt revised this gist Jun 21, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions bash.sh
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,9 @@ kubectl cluster-info dump
    # every component with namespace kube-system
    kubectl get all --namespace kube-system

    # Networking
    kubectl get nodes --output json

    # Flannel logging
    kubectl logs -n kube-system kube-flannel-ds-cw7kf -c kube-flannel

  29. jonashackt revised this gist Jun 20, 2018. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion bash.sh
    Original file line number Diff line number Diff line change
    @@ -12,4 +12,6 @@ kubectl logs -n kube-system kube-flannel-ds-cw7kf -c kube-flannel
    kubectl get pod kube-flannel-ds-cw7kf --namespace kube-system -o yaml

    # Kube-DNS
    kubectl describe pods -l k8s-app=kube-dns -n kube-system
    kubectl describe pods -l k8s-app=kube-dns -n kube-system

    kubectl get nodes --output=jsonpath='{range .items[*]}{.status.addresses[?(@.type=="InternalIP")].address} {.spec.podCIDR} {"\n"}{end}'
  30. jonashackt revised this gist Jun 20, 2018. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion bash.sh
    Original file line number Diff line number Diff line change
    @@ -7,4 +7,9 @@ kubectl cluster-info dump
    kubectl get all --namespace kube-system

    # Flannel logging
    kubectl get pod kube-flannel-ds-cw7kf --namespace kube-system -o yaml
    kubectl logs -n kube-system kube-flannel-ds-cw7kf -c kube-flannel

    kubectl get pod kube-flannel-ds-cw7kf --namespace kube-system -o yaml

    # Kube-DNS
    kubectl describe pods -l k8s-app=kube-dns -n kube-system