{"id":23469886,"url":"https://github.com/vapor-ware/k8s-elector","last_synced_at":"2025-04-14T16:33:58.802Z","repository":{"id":45444716,"uuid":"183640272","full_name":"vapor-ware/k8s-elector","owner":"vapor-ware","description":"A minimal kubernetes-native sidecar elector service.","archived":false,"fork":false,"pushed_at":"2022-08-17T15:47:04.000Z","size":72,"stargazers_count":10,"open_issues_count":3,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-21T22:03:10.219Z","etag":null,"topics":["election","kubernetes","sidecar"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vapor-ware.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}},"created_at":"2019-04-26T14:11:23.000Z","updated_at":"2024-09-14T02:34:06.000Z","dependencies_parsed_at":"2022-09-10T02:22:35.928Z","dependency_job_id":null,"html_url":"https://github.com/vapor-ware/k8s-elector","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vapor-ware%2Fk8s-elector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vapor-ware%2Fk8s-elector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vapor-ware%2Fk8s-elector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vapor-ware%2Fk8s-elector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vapor-ware","download_url":"https://codeload.github.com/vapor-ware/k8s-elector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248916711,"owners_count":21182852,"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":["election","kubernetes","sidecar"],"created_at":"2024-12-24T15:36:46.170Z","updated_at":"2025-04-14T16:33:58.760Z","avatar_url":"https://github.com/vapor-ware.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# k8s-elector\nk8s-elector is a minimal Kubernetes-native sidecar elector service, allowing you to\nperform simple leader election within your Kubernetes deployment. \n\nInternally, it uses `\"k8s.io/client-go/tools/leaderelection\"` to run the election.\n\n## Usage\nThe k8s-elector is intended to be run as a sidecar to other services to provide\nthem leader election capabilities, but it can run on its own as well. For an example,\nyou can run just the elector containers with\n\n```\n$ kubectl run k8s-elector --image=vaporio/k8s-elector --replicas=3 -- -election=example\n``` \n\n\u003e **Note** By default, k8s-elector tries to use a Kubernetes LeaseLock. If running a\n\u003e version of Kubernetes which does not support this, you can change the lock type with\n\u003e the `-lock-type` flag. (valid values: leases, endpoints, configmaps)\n\nThis will run 3 instances of the k8s-elector. You can observe their logs to verify\na leader is chosen among them.\n\nLooking through the logs for leadership is not tenable for a deployment to identify\nleadership. k8s-elector exposes a basic HTTP API to provide leadership status information.\nYou can enable and conifgure it with the `-http` flag.\n\n```\n$ kubectl run k8s-elector --image=vaporio/k8s-elector --replicas=3 -- -election=example -lock-type=configmaps -http=0.0.0.0:5002\n``` \n\nYou can look through the logs to see a leader was elected and you can verify [from within\nthe cluster](https://kubernetes.io/docs/tasks/debug-application-cluster/debug-service/#running-commands-in-a-pod)\nthat each pod reports its leadership status correctly.\n\n```console\n/ # curl 10.1.0.180:5002/\n{\"is_leader\":false,\"leader\":\"k8s-elector-74c54b485f-hgf9z\",\"node\":\"k8s-elector-74c54b485f-564ht\",\"timestamp\":\"2019-05-02T18:28:51Z\"}\n/ # curl 10.1.0.181:5002/\n{\"is_leader\":false,\"leader\":\"k8s-elector-74c54b485f-hgf9z\",\"node\":\"k8s-elector-74c54b485f-qztgk\",\"timestamp\":\"2019-05-02T18:29:21Z\"}\n/ # curl 10.1.0.179:5002/\n{\"is_leader\":true,\"leader\":\"k8s-elector-74c54b485f-hgf9z\",\"node\":\"k8s-elector-74c54b485f-hgf9z\",\"timestamp\":\"2019-05-02T18:29:26Z\"}\n```\n\nAs the above run command specified the lock type as \"configmaps\", you should also expect to\nsee a ConfigMap with the same name as the election.\n\n```\n$ kubectl get cm\nNAME      DATA      AGE\nexample   0         21m\n```\n\n## Configuration\nFor a full list of configuration options, you can run the elector with the `-h` flags. These\nwill include both the flags for the elector itself as well as flags for configuring logging.\n\n```\nUsage of ./elector:\n  -election string\n    \tThe name of the election. This is required.\n  -http string\n    \tThe HTTP address (host:port) which leader state will be reported on.\n  -id string\n    \tThe ID of the election participant. If not set, the hostname, as reported by the kernel, is used.\n  -kubeconfig string\n    \tThe kubeconfig file to use. If not set, in-cluster config will be used.\n  -lock-type string\n    \tThe type of Kubernetes object to use for the lock (leases, endpoints, configmaps) (default \"leases\")\n  -namespace string\n    \tThe Kubernetes namespace to run the election in. If not set, elections will run in the default namespace. (default \"default\")\n  -ttl duration\n    \tThe TTL for the election. (default 10s)\n```\n\n## API\nWhen enabled, the exposed HTTP API consists of a single endpoint at the URL root.\n\n### `/`\n\nMethod: `GET`\n\n#### Example response:\n```json\n{\n  \"is_leader\": false,\n  \"leader\": \"k8s-elector-74c54b485f-hgf9z\",\n  \"node\": \"k8s-elector-74c54b485f-564ht\",\n  \"timestamp\": \"2019-05-02T18:28:51Z\"\n}\n```\n\n#### Fields\n\n| Field | Description |\n| :---- | :---------- |\n| *is_leader* | A boolean describing whether the node being queried is the leader node. |\n| *leader* | The ID of the node which is currently the leader. |\n| *node* | The ID of the node being queried for leadership status. |\n| *timestamp* | The RFC3339-formatted UTC timestamp for when the response was returned. |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvapor-ware%2Fk8s-elector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvapor-ware%2Fk8s-elector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvapor-ware%2Fk8s-elector/lists"}