{"id":21447860,"url":"https://github.com/hsbc/cost-manager","last_synced_at":"2025-07-14T20:30:49.185Z","repository":{"id":210049171,"uuid":"725566300","full_name":"hsbc/cost-manager","owner":"hsbc","description":"Automate Kubernetes cluster cost optimisations","archived":false,"fork":false,"pushed_at":"2024-06-17T09:20:37.000Z","size":209,"stargazers_count":12,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-21T15:47:45.248Z","etag":null,"topics":["cost-optimization","finops","kubernetes"],"latest_commit_sha":null,"homepage":"","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/hsbc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-30T12:16:57.000Z","updated_at":"2024-02-19T09:01:44.000Z","dependencies_parsed_at":"2024-06-21T14:25:06.238Z","dependency_job_id":"62ec2bf0-2b73-481b-8f53-77933d39a959","html_url":"https://github.com/hsbc/cost-manager","commit_stats":null,"previous_names":["hsbc/cost-manager"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsbc%2Fcost-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsbc%2Fcost-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsbc%2Fcost-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsbc%2Fcost-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hsbc","download_url":"https://codeload.github.com/hsbc/cost-manager/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225994783,"owners_count":17556830,"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":["cost-optimization","finops","kubernetes"],"created_at":"2024-11-23T03:12:26.938Z","updated_at":"2024-11-23T03:12:27.403Z","avatar_url":"https://github.com/hsbc.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# cost-manager\n\ncost-manager is a Kubernetes controller manager that manages\n[controllers](https://kubernetes.io/docs/concepts/architecture/controller/) to automate cost\noptimisations.\n\n## Controllers\n\nHere we provide details of the various controllers supported by cost-manager.\n\n### spot-migrator\n\nSpot VMs are unused compute capacity that many cloud providers support access to at significantly\nreduced costs (e.g. on GCP spot VMs provide a [60-91%\ndiscount](https://cloud.google.com/compute/docs/instances/spot#pricing)). Since spot VM availability\ncan fluctuate it is common to configure workloads to be able to run on spot VMs but to allow\nfallback to on-demand VMs if spot VMs are unavailable. However, even if spot VMs are available, if\nworkloads are already running on on-demand VMs there is no reason for them to migrate.\n\nTo improve spot VM utilisation, [spot-migrator](./pkg/controller/spot_migrator.go) periodically\nattempts to migrate workloads from on-demand VMs to spot VMs by draining on-demand Nodes to force\ncluster scale up, relying on the fact that the cluster autoscaler [attempts to expand the least\nexpensive possible node\ngroup](https://github.com/kubernetes/autoscaler/blob/600cda52cf764a1f08b06fc8cc29b1ef95f13c76/cluster-autoscaler/proposals/pricing.md),\ntaking into account the reduced cost of spot VMs. If an on-demand VM is added to the cluster then\nspot-migrator assumes that there are currently no more spot VMs available and waits for the next\nmigration attempt (currently every hour) however if no on-demand VMs were added then spot-migrator\ncontinues to drain on-demand VMs until there are no more left in the cluster (and all workloads are\nrunning on spot VMs). Node draining respects\n[PodDisruptionBudgets](https://kubernetes.io/docs/concepts/workloads/pods/disruptions/) to ensure\nthat workloads are migrated whilst maintaining desired levels of availability.\n\nCurrently only [GKE\nStandard](https://cloud.google.com/kubernetes-engine/docs/concepts/types-of-clusters) clusters are\nsupported. To allow spot-migrator to migrate workloads to spot VMs with fallback to on-demand VMs\nyour cluster must be running at least one on-demand node pool and at least one spot node pool.\n\n```yaml\napiVersion: cost-manager.io/v1alpha1\nkind: CostManagerConfiguration\ncontrollers:\n- spot-migrator\ncloudProvider:\n  name: gcp\n```\n\n### pod-safe-to-evict-annotator\n\nCertain [types of\nPods](https://github.com/kubernetes/autoscaler/blob/bb72e46cb0697090683969c932a38afec9089978/cluster-autoscaler/FAQ.md#what-types-of-pods-can-prevent-ca-from-removing-a-node)\ncan prevent the cluster autoscaler from removing a Node (e.g. Pods in the kube-system Namespace that\ndo not have a PodDisruptionBudget) leading to more Nodes in the cluster than necessary. This can be\nparticularly problematic for workloads that cluster operators are not in control of and can have a\nhigh number of replicas, such as kube-dns or the [Konnectivity\nagent](https://kubernetes.io/docs/tasks/extend-kubernetes/setup-konnectivity/), which are typically\ninstalled by cloud providers.\n\nTo allow the cluster autoscaler to evict all Pods that have not been explicitly marked as unsafe for\neviction, [pod-safe-to-evict-annotator](./pkg/controller/pod_safe_to_evict_annotator.go) adds the\n`cluster-autoscaler.kubernetes.io/safe-to-evict: \"true\"` annotation to all Pods that have not\nalready been annotated; note that PodDisruptionBudgets can still be used to maintain desired levels\nof availability.\n\n```yaml\napiVersion: cost-manager.io/v1alpha1\nkind: CostManagerConfiguration\ncontrollers:\n- pod-safe-to-evict-annotator\npodSafeToEvictAnnotator:\n  namespaceSelector:\n    matchExpressions:\n    - key: kubernetes.io/metadata.name\n      operator: In\n      values:\n      - kube-system\n```\n\n## Installation\n\nYou can install cost-manager into a GKE cluster with [Workload\nIdentity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity) enabled as\nfollows:\n\n```sh\nNAMESPACE=\"cost-manager\"\nkubectl get namespace \"$NAMESPACE\" || kubectl create namespace \"$NAMESPACE\"\nLATEST_RELEASE_TAG=\"$(curl -s https://api.github.com/repos/hsbc/cost-manager/releases/latest | jq -r .tag_name)\"\n# GCP service account bound to the roles/compute.instanceAdmin role\nGCP_SERVICE_ACCOUNT_EMAIL_ADDRESS=\"cost-manager@example.iam.gserviceaccount.com\"\ncat \u003c\u003cEOF \u003e values.yaml\nimage:\n  tag: $LATEST_RELEASE_TAG\nconfig:\n  apiVersion: cost-manager.io/v1alpha1\n  kind: CostManagerConfiguration\n  controllers:\n  - spot-migrator\n  - pod-safe-to-evict-annotator\n  cloudProvider:\n    name: gcp\n  podSafeToEvictAnnotator:\n    namespaceSelector:\n      matchExpressions:\n      - key: kubernetes.io/metadata.name\n        operator: In\n        values:\n        - kube-system\nserviceAccount:\n  annotations:\n    iam.gke.io/gcp-service-account: $GCP_SERVICE_ACCOUNT_EMAIL_ADDRESS\nEOF\nhelm template ./charts/cost-manager -n \"$NAMESPACE\" -f values.yaml | kubectl apply -f -\n```\n\n## Testing\n\nBuild Docker image and run E2E tests using [kind](https://github.com/kubernetes-sigs/kind):\n\n```sh\nmake image e2e\n```\n\n## Roadmap\n\nSee [ROADMAP.md](ROADMAP.md) for details.\n\n## Contributing\n\nContributions are greatly appreciated. The project follows the typical GitHub pull request model.\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsbc%2Fcost-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhsbc%2Fcost-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsbc%2Fcost-manager/lists"}