Giter Site home page Giter Site logo

somrajroy / opensourceproject-kubernetes-hpa-minikube Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 46 KB

Horizontal Pod Autoscaling (HPA) in Kubernetes for cloud cost optimization. Client Demos

hpa kubenetes-deployment kubernetes kubernetes-cluster kubernetes-hpa metrics-server minikube minikube-cluster autoscaling cloud-costs

opensourceproject-kubernetes-hpa-minikube's Introduction

Kubernetes-Horizental Pod Autoscaler/Autoscaling

Horizontal Pod Autoscaling in Kubernetes (minikube). Ideally HPA needs to be done in EKS/AKS with CA which will be done later.

  • In Kubernetes, a HorizontalPodAutoscaler automatically updates a workload resource (such as a Deployment or StatefulSet), with the aim of automatically scaling the workload to match demand.
  • Kubernetes uses the horizontal pod autoscaler (HPA) to monitor the resource demand and automatically scale the number of replicas.
  • This method can also be referred to as scaling out. In this method, Kubernetes allows DevOps engineer, SRE, or cluster admin to increase or decrease the number of pods automatically based upon application resource usage. The below diagrams explains the process.

    image

    image

Steps for HPA demo.

  • Enable the metrics-server addon for minikube by running the below command (Confirmation will be like the image below). The metrics-server fetches resource metrics from the kubelets and exposes them in the Kubernetes API server through the Metrics API for use by the HPA and VPA. By default, the horizontal pod autoscaler checks the Metrics API every 15 seconds for any required changes in replica count, but the Metrics API retrieves data from the Kubelet every 60 seconds. Effectively, the HPA is updated every 60 seconds. When changes are required, the number of replicas is increased or decreased accordingly.
    $ minikube addons enable metrics-server
    image
  • It’s helpful to use lower collection intervals of 1 minute and 10 seconds to see more immediate action.
    $ minikube start — extra-config=controller-manager.horizontal-pod-autoscaler-upscale-delay=1m — extra-config=controller-manager.horizontal-pod-autoscaler-downscale-delay=1m — extra-config=controller-manager.horizontal-pod-autoscaler-sync-period=10s — extra-config=controller-manager.horizontal-pod-autoscaler-downscale-stabilization=1m
  • Download and deploy the manifest HPA.yaml
    $ kubectl apply -f HPA.yaml
  • Check the pod and service created. Wait for the pod to be in running state
    $ kubectl get pod,svc
    image
  • Create the HorizontalPodAutoscaler.
    $ kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=5
  • Check the current status of the newly-made HorizontalPodAutoscaler, by running below command. The output should be similar to the image.
    $ kubectl get hpa
    image
  • Check how the autoscaler reacts to increased load. To do this, start a different Pod to act as a client. The container within the client Pod runs in an infinite loop, sending queries to the php-apache service. Open a new window and run the below command.
    $ kubectl run -i --tty load-generator --rm --image=busybox:1.28 --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"
  • In main window run the below command. (type Ctrl+C to end the watch). Within a minute or so, the terminal should display the higher CPU load like the image below
    $ kubectl get hpa php-apache --watch
    image
  • After the load increased the deployment size will also increase and can be seen by running below command.
    $ kubectl get deployment php-apache
    image
  • After few moments if the pods are checked then all 5 pods will be running. (replica count matching the figure from the HorizontalPodAutoscaler)
    $ kubectl get pods
    image
  • Stoping the load - In the terminal where the Pod that runs a busybox image, terminate the load generation by typing Control + C.
  • After few mins if we check the deployment and replicas then we can see only 1 pod with 1 replica.

Further references

opensourceproject-kubernetes-hpa-minikube's People

Contributors

somrajroy avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.