Skip to content

Instantly share code, notes, and snippets.

@r10r
Forked from jonashackt/kubernetes-cheatsheet.md
Created October 12, 2021 20:01
Show Gist options
  • Save r10r/344b15c5b1a4f8398bd8b43e7f3f8d93 to your computer and use it in GitHub Desktop.
Save r10r/344b15c5b1a4f8398bd8b43e7f3f8d93 to your computer and use it in GitHub Desktop.
Kubernetes cheat sheet

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

sudo journalctl -u kube-apiserver --follow

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

Retrieve cluster info

kubectl cluster-info dump

every component with namespace kube-system

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

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

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 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

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

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

Worker

K8s nodes in State NotReady

kubectl describe nodes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment