{"id":15482977,"url":"https://github.com/devth/k8s-labeler","last_synced_at":"2025-04-22T16:49:05.896Z","repository":{"id":136771229,"uuid":"88365944","full_name":"devth/k8s-labeler","owner":"devth","description":"⚓️ Apply labels to Kubernetes pods on startup","archived":false,"fork":false,"pushed_at":"2017-04-15T19:00:24.000Z","size":5,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-17T07:17:01.779Z","etag":null,"topics":["docker","kubernetes","metadata"],"latest_commit_sha":null,"homepage":"https://hub.docker.com/r/devth/k8s-labeler/","language":"Shell","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/devth.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,"zenodo":null}},"created_at":"2017-04-15T18:17:02.000Z","updated_at":"2020-11-26T09:57:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"2b598461-8712-4561-b909-02058a029ade","html_url":"https://github.com/devth/k8s-labeler","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/devth%2Fk8s-labeler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devth%2Fk8s-labeler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devth%2Fk8s-labeler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devth%2Fk8s-labeler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devth","download_url":"https://codeload.github.com/devth/k8s-labeler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250281944,"owners_count":21404892,"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","metadata"],"created_at":"2024-10-02T05:10:27.693Z","updated_at":"2025-04-22T16:49:05.888Z","avatar_url":"https://github.com/devth.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# k8s-labeler\n\n[![Code Climate](https://img.shields.io/codeclimate/issues/github/devth/k8s-labeler.svg?style=flat-square)](https://codeclimate.com/github/devth/k8s-labeler)\n[![Docker Automated build](https://img.shields.io/docker/automated/devth/k8s-labeler.svg?style=flat-square)](https://hub.docker.com/r/devth/k8s-labeler/)\n\nIntended to be used as an init container for a Kubernetes pod.\n\n## Usage\n\nThe `KUBE_NAMESPACE` env var is **required**. This must match the namespace of\nthe pod you're running in.\n\nAny env vars containing `KUBE_LABEL_` will be applied to the pod as labels via\nthe API. For example:\n\n```bash\nKUBE_LABEL_hostname=foobar\n```\n\nWould result in a label `hostname: foobar` on the pod.\n\nThis can be useful for setting properties from the [Downward\nAPI](https://kubernetes.io/docs/tasks/configure-pod-container/environment-variable-expose-pod-information/)\nas labels (e.g. exposing a unique label for each pod in a stateful).\n\n## Run locally\n\n```bash\n./run.sh\n```\n\n## Kubernetes example\n\nThis init container sets a `hostname` label equal to the pod's name:\n\n```yaml\ninitContainers:\n  - image: devth/k8s-labeler\n    name: labeler\n    env:\n      - name: KUBE_NAMESPACE\n        valueFrom:\n          fieldRef:\n            fieldPath: metadata.namespace\n      - name: KUBE_LABEL_hostname\n        valueFrom:\n          fieldRef:\n            fieldPath: metadata.name\n```\n\nInspect the pod with:\n\n```bash\nkubectl get pod -l app=myapp --show-labels\n\nNAME                     READY     STATUS    RESTARTS   AGE       LABELS\nmyapp-2768796676-c702s   2/2       Running   0          25m       app=myapp,hostname=myapp-2768796676-c702s,pod-template-hash=2768796676\n```\n\nAnd notice that the `hostname=myapp-2768796676-c702s` label is present.\n\n## License\n\nCopyright 2017 Trevor C. Hartman\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevth%2Fk8s-labeler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevth%2Fk8s-labeler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevth%2Fk8s-labeler/lists"}