Skip to content

Commit

Permalink
Add kubectl frequently used commands
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusroemer committed May 10, 2024
1 parent d306bd2 commit 77c5c1f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions kubernetes/KUBECTL_FAQ.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 2 additions & 0 deletions kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 77c5c1f

Please sign in to comment.