Kubernetes utils
June 26, 2023
kubectl count (krew)
Данный плагин предназначен для подсчёта количества ресурсов в Namespace по kind.
( set -x; cd "$(mktemp -d)" && OS="$(uname | tr '[:upper:]' '[:lower:]')" && ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" && KREW="krew-${OS}_${ARCH}" && curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" && tar zxvf "${KREW}.tar.gz" && ./"${KREW}" install krew )
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
kubectl krew install count
kubectl count pods,ds,deploy kubectl count -n kube-system po,deploy #Вывод в yaml формате. kubectl count -oy -n kube-system deploy,svc
kubectl count -oy -n kube-system deploy,svc - namespace: kube-system groupVersion: apps/v1 kind: Deployment count: 3 - namespace: kube-system groupVersion: v1 kind: Service count: 10
kubectl count pods -n kube-system +-------------+------------------------+------------+-------+ | Namespace | GroupVersion | Kind | Count | +-------------+------------------------+------------+-------+ | kube-system | v1 | Pod | 46 | + +------------------------+------------+ + | | metrics.k8s.io/v1beta1 | PodMetrics | | +-------------+------------------------+------------+-------+
Полезные ссылки.
GitHUB проекта: https://github.com/chenjiandongx/kubectl-count
Установка krew: https://krew.sigs.k8s.io/docs/user-guide/setup/install/
Список плагинов krew: https://krew.sigs.k8s.io/plugins/