{"id":28745449,"url":"https://github.com/bphun/kubernetesautoscaling","last_synced_at":"2026-04-12T12:43:48.071Z","repository":{"id":48499800,"uuid":"297883103","full_name":"bphun/KubernetesAutoscaling","owner":"bphun","description":"K8s Horizontal Auto Scaling 🏎💨 ","archived":false,"fork":false,"pushed_at":"2022-03-21T19:23:58.000Z","size":54786,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-19T06:43:50.152Z","etag":null,"topics":["cadvisor","cumulative-sum","go","k8s","k8s-cluster","kubernetes","metallb","mongodb","nginx","promethues","statsd"],"latest_commit_sha":null,"homepage":"","language":"Go","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/bphun.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}},"created_at":"2020-09-23T07:05:00.000Z","updated_at":"2021-08-29T03:04:16.000Z","dependencies_parsed_at":"2022-08-24T08:41:07.868Z","dependency_job_id":null,"html_url":"https://github.com/bphun/KubernetesAutoscaling","commit_stats":null,"previous_names":["bphun/k8sautoscaling"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bphun/KubernetesAutoscaling","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bphun%2FKubernetesAutoscaling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bphun%2FKubernetesAutoscaling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bphun%2FKubernetesAutoscaling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bphun%2FKubernetesAutoscaling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bphun","download_url":"https://codeload.github.com/bphun/KubernetesAutoscaling/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bphun%2FKubernetesAutoscaling/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260166312,"owners_count":22968639,"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":["cadvisor","cumulative-sum","go","k8s","k8s-cluster","kubernetes","metallb","mongodb","nginx","promethues","statsd"],"created_at":"2025-06-16T13:11:25.399Z","updated_at":"2026-04-12T12:43:48.027Z","avatar_url":"https://github.com/bphun.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kubernetes Autoscaling\n\nThis is a Kubernetes cluster that horizontally scales a Golang REST API based on how many requests per second (RPS) the API is processing. Currently, the `HorizontalPodAutoscaler` (HPA) threshold is set to 3000 RPS. The API simply takes a JSON with an array and returns the cumulative sum of the array as a JSON response.\n\n## Running the Cluster\nI ran the cluster on a Ubuntu 20.04.1 system with Kubernetes bootstrapped using kubeadm 1.20.1 but you can boostrap the cluster however you want. \n\nTo start the services, initialize the Kubernetes cluster then run the following commands.\n```\ngit clone https://github.com/bphun/k8AutoScalingTest.git\ncd k8AutoScalingTest\n./startServices.sh\n```\n\n## Accessing the cluster\nRun `kubectl --namespace default get services -o wide -w nginx-ingress-ingress-nginx-controller`. You will see a similar output:\n```\nNAME                                     TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)                      AGE   SELECTOR\nnginx-ingress-ingress-nginx-controller   LoadBalancer   10.110.227.68   203.0.113.10   80:31757/TCP,443:31344/TCP   29s   app.kubernetes.io/component=controller,app.kubernetes.io/instan\n```\n\nThis will give you the external IP address of the Nginx ingress controller (203.0.113.10 in this example). You can use the external IP address to access the API from a node within the Kubernetes cluster by running:\n```\ncurl -X POST --data '{\"arr\": [1, 2, 3, 4, 5, 5, 6, 7, 8, 10], \"mode\": \"man\"}' http://$EXTERNAL_IP/api/ | jq\n```\n\nIn addition to the API service, the Prometheus service can be accessed at `http://$EXTERNAL_IP/prometheus/` and a Grafana dashboard can be accessed at `http://$EXTERNAL_IP/grafana_dashboard/`. The required dashboards are available as JSON files you can import in the `grafana/` directory.\n\nIf you want to access the API service from your LAN, you can use an SSH tunnel like so:\n```\nssh -L $MASTER_NODE_IP:8000:$EXTERNAL_IP:80 $USER@$MASTER_NODE_IP\n```\nThis will allow you to access the API service from any computer in your LAN through `$MASTER_NODE_IP:8000`\n\n## Load testing the API\nI used [Hey](https://github.com/rakyll/hey) to load test the API, which can trigger the Kubernetes HPA to scale the API services. To run Hey, use the following command:\n```\nhey -m POST -H \"Content-Type: application/json\" -n 10000 -c 100 -D api/input.json http://$EXTERNAL_IP/api/ \n```\nThe `-n` argument is the number of requests that will be sent and `-c` is the number of concurrent requests that will be sent by Hey. Increasing `-n` will trigger the HPA to horizontally scale the API service.\n\nIf you want to change the HPA threshold, change the `averageValue` value in `k8s/horizontal-autoscalers/api.yaml` and reload the services using `./startServices.sh`\n\n## Update: 04/03/2021\n* Added MongoDB database to store request history. Request history may be used in future for custom data aggregation UI\n* Implement gRPC API to allow \"Cum-Sum-API\" to store requests in MongoDB database\n* Use [Jaeger](https://www.jaegertracing.io) to add distributed tracing support\n* Add ElasticSearch database to store Jaeger spans\n\n### API Architecture\n```\n|--------|    HTTP    |---------------|    gRPC    |------------------|   TCP/IP Socket    |-----------|\n|  User  |  -------\u003e  |  Cum-Sum-API  |  -------\u003e  |  TransactionAPI  |  ---------------\u003e  |  MongoDB  |  \n|--------|            |---------------|            |------------------|                    |-----------|\n```\n\n### Distributed tracing pipeline:\n```\n                                                                              |-------------|\n                                                                              |  Jaeger UI  |\n                                                                              |-------------|\n\n                                                                                    |\n                                                                                    |\n                                                                                    V\n\n  |------------|        |----------------|      |--------------------|      |-----------------|\n  |  REST API  |  ---\u003e  |  Jaeger Agent  | ---\u003e |  Jaeger Collector  | ---\u003e |  Elasticsearch  |\n  |------------|        |----------------|      |--------------------|      |-----------------|\n```\n\n## Future features\n* I already have Nginx exporter setup so I would like to add a HPA controller for that service\n* Add a VerticalPodAutoscaler (VPA) for the API and Nginx services using Node exporter\n* ~~Add another \"Microservice\" so I can test out distributed tracing frameworks like OpenTracing~~ (*Update: 04/03/2021*)\n* Add improved logging to the Go API service","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbphun%2Fkubernetesautoscaling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbphun%2Fkubernetesautoscaling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbphun%2Fkubernetesautoscaling/lists"}