{"id":21712591,"url":"https://github.com/mhausenblas/krs","last_synced_at":"2025-07-07T20:11:41.176Z","repository":{"id":140043640,"uuid":"151563750","full_name":"mhausenblas/krs","owner":"mhausenblas","description":"A command line tool for capturing and serializing Kubernetes resource statistics in OpenMetrics format","archived":false,"fork":false,"pushed_at":"2018-10-24T08:09:14.000Z","size":120,"stargazers_count":96,"open_issues_count":2,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T18:06:34.013Z","etag":null,"topics":["cli","kubernetes","openmetrics"],"latest_commit_sha":null,"homepage":"https://mhausenblas.info/krs/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mhausenblas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-04T11:51:19.000Z","updated_at":"2025-03-16T21:57:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"4d060097-b824-46af-bdc3-493dbb3900a2","html_url":"https://github.com/mhausenblas/krs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhausenblas%2Fkrs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhausenblas%2Fkrs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhausenblas%2Fkrs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhausenblas%2Fkrs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mhausenblas","download_url":"https://codeload.github.com/mhausenblas/krs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248610345,"owners_count":21132921,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","kubernetes","openmetrics"],"created_at":"2024-11-25T23:40:22.503Z","updated_at":"2025-04-12T18:08:28.168Z","avatar_url":"https://github.com/mhausenblas.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Report Card](https://goreportcard.com/badge/github.com/mhausenblas/krs)](https://goreportcard.com/report/github.com/mhausenblas/krs)\n[![container repository on Quay](https://quay.io/repository/mhausenblas/krs/status \"Docker Repository on Quay\")](https://quay.io/repository/mhausenblas/krs)\n\n\u003cdiv style=\"color: #e03030; font-size: smaller; font-weight: bolder; margin-bottom: 20px; \"\u003e\nNOTE: this is heavy work in progress and we may introduce breaking, non-backwards compatible changes in any version before 1.0 and also, use it at your own risk, ideally only in dev and test environments.\n\u003c/div\u003e\n\n\u003cdiv style=\"text-align: center; margin-bottom: 50px;\"\u003e\n  \u003cimg src=\"om-k8s.png\" width=\"200px\" /\u003e\n\u003c/div\u003e\n\n`krs` is a command line tool for capturing and serializing Kubernetes resource statistics in [OpenMetrics](https://github.com/OpenObservability/OpenMetrics) format. It dumps statistics about Kubernetes resources, for example the number of pods in a certain namespace, on a periodic basis to local storage. The kind of resources (pods, services, etc.) as well as the scope, that is, cluster-level or a list of namespaces, is configurable. You can use `krs` either on the client-side (for example, from your laptop) or in-cluster, like in a deployment. Note that `krs` leaves the decision where and how long-term storage is carried out up to you. [More …](https://itnext.io/kubernetes-resource-statistics-e8247f92b45c)\n\n---\n\nIndex:\n\n- [Install](#install)\n    - [From binaries](#from-binaries)\n    - [From source](#from-source)\n    - [From Kubernetes](#from-kubernetes)\n- [Use](#use)\n- [Testing](e2e-test/)\n\n\n## Install\n\nIn order to use `krs` you must meet the following two prerequisites:\n\n1. `kubectl` must be [installed](https://kubernetes.io/docs/tasks/tools/install-kubectl/).\n1. Access to a Kubernetes cluster must be configured. \n\nHere are my test environments: a v1.9 cluster via OpenShift Online, a v1.10 cluster via AKS, and a v1.11 cluster via Minikube, all with a `kubectl`@v1.11 client-side, on macOS.\n\n### From binaries\n\nYou can download binaries for Linux, macOS, and Windows which are available [via the release page](https://github.com/mhausenblas/krs/releases/latest). To install from binary, for example, on a macOS system, do:\n\n```shell\n$ curl -L $(curl -s https://api.github.com/repos/mhausenblas/krs/releases/latest | grep macos | grep browser_download_url | cut -d : -f 2,3 | tr -d \\\") -o krs\n$ chmod +x krs\n$ sudo mv krs /usr/local/bin\n```\n\n### From source\n\nAssuming you've got Go in version 1.10 or above installed you can install `krs` from source like so:\n\n```shell\n$ go get -u github.com/mhausenblas/krs\n```\n\n### From Kubernetes\n\nYou can launch `krs` in Kubernetes using the `launch.sh` script as follows. The script will dynamically create the respective permissions for the namespace and run `krs` as a deployment.  \nSo, in a sense this is a self-test: create and watch a namespace `krs-test` and view the output like so:\n\n```shell\n$ kubectl create ns krs-test\nnamespace/krs-test created\n\n$ ./launch.sh krs-test\nserviceaccount/krs created\nclusterrole.rbac.authorization.k8s.io/resreader configured\nrolebinding.rbac.authorization.k8s.io/allowpodprobes created\ndeployment.apps/krs created\n\n$ kubectl -n krs-test logs -f $(kubectl -n krs-test get po -l=run=krs --output=jsonpath={.items[*].metadata.name})\n# HELP pods Number of pods in any state, for example running\n# TYPE pods gauge\npods{namespace=\"krs-test\"} 1\n# HELP deployments Number of deployments\n# TYPE deployments gauge\ndeployments{namespace=\"krs-test\"} 1\n# HELP services Number of services\n# TYPE services gauge\nservices{namespace=\"krs-test\"} 0\n...\n```\n\n## Use\n\n`krs` assumes that `kubectl` is installed and configured. It writes the OpenMetrics data to `stdout` which you can then redirect to a file or process further. \n\nFor example, to gathers stats of the `dev42` namespace and store the OpenMetrics formatted  stats in a file called `/tmp/krs/2018-10-05.om` as well as see the errors on screen (via `stdout`), do the following:\n\n```shell\n$ krs --namespace dev42 \u003e\u003e /tmp/krs/2018-10-05.om\n```\n\nIf you don't provide a namespace as the first argument, `krs` will watch the `default` namespace. Also, by default, the following resources are tracked: pods, deployments, and services.\n\nFor example, an excerpt of the [output](e2e-test/e2e-output.om) of the [end-to-end test](e2e-test/) looks as follows:\n\n```shell\n# HELP pods Number of pods in any state, for example running\n# TYPE pods gauge\npods{namespace=\"krs\"} 2\n# HELP deployments Number of deployments\n# TYPE deployments gauge\ndeployments{namespace=\"krs\"} 2\n# HELP services Number of services\n# TYPE services gauge\nservices{namespace=\"krs\"} 1\n# HELP pods Number of pods in any state, for example running\n# TYPE pods gauge\npods{namespace=\"krs\"} 2\n# HELP deployments Number of deployments\n# TYPE deployments gauge\ndeployments{namespace=\"krs\"} 2\n# HELP services Number of services\n# TYPE services gauge\nservices{namespace=\"krs\"} 1\n...\n```\n\nIf you, for example, want to track pods, stateful sets, and persistent volumes in the namespace `prod1337` you'd launch `krs` like so:\n\n```shell\n$ krs --namespace prod1337 --resources \"pods,sts,pv,pvc\"\n```\n\nThere are two environment variables that `krs` understands:\n\n- With `KRS_KUBECTL_BIN` you can define which `kubectl` binary `krs` will use. Note: under Windows this is required, for OpenShift, this is an option to use `oc` instead of `kubectl`.\n- With `KRS_VERBOSE` set (for example, to `true` but really any value does) you can get debug-level information, down to what `kubectl` call has been issued.\n\nTo do:\n\n- [ ] Improve [Make file](https://suva.sh/posts/well-documented-makefiles/)\n- [ ] Complete e2e testing\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhausenblas%2Fkrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmhausenblas%2Fkrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhausenblas%2Fkrs/lists"}