From d10f17879faf117cb902914121a66270af0be6c2 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Tue, 8 Oct 2024 23:42:48 +0200 Subject: [PATCH] chore(k8s): get raw data --- knowledge base/kubernetes/kubectl.md | 72 ++++++++++++++++------------ snippets/kubectl.sh | 5 ++ 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/knowledge base/kubernetes/kubectl.md b/knowledge base/kubernetes/kubectl.md index 91eae2a..76c174f 100644 --- a/knowledge base/kubernetes/kubectl.md +++ b/knowledge base/kubernetes/kubectl.md @@ -13,7 +13,8 @@ kubectl get deploy,rs,po -A Use `kubectl api-resources` to check out the available resources and their abbreviations. Multiple resource types can be specified together, but **only one resource name** is accepted at a time.
-Resource names are case **sensitive** and will filter the requested resources; use the `-l` (`--selector`) option to play around filtering: +Resource names are case **sensitive** and will filter the requested resources; use the `-l` (`--selector`) option to +play around filtering: ```sh kubectl get deployments,replicaSets -A @@ -23,8 +24,6 @@ kubectl get pods -l 'app=nginx,tier=frontend' One possible output format is [JSONpath]. -## Table of contents - 1. [TL;DR](#tldr) 1. [Configuration](#configuration) 1. [Configure access to multiple clusters](#configure-access-to-multiple-clusters) @@ -412,6 +411,11 @@ kubectl run --rm -it --image 'amazon/aws-cli:2.17.16' 'awscli' -- autoscaling de # Attach to running pods. kubectl attach 'alpine' -c 'alpine' -it + +# Get raw information as JSON +kubectl get --raw "/api/v1/nodes/node-name/proxy/stats/summary" +# Get raw information as Prometheus metrics +kubectl get --raw "/api/v1/nodes/node-name/proxy/metrics/cadvisor" ``` @@ -432,8 +436,7 @@ kubectl delete crds -l "helm.sh/chart=awx-operator" # Run pods with specific specs. kubectl -n 'kube-system' run --rm -it 'awscli' --overrides '{"spec":{"serviceAccountName":"cluster-autoscaler-aws"}}' \ --image '012345678901.dkr.ecr.eu-west-1.amazonaws.com/cache/amazon/aws-cli:2.17.16' \ - -- \ - autoscaling describe-auto-scaling-groups + -- autoscaling describe-auto-scaling-groups # Show Containers' status, properties and capabilities from the inside. # Run the command from *inside* the container. @@ -459,6 +462,10 @@ reclaimPolicy: Delete volumeBindingMode: WaitForFirstConsumer allowVolumeExpansion: true EOF + +# Check persistent volumes' usage +# Need to connect to the pod mounting it +kubectl -n 'gitea' exec 'gitea-766fd5fb64-2qlqb' -c 'gitea' -- df -h '/data' ``` @@ -467,19 +474,23 @@ EOF The configuration files are loaded as follows: -1. If the `--kubeconfig` flag is set, then only that file is loaded; the flag may only be set **once**, and no merging takes place: +1. If the `--kubeconfig` flag is set, then only that file is loaded; the flag may only be set **once**, and no merging + takes place: ```sh kubectl config --kubeconfig 'config.local' view ``` -1. If the `$KUBECONFIG` environment variable is set, then it is used as a list of paths following the normal path delimiting rules for your system; the files are merged: +1. If the `$KUBECONFIG` environment variable is set, then it is used as a list of paths following the normal path + delimiting rules for your system; the files are merged: ```sh export KUBECONFIG="/tmp/config.local:.kube/config.prod" ``` - When a value is modified, it is modified in the file that defines the stanza; when a value is created, it is created in the first existing file; if no file in the chain exist, then the last file in the list is created with the configuration. + When a value is modified, it is modified in the file that defines the stanza; when a value is created, it is created + in the first existing file; if no file in the chain exist, then the last file in the list is created with the + configuration. 1. If none of the above happens, `~/.kube/config` is used, and no merging takes place. @@ -578,7 +589,8 @@ data: EOF ``` -When subsequentially (re-)applying manifests, one can compare the current state of the cluster against the state it would be in if the manifest was applied: +When subsequentially (re-)applying manifests, one can compare the current state of the cluster against the state it +would be in if the manifest was applied: ```sh kubectl diff -f 'manifest.yaml' @@ -606,16 +618,16 @@ kubectl create job 'backup-before-upgrade-13.6.2-to-13.9.2' \ Add the `-o`, `--output` option to a command: -Format | Description ------------------------------------ | ----------- -`-o=custom-columns=` | Print a table using a comma separated list of custom columns -`-o=custom-columns-file=` | Print a table using the custom columns template in the \ file -`-o=json` | Output a JSON formatted API object -`-o=jsonpath=