# Kubectl cheat-sheet

**URL:** <https://forum.meshat.se/t/kubectl-cheat-sheet/127>\
**Category:** Bloggar\
**Tags:** linux\
**Created:** [28 Februari 2023 08:04 UTC](https://forum.meshat.se/t/kubectl-cheat-sheet/127 "2023-02-28T08:04:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![selea](https://forum.meshat.se/user_avatar/forum.meshat.se/selea/32/16_2.png) [@selea](https://forum.meshat.se/u/selea)\
**Post date:** [28 Februari 2023 08:04 UTC](https://forum.meshat.se/t/kubectl-cheat-sheet/127/1 "2023-02-28T08:04:47Z")

</div>

## Just some random #kubectl commands for myself. I have tested these on 1.20 \<\> 1.25

#### Get all ingress logs (if your ingress is nginx)

```
kubectl logs -n ingress-nginx -l app.kubernetes.io/name=ingress-nginx

```

#### Get all logs from Deployment

```
kubectl logs deployment/ -n --watch

```

#### Why is the pod stuck in “ContainerCreating”?

```
kubectl get events --sort-by=.metadata.creationTimestamp --watch

```

#### Restart your deployment, nice and clean

```
kubectl rollout restart deployment/ -n 

```

#### Check which namespaces are using the most disk space

```
kubectl get namespace --no-headers | xargs -I {} sh -c 'echo {}; kubectl get pods -n {} --no-headers | xargs -I {} sh -c "kubectl logs {} -n {} | wc -c"' | awk '{print $1" "($2/1024/1024)" MB"}' | sort -k2 -n -r | head

```

#### Check if any pods are using a lot of disk space

```
kubectl get pods --all-namespaces -o json | jq '.items[].spec.containers[].resources.requests.storage' | grep -v null

```

#### Check the Kubernetes event logs for any disk-related errors

```
kubectl get events --field-selector involvedObject.kind=Node,reason=OutOfDisk

```

I'll add more when I find more usefull stuff

#linux #k8s #kubernetes #kubectl #ingress #nginx #deployment #logs

* * *
Detta är ett kopplat diskussionsämne till det ursprungliga inlägget på [https://blogs.linux.pizza/kubectl-cheat-sheet](https://blogs.linux.pizza/kubectl-cheat-sheet)
