From 6760b9ca8b6acfc92939319de392ac15a5a9d4eb Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Wed, 9 Oct 2024 00:01:13 +0200 Subject: [PATCH] feat(k8s): check usage of ephemeral storage --- knowledge base/kubernetes/kubectl.md | 32 +++++++++++++++------------- snippets/kubectl.sh | 4 ++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/knowledge base/kubernetes/kubectl.md b/knowledge base/kubernetes/kubectl.md index 76c174f..e670063 100644 --- a/knowledge base/kubernetes/kubectl.md +++ b/knowledge base/kubernetes/kubectl.md @@ -32,7 +32,7 @@ One possible output format is [JSONpath]. 1. [Verbosity and debugging](#verbosity-and-debugging) 1. [Plugins](#plugins) 1. [Further readings](#further-readings) -1. [Sources](#sources) + 1. [Sources](#sources) ## TL;DR @@ -463,9 +463,13 @@ volumeBindingMode: WaitForFirstConsumer allowVolumeExpansion: true EOF -# Check persistent volumes' usage -# Need to connect to the pod mounting it +# Check persistent volumes' usage. +# Need to connect to the pod mounting it. kubectl -n 'gitea' exec 'gitea-766fd5fb64-2qlqb' -c 'gitea' -- df -h '/data' + +# Get ephemeral storage usage for pods. +kubectl get --raw "/api/v1/nodes/ip-172-31-69-42.eu-west-1.compute.internal/proxy/stats/summary" \ +| jq '.pods[] | select(.podRef.name == "gitlab-runner-59dd68c5cb-9vcp4")."ephemeral-storage"' ``` @@ -676,20 +680,25 @@ TODO - [Enforce Pod Security Standards with Namespace Labels] - [Krew] -## Sources - -All the references in the [further readings] section, plus the following: +### Sources - [Cheatsheet] - [Run a single-instance stateful application] - [Run a replicated stateful application] - [Accessing an application on Kubernetes in Docker] - [Plugins] +- [How can I determine the current ephemeral-storage usage of a running Kubernetes pod?] + +[jsonpath]: ../jsonpath.md +[krew]: krew.placeholder +[kubernetes]: README.md + [assigning pods to nodes]: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/ [cheatsheet]: https://kubernetes.io/docs/reference/kubectl/cheatsheet @@ -700,15 +709,8 @@ All the references in the [further readings] section, plus the following: [plugins]: https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/ [taints and tolerations]: https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/ - -[further readings]: #further-readings - - -[jsonpath]: ../jsonpath.md -[krew]: krew.placeholder -[kubernetes]: README.md - [accessing an application on kubernetes in docker]: https://medium.com/@lizrice/accessing-an-application-on-kubernetes-in-docker-1054d46b64b1 +[how can i determine the current ephemeral-storage usage of a running kubernetes pod?]: https://stackoverflow.com/questions/53217227/how-can-i-determine-the-current-ephemeral-storage-usage-of-a-running-kubernetes#72891131 [run a replicated stateful application]: https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/ [run a single-instance stateful application]: https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/ diff --git a/snippets/kubectl.sh b/snippets/kubectl.sh index a6b80dc..becabca 100644 --- a/snippets/kubectl.sh +++ b/snippets/kubectl.sh @@ -70,3 +70,7 @@ kubectl cordon 'kworker-rj2' \ kubectl get --raw "/api/v1/nodes/ip-172-31-69-42.eu-west-1.compute.internal/proxy/stats/summary" # Get raw information as Prometheus metrics kubectl get --raw "/api/v1/nodes/ip-172-31-69-42.eu-west-1.compute.internal/proxy/metrics/cadvisor" + +# Get ephemeral storage usage for pods +kubectl get --raw "/api/v1/nodes/ip-172-31-69-42.eu-west-1.compute.internal/proxy/stats/summary" \ +| jq '.pods[] | select(.podRef.name == "gitlab-runner-59dd68c5cb-9vcp4")."ephemeral-storage"'