From 77c5c1f8aa74905340138fa5ada9c7b1b10fc9cb Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Fri, 10 May 2024 16:04:20 +0200 Subject: [PATCH] Add kubectl frequently used commands --- kubernetes/KUBECTL_FAQ.md | 35 +++++++++++++++++++++++++++++++++++ kubernetes/README.md | 2 ++ 2 files changed, 37 insertions(+) create mode 100644 kubernetes/KUBECTL_FAQ.md diff --git a/kubernetes/KUBECTL_FAQ.md b/kubernetes/KUBECTL_FAQ.md new file mode 100644 index 000000000..ec9ea7268 --- /dev/null +++ b/kubernetes/KUBECTL_FAQ.md @@ -0,0 +1,35 @@ +# Tips for working with kubernetes + +## Show all pods in all namespaces + +```shell +kubectl get pods --all-namespaces +``` + +(you can use `-A` instead of `--all-namespaces`) + +## Show resource usage of all pods in all namespaces + +```shell +kubectl top pods --all-namespaces --sum=true +``` + +If you want to see resource usage with container granularity, add `--containers=true`: + +```shell +kubectl top pods --all-namespaces --containers=true +``` + +## Show resource usage of all nodes + +```shell +$ kubectl top nodes +NAME CPU(cores) CPU% MEMORY(bytes) MEMORY% +pp-hetzner01 4250m 35% 53130Mi 82% +``` + +## Show resource limits and requests for all pods in all namespaces + +```shell +kubectl get pods -o "custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,MEMORY_REQUESTS:.spec.containers[*].resources.requests.memory,MEMORY_LIMITS:.spec.containers[*].resources.limits.memory,CPU_REQUESTS:.spec.containers[*].resources.requests.cpu,CPU_LIMITS:.spec.containers[*].resources.limits.cpu" -A | sort +``` diff --git a/kubernetes/README.md b/kubernetes/README.md index 981c524c7..be2881085 100644 --- a/kubernetes/README.md +++ b/kubernetes/README.md @@ -165,6 +165,8 @@ See [kubeconfig docs](https://kubernetes.io/docs/concepts/configuration/organize ## Tips +You can find frequently used `kubectl` commands in the [KUBECTL_FAQ.md](./KUBECTL_FAQ.md) file. + ### Debugging failed deployments with kubectl If a deployment fails, you can use `kubectl` to get more information. For example, to see the status of the pods: