{"id":13839382,"url":"https://github.com/16Bitt/kubemem","last_synced_at":"2025-07-11T03:32:01.310Z","repository":{"id":78436597,"uuid":"210243502","full_name":"16Bitt/kubemem","owner":"16Bitt","description":"A small binary to probe memory usage in a kubernetes pod","archived":false,"fork":false,"pushed_at":"2024-05-22T21:24:07.000Z","size":10,"stargazers_count":43,"open_issues_count":5,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-21T04:31:00.941Z","etag":null,"topics":["docker","kubernetes"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/16Bitt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-09-23T01:53:38.000Z","updated_at":"2024-09-27T00:43:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"d91c894b-7e01-4932-aa07-2925714d1558","html_url":"https://github.com/16Bitt/kubemem","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/16Bitt/kubemem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/16Bitt%2Fkubemem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/16Bitt%2Fkubemem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/16Bitt%2Fkubemem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/16Bitt%2Fkubemem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/16Bitt","download_url":"https://codeload.github.com/16Bitt/kubemem/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/16Bitt%2Fkubemem/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264721331,"owners_count":23653920,"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":["docker","kubernetes"],"created_at":"2024-08-04T17:00:21.256Z","updated_at":"2025-07-11T03:32:01.066Z","avatar_url":"https://github.com/16Bitt.png","language":"C","funding_links":[],"categories":["Observability"],"sub_categories":[],"readme":"# Kubemem\nKubemem is a small binary intended to be used as a liveness probe inside of your\nKubernetes applications that will allow graceful failure when the memory starts\nto get too high. As it is not a shell script, it should be fast and portable for\nyour containers.\n\n\u003e Kubernetes already stops containers from using too much memory! What's the point?\n\nKubernetes [does not offer a way](https://github.com/kubernetes/kubernetes/issues/40157)\nto add a graceful handler for OOM killed containers currently, so this is a nice medium.\nWhere I work, we have long running Sidekiq jobs with pods that should try to exit\ngracefully but are instead immediately trashed once they hit the memory threshold.\n\n## How it works\n\nKubemem has three options:\n\n* a warning percentage: When your RAM usage hits this threshold, kubemem will log the warning\n* a failure percentage: When your RAM usage hits this threshold, kubemem will exit with\n  a non-zero exit code, causing kubernetes to trigger a graceful kill of your pod.\n* a logfile path\n\nKubemem will use the cgroup filesystem to get memory info, and then use your options\nto either log or fail.\n\n## Usage\n\nFirst, pick the tag you'd like to use:\n\n* glibc: Debian-based builds\n* musl: This is what you'll select for alpine\n\nSimply add this container as another stage in your build:\n\n```Dockerfile\nFROM sixteenbitt/kubemem:glibc AS kubemem\n\n# Do your normal build\n\nCOPY --from=kubemem /bin/kubemem /bin/kubemem\n```\n\nAnd then add a probe to your deployment:\n\n```yaml\n    livenessProbe:\n      exec:\n        command:\n        - kubemem\n        - --failure\n        - \"95\" # Fail at 95% memory\n        - --warning\n        - \"85\" # Warn at 85% or greater memory usage\n        - --logfile\n        - /proc/1/fd/1 # Write to PID 1's output, allowing logging\n      initialDelaySeconds: 5\n      periodSeconds: 5\n```\n\nIf you'd like to play around with it, you can run it from the command line:\n\n```sh\ndocker run sixteenbitt/kubemem:musl kubemem --warning 80 --failure 90\n```\n\n## A note about logging\n\nKubernetes currently aggregates probe logs in kubelet, and only if logging is set to\nverbosity level 4 or higher. See [this issue](https://github.com/16Bitt/kubemem/issues/1)\nfor more info about how kubernetes handles probe logs if you'd like to capture them.\n\nAs a workaround, set your logfile parameter to `/proc/1/fd/1` to write to the containers\nPID 1 stdout for logging.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F16Bitt%2Fkubemem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F16Bitt%2Fkubemem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F16Bitt%2Fkubemem/lists"}