This is my Kubernetes reference page. Most are commands that I don't want to forget, links to credits where due.
kubectl cluster-info dump
kubectl get nodes -o jsonpath='{ $.items[*].status.addresses[?(@.type=="InternalIP")].address }'
Deploy Kubernetes Dashboard & Retrieve Token/Port
VER="$(curl -sL -o /dev/null -w "%{url_effective}" https://github.com/kubernetes/dashboard/releases/latest | awk -F "/" '{print $NF}')"
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/${VER}/src/deploy/recommended/kubernetes-dashboard.yaml
kubectl delete service -n kube-system kubernetes-dashboard
kubectl expose deployment -n kube-system kubernetes-dashboard --type=NodePort
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kube-system
EOF
kubectl describe secret -n kube-system $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
kubectl get svc -n kube-system -l k8s-app=kubernetes-dashboard -o jsonpath='{.spec.ports[].nodePort}'
kubectl get pods --all-namespaces --field-selector 'status.phase==Failed' -o json | kubectl delete -f -
Get all node ports on cluster
kubectl get svc --all-namespaces -o go-template='{{range .items}}{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}{{end}}'
Working with Kubernetes Field Selectors
kubectl get pods -n <namespace> --field-selector=status.phase!=Running
kubectl get pods -n <namespace> --field-selector=status.phase!=Running,spec.restartPolicy=Always
kubectl exec -it --namespace=prometheus "$(kubectl get po -o wide -n prometheus -l app=prometheus,component=node-exporter --no-headers=true | grep "$(hostname -f)" | awk '{print $1}')" -- df -h
kubectl get pod -n rook-ceph -l app=rook-ceph-osd -o=jsonpath='{range .items[*]}{.status.conditions[?(@.type=="Ready")].status}{end}'
kubectl -n rook-ceph exec $(kubectl get pods -n rook-ceph -l app=rook-ceph-tools -o jsonpath='{.items[0].metadata.name}') -- ceph status
(other Ceph commands: ceph osd status, ceph health detail, ceph quorum_status --format json-pretty, ceph mon dump, ceph df, ceph osd df, ceph osd pool ls detail)