Last active
April 8, 2025 08:59
-
-
Save pydevops/0efd399befd960b5eb18d40adb68ef83 to your computer and use it in GitHub Desktop.
Revisions
-
pydevops revised this gist
Nov 30, 2024 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -161,6 +161,8 @@ kubectl get --raw /apis/${group/version} | jq -r '.resources[].kind' kubectl get --raw /apis/apps/v1 | jq . -C | less -R API_SERVER_ENDPOINT="$(kubectl config view --raw -o json | jq -r '.clusters[0].cluster.server') ``` ### list resources under a specific api version. -
pydevops revised this gist
Nov 19, 2024 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -265,4 +265,9 @@ kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes \ | jq '[.items [] | {nodeName: .metadata.name, nodeCpu: .usage.cpu, nodeMemory: .usage.memory}]' kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods | jq . -C | less -R ``` ## labels ``` kubectl get nodes -L karpenter.sh/nodepool -L node.kubernetes.io/instance-type -L topology.kubernetes.io/zone -L karpenter.sh/capacity-type ``` -
pydevops revised this gist
Jul 16, 2024 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -108,6 +108,15 @@ kubectl run -it --rm debug --image=busybox -- sh ``` * busybox https://busybox.net/downloads/BusyBox.html ## cert compare ``` kubectl get validatingwebhookconfigurations.admissionregistration.k8s.io aws-load-balancer-webhook -ojsonpath={.webhooks[0].clientConfig.caBundle} | base64 -d | openssl x509 -noout -text kubectl get secret -n kube-system aws-load-balancer-tls -ojsonpath="{.data.ca\.crt}" |base64 -d |openssl x509 -noout -text ``` ## context, namespace ``` get current context: kubectl config view -o=jsonpath='{.current-context}' -
pydevops revised this gist
Jul 12, 2024 . 1 changed file with 13 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -86,10 +86,22 @@ Did this for cleaning up pods with not in Running state such as Terminated k get po --field-selector=status.phase!=Running -o custom-columns=":metadata.name" --no-headers | xargs kubectl delete po ``` ## mysql and psql ``` kubectl run -n default mysql-client-${USER} --image=mysql:5.7 -it --restart=Never -- /bin/bash kubectl run -n default psql-cli-${USER} --image=postgres -it --restart=Never -- bash ``` ## wait for * https://vadosware.io/post/so-you-need-to-wait-for-some-kubernetes-resources/ ``` kubectl -n istio-system wait --for=jsonpath='{.data.ca\.crt}' secrets/cacerts ``` ## debug ``` kubectl run -it --rm debug --image=busybox -- sh -
pydevops revised this gist
Jun 5, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ ## references * https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands * [how it works](https://github.com/jamiehannaford/what-happens-when-k8s) * https://medium.com/@bingolbalihasan/how-does-kubectl-work-writing-custom-kubectl-commands-da86e5d49c74 -
pydevops revised this gist
Jun 5, 2024 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ ## reference * https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands * [how it works](https://github.com/jamiehannaford/what-happens-when-k8s) * https://medium.com/@bingolbalihasan/how-does-kubectl-work-writing-custom-kubectl-commands-da86e5d49c74 ## cheatsheet & tips * https://kubernetes.io/docs/user-guide/kubectl-cheatsheet/ -
pydevops revised this gist
Aug 1, 2023 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,8 +2,9 @@ * https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands * [how it works](https://github.com/jamiehannaford/what-happens-when-k8s) ## cheatsheet & tips * https://kubernetes.io/docs/user-guide/kubectl-cheatsheet/ * https://github.com/devoriales/kubectl-cheatsheet * https://learncloudnative.com/blog/2022-05-10-kubectl-tips * https://itnext.io/tips-tricks-for-cka-ckad-and-cks-exams-cc9dade1f76d * https://cloud.google.com/anthos/gke/docs/on-prem/reference/cheatsheet -
pydevops revised this gist
Jun 14, 2023 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -181,10 +181,13 @@ kubectl rollout undo deployment/hello ``` ## rbac ``` # list what a sa 's rbac k auth can-i --list --as system:serviceaccount:datadog:datadog k auth can-i get crd --as system:serviceaccount:velero:velero k auth can-i '*' '*' --as system:serviceaccount:default:remote-admin-sa --all-namespaces # list what I can do k auth can-i get crd k auth can-i '*' '*' --all-namespaces # with krew plugins -
pydevops revised this gist
May 22, 2023 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -38,6 +38,11 @@ kubectl get pods -o jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{ran kubectl get svc -l component=elasticsearch,role=client -o jsonpath='{..ip}' grace=$(kubectl get po cassandra-0 -o=jsonpath=‘{.spec.terminationGracePeriodSeconds}’) grace=$(kubectl get sts -l component=elasticsearch,role=data -o jsonpath='{..terminationGracePeriodSeconds}' # list node instance type, zone, ami echo "***list karpenter nodes ami" kubectl get nodes -L karpenter.k8s.aws/instance-ami-id -l karpenter.sh/provisioner-name=default -o custom-columns="Name:.metadata.name,InstanceType:.metadata.labels.node\.kubernetes\.io/instance-type,\ Zone:.metadata.labels.topology\.kubernetes\.io/zone,Ami:.metadata.labels.karpenter\.k8s\.aws/instance-ami-id" ``` ## custom-columns -
pydevops revised this gist
Dec 14, 2022 . 1 changed file with 0 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -18,11 +18,6 @@ * https://karlkfi.medium.com/compendium-of-kubernetes-application-deployment-tools-80a828c91e8f * https://krew.sigs.k8s.io/plugins/ ## JSONAPTH -
pydevops revised this gist
Dec 14, 2022 . 1 changed file with 8 additions and 16 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -28,38 +28,30 @@ ``` # loop with range # list pod's name k get po -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' k get po -o jsonpath={.items..metadata.name} # list node names and cpu capacity k get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.capacity.cpu}{"\n"}{end}' # list image kubectl get pods -o jsonpath="{..image}" | tr -s '[[:space:]]' '\n' | sort | uniq kubectl get pods -o jsonpath="{.items[*].spec.containers[*].image}" kubectl get pods -o jsonpath='{.items[*].status.podIP}' kubectl get pods -o jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' kubectl get svc -l component=elasticsearch,role=client -o jsonpath='{..ip}' grace=$(kubectl get po cassandra-0 -o=jsonpath=‘{.spec.terminationGracePeriodSeconds}’) grace=$(kubectl get sts -l component=elasticsearch,role=data -o jsonpath='{..terminationGracePeriodSeconds}' ``` ## custom-columns ``` # same query in jsonpath k get po -o custom-columns='POD_NAME:metadata.name' # same query as in jsonpath for node and cpu counts k get nodes -o custom-columns="NODE:.metadata.name,CPU:.status.capacity.cpu" # node name k get nodes -o custom-columns=NAME:.metadata.name # pod name -
pydevops revised this gist
Dec 14, 2022 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,13 +3,12 @@ * [how it works](https://github.com/jamiehannaford/what-happens-when-k8s) ## cheatsheet * https://kubernetes.io/docs/user-guide/kubectl-cheatsheet/ * https://learncloudnative.com/blog/2022-05-10-kubectl-tips * https://itnext.io/tips-tricks-for-cka-ckad-and-cks-exams-cc9dade1f76d * https://cloud.google.com/anthos/gke/docs/on-prem/reference/cheatsheet * https://medium.com/flant-com/kubectl-commands-and-tips-7b33de0c5476 * https://prefetch.net/blog/2019/10/16/the-beginners-guide-to-creating-kubernetes-manifests/ * https://medium.com/faun/kubectl-commands-cheatsheet-43ce8f13adfb * https://gist.github.com/so0k/42313dbb3b547a0f51a547bb968696ba * https://www.atomiccommits.io/everything-useful-i-know-about-kubectl @@ -217,8 +216,10 @@ k access-matrix --sa kube-system:kube-state-metrics ``` ## find top resource hungry pod ``` # pod sort by cpu k top pods --sort-by=cpu --no-headers # container sort by memory k top pods --containers --sort-by=memory kubectl top pods -A --no-headers | sort -rn -k 3 # memory kubectl top pods -A --no-headers | sort -rn -k 4 -
pydevops revised this gist
Dec 14, 2022 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,6 @@ ## cool gear to have * https://karlkfi.medium.com/a-select-list-of-kubernetes-tools-38249fc27155 * https://karlkfi.medium.com/compendium-of-kubernetes-application-deployment-tools-80a828c91e8f * https://krew.sigs.k8s.io/plugins/ ## imperative -
pydevops revised this gist
Dec 14, 2022 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -30,6 +30,9 @@ ``` # loop with range # list pods k get po -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' # list node names and cpu capacity k get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.capacity.cpu}{"\n"}{end}' kubectl get pods -o jsonpath="{..image}" @@ -54,6 +57,8 @@ grace=$(kubectl get sts -l component=elasticsearch,role=data -o jsonpath='{..ter ## custom-columns ``` # same query in jsonpath k get po -o custom-columns='POD_NAME:.metadata.name' # same query as in jsonpath for node and cpu counts k get nodes -o custom-columns="NODE:.metadata.name,CPU:.status.capacity.cpu" -
pydevops revised this gist
Dec 13, 2022 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -54,18 +54,27 @@ grace=$(kubectl get sts -l component=elasticsearch,role=data -o jsonpath='{..ter ## custom-columns ``` # same query as in jsonpath for node and cpu counts k get nodes -o custom-columns="NODE:.metadata.name,CPU:.status.capacity.cpu" # node name k get nodes -o custom-columns=NAME:.metadata.name # pod name k get po -o custom-columns=NAME:.metadata.name # image name k get po -o custom-columns='IMAGE:spec.containers[*].image' # list container image and k8s-app lable value in kube-system k get deployment -o custom-columns='IMAGE:.spec.template.spec.containers[*].image,LABEL:.spec.template.metadata.labels.k8s-app' -n kube-system ``` ## sort-by ``` # implict range or items[*] k get nodes --sort-by=".metadata.name" k get nodes --sort-by=".status.capacity.cpu" k get po --sort-by=.spec.nodeName -o wide k get po --sort-by=".metadata.creationTimestamp" k get pv --sort-by=.spec.capacity.storage -o custom-columns="NAME:.metadata.name,CAPACITY:.spec.capacity.storage" -
pydevops revised this gist
Dec 13, 2022 . 1 changed file with 47 additions and 37 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -26,6 +26,53 @@ * https://medium.com/bitnami-perspectives/imperative-declarative-and-a-few-kubectl-tricks-9d6deabdde * https://blog.heptio.com/using-kubectl-to-jumpstart-a-yaml-file-heptioprotip-6f5b8a63a3ea ## JSONAPTH ``` # loop with range k get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.capacity.cpu}{"\n"}{end}' kubectl get pods -o jsonpath="{..image}" kubectl get pods -o jsonpath="{.items[*].spec.containers[*].image}" kubectl get pods -o jsonpath='{.items[*].status.podIP}' kubectl get nodes -o jsonpath='{.items[*].spec.podCIDR}' | tr " " "\n" kubectl get nodes -o json | jq '.items[] | .spec' kubectl get no -o go-template='{{range .items}}{{.spec.podCIDR}}{{"\n"}}{{end}}' kubectl get pods -o jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' kubectl get pods -o go-template --template="{{range .items}}{{range .spec.containers}}{{.image}} {{end}}{{end}}" kubectl get svc -l component=elasticsearch,role=client -o jsonpath='{..ip}' kubectl get pods --all-namespaces -o jsonpath="{..image}" |\ tr -s '[[:space:]]' '\n' |\ sort |\ uniq -c grace=$(kubectl get po cassandra-0 -o=jsonpath=‘{.spec.terminationGracePeriodSeconds}’) grace=$(kubectl get sts -l component=elasticsearch,role=data -o jsonpath='{..terminationGracePeriodSeconds}' ``` ## custom-columns ``` # node name k get nodes -o custom-columns=NAME:.metadata.name # pod name k get po -o custom-columns=NAME:.metadata.name # image name k get po -o custom-columns='IMAGE:spec.containers[*].image' k get deployment -o custom-columns='IMAGE:.spec.template.spec.containers[*].image,LABEL:.spec.template.metadata.labels.k8s-app' -n kube-system ``` ## sort-by ``` # implict range or items[*] k get po --sort-by=.spec.nodeName -o wide k get po --sort-by=".metadata.creationTimestamp" k get pv --sort-by=.spec.capacity.storage -o custom-columns="NAME:.metadata.name,CAPACITY:.spec.capacity.storage" ``` ## clean up pods Did this for cleaning up pods with not in Running state such as Terminated @@ -106,43 +153,6 @@ echo $(kubectl get secret/terraform -o jsonpath="{.data['terraform\.json']}" | b * https://gist.github.com/so0k/42313dbb3b547a0f51a547bb968696ba * https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/ ## Get the TCP LB port and IP ``` -
pydevops revised this gist
Dec 13, 2022 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -128,8 +128,13 @@ uniq -c ``` ## custom-columns ``` # node name k get nodes -o custom-columns=NAME:.metadata.name # pod name k get po -o custom-columns=NAME:.metadata.name # image name k get po -o custom-columns='IMAGE:spec.containers[*].image' k get pv --sort-by=.spec.capacity.storage -o custom-columns="NAME:.metadata.name,CAPACITY:.spec.capacity.storage" k get deployment -o custom-columns='IMAGE:.spec.template.spec.containers[*].image,LABEL:.spec.template.metadata.labels.k8s-app' -n kube-system ``` ## sort-by -
pydevops revised this gist
Aug 21, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ * [how it works](https://github.com/jamiehannaford/what-happens-when-k8s) ## cheatsheet * https://learncloudnative.com/blog/2022-05-10-kubectl-tips * https://itnext.io/tips-tricks-for-cka-ckad-and-cks-exams-cc9dade1f76d * https://cloud.google.com/anthos/gke/docs/on-prem/reference/cheatsheet * https://medium.com/flant-com/kubectl-commands-and-tips-7b33de0c5476 -
pydevops revised this gist
Mar 9, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ * https://karlkfi.medium.com/a-select-list-of-kubernetes-tools-38249fc27155 * https://karlkfi.medium.com/compendium-of-kubernetes-application-deployment-tools-80a828c91e8f * https://medium.com/free-code-camp/how-to-set-up-a-serious-kubernetes-terminal-dd07cab51cd4 * https://krew.sigs.k8s.io/plugins/ ## imperative * https://kubernetes.io/docs/tasks/manage-kubernetes-objects/imperative-command/ -
pydevops revised this gist
Mar 9, 2022 . 1 changed file with 6 additions and 24 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -71,32 +71,14 @@ kubectl api-resources --sort-by=kind # find out what is under the api group k api-resources --api-group=networking.k8s.io NAME SHORTNAMES APIVERSION NAMESPACED KIND ingressclasses networking.k8s.io/v1 false IngressClass ingresses ing networking.k8s.io/v1 true Ingress networkpolicies netpol networking.k8s.io/v1 true NetworkPolicy # then we can explain with $APIVERSION k explain --api-version=$APIVERSION ingress --recursive k explain --api-version=apps/v1 deployment --recursive # for each "group/version" in the output above except for "api/v1" -
pydevops revised this gist
Mar 9, 2022 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -58,7 +58,8 @@ kubectl config set-context --current --namespace=kube-system ## API * https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/ * API group https://kubernetes.io/docs/reference/using-api/api-overview/#api-groups * API convention https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#api-conventions ``` # Print the supported API group and its versions on the server, in the form of "group/version" -
pydevops revised this gist
Mar 9, 2022 . 1 changed file with 10 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -176,16 +176,6 @@ kubectl rollout resume deployment/hello # roll back kubectl rollout undo deployment/hello ``` ## rbac ``` k auth can-i get crd @@ -212,6 +202,16 @@ k who-can create customresourcedefinition k access-matrix --sa default:deployer k access-matrix --sa kube-system:kube-state-metrics ``` ## find top resource hungry pod ``` # cpu k top pods --sort-by=cpu --no-headers kubectl top pods -A --no-headers | sort -rn -k 3 # memory kubectl top pods -A --no-headers | sort -rn -k 4 # top 1 kubectl top pod --no-headers | grep -v NAME | sort -k 3 -nr | awk -F ' ' 'NR==1{print $1}' ``` ## metrics -
pydevops revised this gist
Mar 9, 2022 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -179,12 +179,12 @@ kubectl rollout undo deployment/hello ## find top resource hungry pod ``` # cpu k top pods --sort-by=cpu --no-headers kubectl top pods -A --no-headers | sort -rn -k 3 # memory kubectl top pods -A --no-headers | sort -rn -k 4 # top 1 kubectl top pod --no-headers | grep -v NAME | sort -k 3 -nr | awk -F ' ' 'NR==1{print $1}' ``` ## rbac ``` -
pydevops revised this gist
Mar 9, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -99,7 +99,7 @@ k explain ingress --api-version=networking.k8s.io/v1 --recursive k explain --api-version=apps/v1 deployment --recursive # for each "group/version" in the output above except for "api/v1" kubectl get --raw /apis/${group/version} | jq -r '.resources[].kind' kubectl get --raw /apis/apps/v1 | jq . -C | less -R -
pydevops revised this gist
Mar 8, 2022 . 1 changed file with 22 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -212,4 +212,26 @@ k who-can create customresourcedefinition k access-matrix --sa default:deployer k access-matrix --sa kube-system:kube-state-metrics ``` ## metrics * https://talkcloudlytome.com/raw-kubernetes-metrics-with-kubectl/ * https://www.datadoghq.com/blog/how-to-collect-and-graph-kubernetes-metrics/ ``` # all nodes kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes | jq -C . | less -R # individual node kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes/$NODE_NAME # all pods kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods | jq . -C | less -R # individual pod kubectl get --raw /apis/metrics.k8s.io/v1beta1/namespaces/$NS/pods/$POD # jq kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes \ | jq '[.items [] | {nodeName: .metadata.name, nodeCpu: .usage.cpu, nodeMemory: .usage.memory}]' kubectl get --raw /apis/metrics.k8s.io/v1beta1/pods | jq . -C | less -R ``` -
pydevops revised this gist
Jan 25, 2022 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,13 @@ * https://medium.com/bitnami-perspectives/imperative-declarative-and-a-few-kubectl-tricks-9d6deabdde * https://blog.heptio.com/using-kubectl-to-jumpstart-a-yaml-file-heptioprotip-6f5b8a63a3ea ## clean up pods Did this for cleaning up pods with not in Running state such as Terminated ``` k get po --field-selector=status.phase!=Running -o custom-columns=":metadata.name" --no-headers | xargs kubectl delete po ``` ## waitfor * https://vadosware.io/post/so-you-need-to-wait-for-some-kubernetes-resources/ -
pydevops revised this gist
Jan 11, 2022 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -11,6 +11,7 @@ * https://learnk8s.io/blog/kubectl-productivity/ * https://medium.com/faun/kubectl-commands-cheatsheet-43ce8f13adfb * https://gist.github.com/so0k/42313dbb3b547a0f51a547bb968696ba * https://www.atomiccommits.io/everything-useful-i-know-about-kubectl ## cool gear to have * https://karlkfi.medium.com/a-select-list-of-kubernetes-tools-38249fc27155 @@ -23,7 +24,9 @@ * https://medium.com/better-programming/kubernetes-tips-create-pods-with-imperative-commands-in-1-18-62ea6e1ceb32 * https://medium.com/bitnami-perspectives/imperative-declarative-and-a-few-kubectl-tricks-9d6deabdde * https://blog.heptio.com/using-kubectl-to-jumpstart-a-yaml-file-heptioprotip-6f5b8a63a3ea ## waitfor * https://vadosware.io/post/so-you-need-to-wait-for-some-kubernetes-resources/ ## debug -
pydevops revised this gist
Jan 4, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -135,7 +135,7 @@ uniq -c ## custom-columns ``` k get po -A -o=custom-columns='DATA:spec.containers[*].image' k get pv --sort-by=.spec.capacity.storage -o=custom-columns="NAME:.metadata.name,CAPACITY:.spec.capacity.storage" k get deployment -o custom-columns='IMAGE:.spec.template.spec.containers[*].image,LABEL:.spec.template.metadata.labels.k8s-app' -n kube-system ``` ## sort-by -
pydevops revised this gist
Jan 4, 2022 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -23,6 +23,8 @@ * https://medium.com/better-programming/kubernetes-tips-create-pods-with-imperative-commands-in-1-18-62ea6e1ceb32 * https://medium.com/bitnami-perspectives/imperative-declarative-and-a-few-kubectl-tricks-9d6deabdde * https://blog.heptio.com/using-kubectl-to-jumpstart-a-yaml-file-heptioprotip-6f5b8a63a3ea ## waitfor * https://vadosware.io/post/so-you-need-to-wait-for-some-kubernetes-resources/ ## debug ``` -
pydevops revised this gist
Dec 15, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ ## reference * https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands * [how it works](https://github.com/jamiehannaford/what-happens-when-k8s) ## cheatsheet * https://itnext.io/tips-tricks-for-cka-ckad-and-cks-exams-cc9dade1f76d
NewerOlder