Autoscaling during rolling update

A Deployment may handle its underlying ReplicaSets via performing a rolling update. A HorizontalPodAutoscaler (HPA) is attached to a deployment when autoscaling has been set up for it. With its replicas field, which it modifies based on resource use, the HPA controls the number of replicas utilized for the deployment.

During a rolling update:

  • The deployment controller makes sure that the total number of pods from all old and new ReplicaSets involved matches the amount that is planned.
  • The HPA keepsmakes an eye on events and adjusts the overall amount of replicas as needed.

The scenario differs substantially for StatefulSets. Without the use of a ReplicaSet or similar intermediate resource, StatefulSets directly keep their pods. When performing a rolling update on an autoscaled StatefulSet:

  • Each pod is handled directly through the StatefulSet controller.
  • The number of pods that a StatefulSet maintains is impacted directly by the HPA’s modification of the StatefulSet’s replica count.

Container resource metrics

Container resource metrics are used by Kubernetes to track and control how much resource every container in a cluster uses. These metrics aid to make sure resources are used effectively and that initiatives function effectively. CPU and memory use are significant metrics that are often used for autoscaling and performance monitoring. A summary of Kubernetes’ container resource metrics is given below:

Key Metrics

  1. CPU Usage:
    • Measured in millicores (m): 1000m = 1 CPU core.
    • Usage: The amount of CPU time the the container consumes.
    • Limit: The maximum amount of CPU resources that may be utilized by the container.
    • Request: The smallest amount of CPU resources that the container gets is guaranteed.
  2. Memory Usage:
    • Measured in bytes (B), kilobytes (Ki), megabytes (Mi), etc..
    • Usage: The amount of RAM which the container utilizes at this point in time.
    • Limit: The greatest quantity of RAM that is permitted to used by the container.
    • Request: The smallest amount of memory that the container will always possess.
  • Resource Requests and Limits: You may set resource requests and limitations when defining a container in a pod specification in order to make sure the container gets the resources that it needs and to prevent it from using more than it should. This improves the cluster’s capacity to distribute assets and provide high-quality services.
  • Collecting Metrics: The Kubernetes Metrics Server is a cluster-wide consumption of resources data aggregator which can be utilized for collecting metrics. It collects metrics from each node’s Kubelet and then makes them accessible through the Kubernetes API.
  • Using Metrics for Autoscaling: These metrics are employed by the HorizontalPodAutoscaler (HPA) to automatically adjust the number of pod replicas based to observed utilization of resources.

Viewing Metrics: The Kubernetes Dashboard or the kubectl top commands may be employed to view metrics.

  • View Node Metrics: kubectl top nodes
  • View Pod Metrics: kubectl top pods

How to Use Kubernetes Horizontal Pod Autoscaler?

The process of automatically scaling in and scaling out of resources is called Autoscaling. There are three different types of autoscalers in Kubernetes: cluster autoscalers, horizontal pod autoscalers, and vertical pod autoscalers. In this article, we’re going to see Horizontal Pod Autoscaler.

Application running workload can be scaled manually by changing the replicas field in the workload manifest file. Although manual scaling is okay for times when you can anticipate load spikes in advance or when the load changes gradually over long periods of time, requiring manual intervention to handle sudden, unpredictable traffic increases isn’t ideal.

To solve this problem, Kubernetes has a resource called Horizontal Pod Autoscaler that can monitor pods and scale them automatically as soon as it detects an increase in CPU or memory usage (Based on a defined metric). Horizontal Pod Autoscaling is the process of automatically scaling the number of pod replicas managed by a controller based on the usage of the defined metric, which is managed by the Horizontal Pod Autoscaler Kubernetes resource to match the demand.

Similar Reads

How does a HorizontalPodAutoscaler work?

A HorizontalPodAutoscaler (HPA) in Kubernetes is a tool that automatically adjusts the number of pod replicas in a deployment, replica set, or stateful set based on observed CPU utilization (or other select metrics). Here’s a simple breakdown of how it works:...

Setup a Minikube Cluster

These steps are necessary to use Autoscaling features. By following the below steps, we can start the cluster and deploy the application into the Minikube cluster....

Scaling Based on CPU Usage

One of the most important metrics to define autoscaling is CPU usage. Let’s say the CPU usage of processes running inside your pod reaches 100% Then they can’t match the demand anymore. To solve this problem, either you can increase the amount of CPU a pod can use (Vertical scale) or increase the number of pods (Horizontal scale) so that the average CPU usage comes down, Enough talking, let’s create a Horizontal Pod Autoscaler resource based on CPU usage and see it in action....

Scaling Based on Memory Usage

This time we’ll configure HPA based on memory usage...

Scaling workloads manually

The Kubectl scale tool can be utilized to manually scale Kubernetes workloads by altering the number of replicas that are desired in the deployment or statefulset demands. This gives users large control over how assets are distributed based on workload demands....

Autoscaling during rolling update

A Deployment may handle its underlying ReplicaSets via performing a rolling update. A HorizontalPodAutoscaler (HPA) is attached to a deployment when autoscaling has been set up for it. With its replicas field, which it modifies based on resource use, the HPA controls the number of replicas utilized for the deployment....

Support for HorizontalPodAutoscaler in kubectl

The HorizontalPodAutoscaler (HPA) in Kubernetes handles scheduling pod scaling up automatically based on resource use metrics as CPU or memory. Below is an overview of how it operates:...

Kubernetes Horizontal Pod Autoscaler – FAQs

How to scale a pod in Kubernetes?...