%%{init: {"theme": "base", "themeVariables": { "edgeLabelBackground":"#fff3e6"}}}%%
flowchart LR
HPA[HPA Definition] --> API[Kube API]
%% EXTERNAL_METRIC_ADAPTER -->|Scrape metrics from application| WORKLOAD[Workload Deployment]
API -->|Get Metrics| EXTERNAL_METRIC_ADAPTER
API -->|Adjust workload scale up down| WORKLOAD
EXTERNAL_METRIC_ADAPTER -->|Get data| EXTERNAL_DATA_SOURCE
classDef hpacolor fill:#FF9966,stroke:#FF9966,color:#fff;
classDef apicolor fill:#FFB5A7,stroke:#FFB5A7,color:#fff;
classDef metricolor fill:#75C9C8,stroke:#75C9C8,color:#fff;
classDef workloadcolor fill:#6C63FF,stroke:#6C63FF,color:#fff;
class HPA hpacolor;
class API apicolor;
class EXTERNAL_METRIC_ADAPTER metricolor;
class WORKLOAD workloadcolor;
class EXTERNAL_DATA_SOURCE metricolor;
linkStyle 0 stroke:#ff9966,stroke-width:2px;
linkStyle 1 stroke:#ffb5a7,stroke-width:2px;
linkStyle 2 stroke:#63ced1,stroke-width:2px;
linkStyle 3 stroke:#a8a6b2,stroke-width:2px;
External adaptor is required else this won’t work
This is very useful when there are parameters based on which the application needs to be scaled but those parameters or objects are not part of the core kubernets ecosystem.
metrics.k8s.io provides the basic metrics for HPA which are memory and CPU utilization.
custom.metrics.k8s.io provides the custom metrics generated by the application inside the cluster which are exposed by the pods or a specific container of the pod.
Piece of software that is installed in kubernetes and acts as a bridge to extrenal sources outside the cluster or a bridge to internal data sources
These allow data sources that are not designed to work natively with kubernetes. Look at these like translators that convert the external data into kubernetes utilizable data
Default kubernetes metrics server does not support custom metrics, to which in turn user need to use external metrics server like prometheus.
It is necessary to make sure that monitoring system and agents can collect and expose the metrics in a format that the adapter can understand.
Adapter is a software installed in the cluster, for example prometheus has an adapter user and HPA can talk to through kubernetes to the prometheus server
The agent, the collector and the adapter needs to be installed because HPA can only talk to kubernetes.
They are guidelines to kubernetes on how to upscale or downscale pods based on metrics
Stabilization window is used for conservative downscaling so that the are no very frequent up scales and down scales, this reduces the quality of service
apiVersion: apps/v1 | apps/v1 | v1 | apps/v1# The API version of the resource to scale
kind: Deployment | ReplicaSet | ReplicationController | StatefulSet# The kind of resource (Deployment, StatefulSet, etc.)
name: RESOURCE_NAME# Name of the resource to scale
minReplicas: MIN_REPLICAS# Minimum number of replicas to maintain
maxReplicas: MAX_REPLICAS# Maximum number of replicas to scale up to
metrics: # Metrics to base scaling decisions on
# There can be multiple instances of Resource or Pods or Object or External type of metric, this is a list
- type: Resource
resource:
name: cpu | memory# Metric name
target:
type: Utilization | Value | AverageValue# Target type: type of parameter to use for evaluation
# Pick the below keys based on the target type
averageUtilization: AVERAGE_UTILIZATION
value: VALUE# Value for memory or cpu, see units
averageValue: AVERAGE_VALUE# Value for memory or cpu, see units
- type: Pods# Metrics that track pod-level custom metrics
pods:
metric:
name: METRIC_NAME# Example custom metric name
target:
type: Utilization | Value | AverageValue# Target type: type of parameter to use for evaluation
# Pick the below keys based on the target type
averageUtilization: AVERAGE_UTILIZATION
value: VALUE# Value for memory or cpu, see units
averageValue: AVERAGE_VALUE# Value for memory or cpu, see units
- type: Object# Metric from another Kubernetes object, Prometheus is required either scraping data from pods or via ServiceMonitor or PodMonitor or Probe
object:
describedObject:
apiVersion: API_VERSION
kind: OBJECT_KIND
# Define either name or selector
name: OBJECT_NAME
selector:
matchLabels:
LABEL: VALUE
...
metric:
name: METRIC_NAME
target:
type: Utilization | Value | AverageValue# Target type: type of parameter to use for evaluation
# Pick the below keys based on the target type
averageUtilization: AVERAGE_UTILIZATION
value: VALUE# Value for memory or cpu, see units
averageValue: AVERAGE_VALUE# Value for memory or cpu, see units
- type: External# Metric from outside Kubernetes
external:
metric:
name: METRIC
target:
type: Utilization | Value | AverageValue# Target type: type of parameter to use for evaluation
# Pick the below keys based on the target type
averageUtilization: AVERAGE_UTILIZATION
value: VALUE# Value for memory or cpu, see units
averageValue: AVERAGE_VALUE# Value for memory or cpu, see units
behavior: # Control scaling behavior rules (available in autoscaling/v2+)
scaleUp:
stabilizationWindowSeconds: SECONDS# Delay before acting on scale-up events, normally 0
selectPolicy: Max | Min# Scaling policy to choose when multiple policies apply
policies:
- type: Percent | Pods# Policy type: percent of current replicas
value: VALUE# Max 100% increase per scaling event
periodSeconds: SECONDS# Period over which this is enforced
scaleDown:
stabilizationWindowSeconds: SECONDS# Delay before acting on scale-down events
selectPolicy: Min | Max# Scaling policy to choose when multiple policies apply
policies:
- type: Percent | Pods# Policy type: absolute number of pods
value: VALUE# Max scale down by 1 pod per event
periodSeconds: SECONDS# Period over which this is enforced
tolerance: FLOAT_VALUE# Allowed deviation from target metric before scaling, from 0.0 to 0.99