Utilizing high availability scalability high performance using kubernetes Ingress Nginx And Hpa
Published:
the steps:
#i use docker desktop that acts as a cluster: to act as a handler for public domain of the app)
load balancer (cluster) -> ingress <-> hpa <-> the application in pods
# hpa: horizontal pod autoscaling
- Install the app you want to scale
- Make the Dockerfile
- Build it, for example:
docker build -t shohiebsense/network-traffic-monitor-8085:latest .
- Push it to harbor/registry or whatever, you can build private harbor/registry tho but i use docker hub https://hub.docker.com/
docker push shohiebsense/network-traffic-monitor-8085:latest
- Install the metrics, tools to monitor the hpa.
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
- Check if metrics installed
kubectl get deployment metrics-server -n kube-system
6a. log if it’s running
kubectl logs -n kube-system deployment/metrics-server
- Apply the deployment, load_balancer, and ingress (
.yaml
file).
kubectl apply -f deployment.yaml
kubectl apply -f ingress.yaml
kubectl apply -f load_balancer.yaml
- You can use bash script or yaml file to do autoscaling
kubectl autoscale deployment network-traffic-monitor-deployment-8085 --cpu-percent=3 --min=2 --max=5
- using
.yaml
apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: network-traffic-monitor-hpa-8085 spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: network-traffic-monitor-deployment-8085 minReplicas: 2 maxReplicas: 7 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 3 # Lower the CPU target to 3%, it's small i know, to see the scaling by generating new pods in action
- Test your app, I use locust
- Monitor your pods, can use
watch
ork9s
watch kubectl get pods -o wide
- https://k9scli.io/
Repo:
https://github.com/shohiebsense/kubernetes_8085-autoscaler-hpa-ingress-nginx