Skip to content

lucatiozzo91/node-flask-autoscaling-k8s

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

k8s Http Autoscaling Service on Load Metrics Node/Flask

In that example you can find a simple way to deploy a service in node or flask that export self load metrics on prometheus. You can also find the way to use that metrics as target for the relative hpa controller. I'v also added the support of terraform for infrastracturing and HTTPS support.

The example is tested on GKE

Tecnologies

  • K8S
  • Helm
  • Terraform
  • PrometheusOperator
  • Grafana
  • Flask
  • Node
  • Go
  • Let's Encrypt

Project Structure:

  • Ingress Folder: ingress yaml and SSL config file
  • k8s Folder: yaml file for the 3: service, deployments and hpa
  • Monitoring Folder: conf for prometheus prometheus-adapter and grafana dashboard
  • rs Folder: source code for the 3 http service
  • Terraform Folder: terraform config file

Flask Metrics

For expose the prometheus load metrics i'v use the Prometheus Flask exporter starting a secondary web server that really collect the metrics and proxying the /metrics request from main server to metrics server.

Node Metrics

Expose prometheus metrics in node is more simple than flask, we can use the express-prometheus-bundle library and simple add some annotation on wich endpoint we won't expose.

Collect Metrics

Collect metrics with prometheus operator is simple we can just add a ServiceMonitor that target our metrics enpoint and the prometheus server will start collect data. You can find an exaple of a ServiceMonitor for product server in monitor folder. Make attention to matchLabels parameters and endpoint parameters.

Hpa on Custom Metrics

Dashboard

HTTPS