Last active
June 24, 2025 15:43
-
-
Save dixsonhuie/72321b52e8f96ab0b0bc69711fc9e026 to your computer and use it in GitHub Desktop.
k8s snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use this when k8s is stuck deleting a resource | |
kubectl patch <resource type>/<resource name> -p '{"metadata":{"finalizers":[]}}' --type=merge | |
Example, | |
kubectl patch pus/pu -p '{"metadata":{"finalizers":[]}}' --type=merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this works similar to force delete | |
helm delete <chart name> --no-hooks | |
# show all charts, even ones that were not successfully deleted | |
helm list -aA | |
-a no filter applied (uninstalling releases not shown otherwise) | |
-A all namespaces |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Show previous failed deployment logs (useful if the pod starts but then crashes and restarts). | |
kubectl logs --previous <pod name> -n <namespace> | |
2. Describe pod will show events | |
kubectl describe pod <pod name> | |
Alternatively, get pod events (useful if the k8s cluster contains many pods and only interested in a single pod) | |
kubectl get event --namespace <namespace> --field-selector involvedObject.name=<pod name> | |
Or get events but sort by timestamp | |
kubectl get events --sort-by='.metadata.creationTimestamp' | |
3. Debug initContainers. Show initContainer statuses. | |
Example: | |
kubectl get pod <pod name> --template '{{.status.initContainerStatuses}}' | |
4. Get logs for an initcontainer | |
kubectl logs <pod name> -c <init container name> | |
Kubernetes documentation | |
Debug main page: https://kubernetes.io/docs/tasks/debug/debug-application/ | |
Debug initContainer subtopic: https://kubernetes.io/docs/tasks/debug-application-cluster/debug-init-containers/ | |
Debug pod subtopic: https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# restore context of minikube, when using tools such kubectl | |
minikube update-context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl get nodes -o wide | awk {'print $1" " $2 " " $7'} | column -t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl get pod -o="custom-columns=NAME:.metadata.name,INIT-CONTAINERS:.spec.initContainers[*].name,INIT-CONTAINERS-IMAGE:.spec.initContainers[*].image,CONTAINERS:.spec.containers[*].name,CONTAINERS-IMAGE:.spec.containers[*].image" | |
NAME INIT-CONTAINERS INIT-CONTAINERS-IMAGE CONTAINERS CONTAINERS-IMAGE | |
grafana-6fc5bf87d7-87nl7 <none> <none> grafana-sc-dashboard,grafana quay.io/kiwigrid/k8s-sidecar:1.19.2,grafana/grafana:9.2.5 | |
influxdb-0 <none> <none> influxdb influxdb:1.8.10 | |
xap-dgw-xap-pu-0 <none> <none> pu-container gigaspaces/smart-cache-enterprise:16.4.2 | |
xap-manager-0 check-external-service-ready gigaspaces/smart-cache-enterprise:16.4.2 gigaspaces-container gigaspaces/smart-cache-enterprise:16.4.2 | |
xap-operator-68fd794b6f-tnvxv create-keystore,wait-for-master-before-starup alpine/openssl,busybox:1.36.0 xap-operator gigaspaces/cache-operator:16.4.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get values passed into helm release | |
helm get values demo -n dih | |
^ release name | |
# Option 1 | |
# generate manifests that would be used for helm install | |
# can redirect output to a file and treated like a regular k8s manifest, using kubectl apply -f | |
helm template dih ./dih -f new-release-values.yaml -n dih --debug | |
^ release name | |
^ local chart | |
^ yaml file containing list of override values | |
^ debug is optional (from what I've seen does not add much value). | |
# Option 2 - more verbose, but option 1 usually provides what is needed | |
# generate manifests but has a section that shows computed values | |
helm install dih dih/dih -n dih --dry-run --debug |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment