All Projects → learnk8s → Spring Boot K8s Hpa

learnk8s / Spring Boot K8s Hpa

Autoscaling Spring Boot with the Horizontal Pod Autoscaler and custom metrics on Kubernetes

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Spring Boot K8s Hpa

linode-k8s-autoscaler
Autoscaling utility for horizontally scaling Linodes in an LKE Cluster Node Pool based on memory or cpu usage
Stars: ✭ 27 (-89.2%)
Mutual labels:  docker-container, autoscaling
Springboot Starterkit
Starter Kit for Spring Boot based (REST APIs and WebMVC) micro services.
Stars: ✭ 596 (+138.4%)
Mutual labels:  spring-boot, docker-container
Ansible Windows Docker Springboot
Example project showing how to provision, deploy, run & orchestrate Spring Boot apps with Docker Windows Containers on Docker Windows native using Packer, Powershell, Vagrant & Ansible
Stars: ✭ 58 (-76.8%)
Mutual labels:  spring-boot, docker-container
Spring Boot Testing Strategies
Sample project demonstrating different Test Strategies that can be followed when using Spring Boot.
Stars: ✭ 233 (-6.8%)
Mutual labels:  spring-boot
Iotwifi
Raspberry Pi (arm) wifi configuration container. Configure and control wifi connectivity with a JSON based REST api.
Stars: ✭ 236 (-5.6%)
Mutual labels:  docker-container
Sqlhelper
SQL Tools ( Dialect, Pagination, DDL dump, UrlParser, SqlStatementParser, WallFilter, BatchExecutor for Test) based Java. it is easy to integration into any ORM frameworks
Stars: ✭ 242 (-3.2%)
Mutual labels:  spring-boot
Spring Boot Start Current
Spring Boot 脚手架 Mybatis Spring Security JWT 权限 Spring Cache + Redis
Stars: ✭ 246 (-1.6%)
Mutual labels:  spring-boot
Spring Security Pac4j
pac4j security library for Spring Security: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 231 (-7.6%)
Mutual labels:  spring-boot
21 Points
❤️ 21-Points Health is an app you can use to monitor your health.
Stars: ✭ 244 (-2.4%)
Mutual labels:  spring-boot
Schedule Job
基于Spring Boot + Quartz 的分布式任务调度系统
Stars: ✭ 239 (-4.4%)
Mutual labels:  spring-boot
Oauthserver
快速实现Spring Boot Oauth2授权服务,保护你的应用资源。
Stars: ✭ 238 (-4.8%)
Mutual labels:  spring-boot
Iot Harbor
reactor3实现的mqtt库
Stars: ✭ 234 (-6.4%)
Mutual labels:  spring-boot
Rocketmq Spring Boot Starter
Spring Boot starter for RocketMQ
Stars: ✭ 243 (-2.8%)
Mutual labels:  spring-boot
App Version
APP版本管理是一套多应用更新发版的管理平台。用户可以通过部署本管理系统,以实现对多APP的多平台多渠道上的版本管理。
Stars: ✭ 236 (-5.6%)
Mutual labels:  spring-boot
Fluentdocker
Commands, Services and Fluent API for docker, docker-compose & docker-machine, for win/mac/linux and native docker in c#
Stars: ✭ 245 (-2%)
Mutual labels:  docker-container
Crnk Framework
JSON API library for Java
Stars: ✭ 234 (-6.4%)
Mutual labels:  spring-boot
Ax Boot Framework
Full Stack Java Web Application Framework with Java & HTML5
Stars: ✭ 244 (-2.4%)
Mutual labels:  spring-boot
Spring Cloud Kubernetes
Kubernetes integration with Spring Cloud Discovery Client, Configuration, etc...
Stars: ✭ 2,894 (+1057.6%)
Mutual labels:  spring-boot
Microservices Platform
基于SpringBoot2.x、SpringCloud和SpringCloudAlibaba并采用前后端分离的企业级微服务多租户系统架构。并引入组件化的思想实现高内聚低耦合,项目代码简洁注释丰富上手容易,适合学习和企业中使用。真正实现了基于RBAC、jwt和oauth2的无状态统一权限认证的解决方案,面向互联网设计同时适合B端和C端用户,支持CI/CD多环境部署,并提供应用管理方便第三方系统接入;同时还集合各种微服务治理功能和监控功能。模块包括:企业级的认证系统、开发平台、应用监控、慢sql监控、统一日志、单点登录、Redis分布式高速缓存、配置中心、分布式任务调度、接口文档、代码生成等等。
Stars: ✭ 3,274 (+1209.6%)
Mutual labels:  spring-boot
Graphqlize
A Clojure & JVM library for developing GraphQL API instantly from Postgres and MySQL databases
Stars: ✭ 240 (-4%)
Mutual labels:  spring-boot

Autoscaling Spring Boot with the Horizontal Pod Autoscaler and custom metrics on Kubernetes

Prerequisites

You should have minikube installed.

You should start minikube with at least 4GB of RAM:

minikube start \
  --memory 4096 \
  --extra-config=controller-manager.horizontal-pod-autoscaler-upscale-delay=1m \
  --extra-config=controller-manager.horizontal-pod-autoscaler-downscale-delay=2m \
  --extra-config=controller-manager.horizontal-pod-autoscaler-sync-period=10s

If you're using a pre-existing minikube instance, you can resize the VM by destroying it an recreating it. Just adding the --memory 4096 won't have any effect.

You should install jq — a lightweight and flexible command-line JSON processor.

You can find more info about jq on the official website.

Installing Custom Metrics Api

Deploy the Metrics Server in the kube-system namespace:

kubectl create -f monitoring/metrics-server

After one minute the metric-server starts reporting CPU and memory usage for nodes and pods.

View nodes metrics:

kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes" | jq .

View pods metrics:

kubectl get --raw "/apis/metrics.k8s.io/v1beta1/pods" | jq .

Create the monitoring namespace:

kubectl create -f monitoring/namespaces.yaml

Deploy Prometheus v2 in the monitoring namespace:

kubectl create -f monitoring/prometheus

Deploy the Prometheus custom metrics API adapter:

kubectl create -f monitoring/custom-metrics-api

List the custom metrics provided by Prometheus:

kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1" | jq .

Package the application

You package the application as a container with:

eval $(minikube docker-env)
docker build -t spring-boot-hpa .

Deploying the application

Deploy the application in Kubernetes with:

kubectl create -f kube/deployment

You can visit the application at http://minkube_ip:32000

(Find the minikube ip address via minikube ip)

You can post messages to the queue by via http://minkube_ip:32000/submit?quantity=2

You should be able to see the number of pending messages from http://minkube_ip:32000/metrics and from the custom metrics endpoint:

kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/default/pods/*/messages" | jq .

Autoscaling workers

You can scale the application in proportion to the number of messages in the queue with the Horizontal Pod Autoscaler. You can deploy the HPA with:

kubectl create -f kube/hpa.yaml

You can send more traffic to the application with:

while true; do curl -d "quantity=1" -X POST http://minkube_ip:32000/submit ; sleep 4; done

When the application can't cope with the number of incoming messages, the autoscaler increases the number of pods in 3 minute intervals.

You may need to wait three minutes before you can see more pods joining the deployment with:

kubectl get pods

The autoscaler will remove pods from the deployment every 5 minutes.

You can inspect the event and triggers in the HPA with:

kubectl get hpa spring-boot-hpa

Notes

The configuration for metrics and metrics server is configured to run on minikube only.

You won't be able to run the same YAML files for metrics and custom metrics server on your cluster or EKS, GKE, AKS, etc.

Also, there are secrets checked in the repository to deploy the Prometheus adapter.

In production, you should generate your own secrets and (possibly) not check them into version control.

If you wish to run metrics and custom metrics server in production, you should check out the following resources:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].