SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
Autoscaling in Kubernetes
Marian Soltys
DevOps Engineers
www.pixelfederation.com
Autoscaling in Kubernetes
Introduction
We are game studio based in Slovakia developing free to
play mobile games.
● Trainstation
● Diggy’s Adventure
● Seaport
● Trainstation 2
● AFK Cats
● Emporea
www.pixelfederation.com
Autoscaling in Kubernetes
TL;DR Summary
● Autoscaling - do we need it?
● Three levels of scaling - VPA, HPA, CA
● Cluster Autoscaler
● Horizontal Pod Autoscaler
● Vertical Pod Autoscaler
● Custom and External metrics for scaling
● Real life example
www.pixelfederation.com
Autoscaling in Kubernetes
Autoscaling - do we need it?
● Number of active players changes over daytime and day of week
● Batch processing
● Combination of both
● Cost optimization
www.pixelfederation.com
Autoscaling in Kubernetes
Three levels of scaling - VPA, HPA, CA
● Vertical Pod Autoscaler
Kubernetes
● CA - Cluster Autoscaler
● Horizontal Pod Autoscaler
www.pixelfederation.com
Autoscaling in Kubernetes
Three levels of scaling - VPA, HPA, CA
● Horizontal Pod Autoscaler
Kubernetes
www.pixelfederation.com
Autoscaling in Kubernetes
Three levels of scaling - VPA, HPA, CA
● CA - Cluster Autoscaler
Kubernetes
● Vertical Pod Autoscaler
● Horizontal Pod Autoscaler
www.pixelfederation.com
Autoscaling in Kubernetes
Node Autoscaling
● Cluster Autoscaler
(https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler)
● Escalator
(https://github.com/atlassian/escalator)
● Cerebral
(https://github.com/containership/cerebral)
www.pixelfederation.com
Autoscaling in Kubernetes
Cluster Autoscaler
Cluster Autoscaler automatically adjusts the size of the Kubernetes cluster cross AZ:
● Watches for pod in pending state events due to insufficient resources.
● Periodically check for underutilized nodes with pods that can be placed on other existing
nodes.
● Respects PodDistributionBudget, Affinity, Annotation, ...
How we use it:
● MinReplicas of 2 with podAntiAffinity to hostname
● Parameters:
○ scale-down-delay-after-add: 10m
○ scale-down-delay-after-delete: 10s
○ scale-down-unneeded-time: 10m
○ scale-down-utilization-threshold: 0.65
● Spot instances
www.pixelfederation.com
Autoscaling in Kubernetes
Vertical Pod Autoscaler
● Can automatically adjust pod requests and limits
● Calculation based on current and historical metrics
● Modes: Auto, Recreate, Initial, Off
Cons:
● Pod restarts when request changes
(Auto/Recreate modes)
● All pods start events goes through VPA
● Could conflict with HPA (on CPU and
memory)
Pros:
● Recommender
● Can solve under or over provisioned
pods
How we use it: We don’t.
www.pixelfederation.com
Autoscaling in Kubernetes
Horizontal Pod Autoscaler
● Scale deployments (number of pods) on metrics base
○ Container resources - CPU/Memory
○ Object
○ Custom/External metrics
● Think twice to use it with stateful deployments
Take into consideration:
● Default metrics loop 15 sec
● Metric toleration 10%
● Downscale stabilization time window. The default value is 5 minutes (5m0s).
● Parameters prior Kubernetes 1.17 are configured on cluster level
● Since Kubernetes 1.18+ some parameters can be tweaked under HPA .spec.behavior
www.pixelfederation.com
Autoscaling in Kubernetes
Horizontal Pod Autoscaler
www.pixelfederation.com
Autoscaling in Kubernetes
Metrics types (autoscaling/v2beta2)
Resource:
● CPU/memory
● Container request(s) must be set
● API: metrics.k8s.io
External:
● Metrics not related to Kubernetes objects
● AWS SQS, RDS, …
● API: external.metrics.k8s.io
Custom:
● Pod/Object (in same namespace)
● Time series DB required (e.g. Prometheus)
● API: custom.metrics.k8s.io
Example with target average 65%:
ceil[currentReplicas * ( currentMetricValue /
desiredMetricValue )] = desiredReplicas
4*(0.781 / 0.650 ) = 4.8 (means +1 pod)
Note: With multiple metrics highest value is
chosen.
www.pixelfederation.com
Autoscaling in Kubernetes
Custom and External metrics
Limitation: One adapter per type Custom/External metrics or one for both
% kubectl get APIService v1beta1.external.metrics.k8s.io -o yaml
kind: APIService
metadata:
labels: …
name: v1beta1.external.metrics.k8s.io
spec:
group: external.metrics.k8s.io
service:
name: k8s-cloudwatch-adapter
namespace: ...
port: …
...
www.pixelfederation.com
Autoscaling in Kubernetes
Custom and External metrics
● Check available metrics:
% kubectl get --raw /apis/external.metrics.k8s.io/v1beta1 | jq .
% kubectl get --raw /apis/external.metrics.k8s.io/v1beta1/namespaces/<ns name>/<metric name> | jq .
{
"kind": "ExternalMetricValueList",
"apiVersion": "external.metrics.k8s.io/v1beta1",
"metadata": {...},
"items": [
{
"metricName": "ts2-numberOfMessagesSent",
"metricLabels": null,
"timestamp": "2021-02-17T11:05:20Z",
"value": “27"
}
]
}
{
"kind": "APIResourceList",
"apiVersion": "v1",
"groupVersion": "external.metrics.k8s.io/v1beta1",
"resources": [
{
"name": "ts2-numberOfMessagesSent",
"singularName": "",
"namespaced": true,
"kind": "ExternalMetricValueList",
"verbs": ["get"]
}
]
}
www.pixelfederation.com
Autoscaling in Kubernetes
Tested Adapters for HPA
● Prometheus adapter - we no longer use it
○ Doesn’t fit our needs any more - redesign of infrastructure needed
○ (https://github.com/kubernetes-sigs/prometheus-adapter)
● K8s-cloudwatch adapter - in use now
○ (https://github.com/awslabs/k8s-cloudwatch-adapter)
● Kube-metrics-adapter - evaluated
○ Collectors: Pod, Prometheus, AWS, HTTP, …
○ (https://github.com/zalando-incubator/kube-metrics-adapter)
● KEDA - evaluating now
○ (https://keda.sh)
www.pixelfederation.com
Autoscaling in Kubernetes
Trainstation 2 - Real Life Example
Types of workloads:
● Live traffic - changes over daytime
● Start/End of the Event - once per month
● Start/End of the Competitions - twice per week
● Event cleanup - a few days after event ends
Goals:
● Scaling backend - based on live traffic
● Batch/Asynchronous workers scaling - based on queue size
● Limit batch processing under DB pressure
● Maximize off peak hours batch processing
● Start of the Event/Competitions - scale ahead
www.pixelfederation.com
Autoscaling in Kubernetes
Trainstation 2 - Real Life Example
Cloudwatch adapter
Common approach:
1. Monitor queue
2. Calculate number of optimal
workers
3. Return metrics
Advanced approach:
1. Monitor queue
2. Calculate number of optimal
workers
3. Monitor RDS utilization
4. Tune number of workers to not
overload live workload
5. Return metrics
www.pixelfederation.com
Autoscaling in Kubernetes
Trainstation 2 - Real Life Example
apiVersion: metrics.aws/v1alpha1
kind: ExternalMetric
metadata:
name: "ts2-numberOfMessagesSent"
spec:
name: name: "ts2-numberOfMessagesSent"
resource:
resource: "deployment"
queries:
- id: queue_metric
metricStat:
metric:
namespace: "AWS/SQS"
metricName: "NumberOfMessagesSent"
dimensions:
- name: QueueName
value: "ts2-demo"
period: 30
stat: Sum
unit: Count
returnData: false
- id: db_cpuutilization
metricStat:
metric:
namespace: "AWS/RDS"
metricName: "CPUUtilization"
dimensions:
- name: DBClusterIdentifier
value: "ts2-demo-cluster"
- name: Role
value: WRITER
period: 300
stat: Average
unit: Percent
returnData: false
- id: workers_calculated
expression: "IF((queue_metric / 300) > 100, 100, queue_metric / 300)"
returnData: false
- id: workers_desired
expression: "IF(db_cpuutilization < 80, workers_calculated,
IF(db_cpuutilization < 90, workers_calculated * 80 / 100, 0))"
returnData: true
Desired pods: get queue size -> calculate desired pods -> limit to 100 max -> if DB util. is more than 80% reduce 20%
www.pixelfederation.com
Autoscaling in Kubernetes
Trainstation 2 - Real Life Example
Horizontal Pod Autoscaler config:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
labels:
app: ts2-demo
name: ts2-demo-worker
spec:
behavior:
scaleDown:
policies:
- periodSeconds: 15
type: Percent
value: 100
selectPolicy: Max
stabilizationWindowSeconds: 120
scaleUp:
...
stabilizationWindowSeconds: 0
spec:
minReplicas: 4
maxReplicas: 100
metrics:
- external:
metric:
name: ts2-numberOfMessagesVisible
target:
averageValue: "1"
type: AverageValue
type: External
- external:
metric:
name: ts2-numberOfMessagesSent
target:
averageValue: "1"
type: AverageValue
type: External
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: ts2-demo-worker
www.pixelfederation.com
Autoscaling in Kubernetes
Trainstation 2 - Real Life Example
% k get hpa ts2-demo-worker
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
ts2-demo-worker Deployment/ts2-demo-worker 0/1 (avg),
1038m/1 (avg)
4 100 27 2d4h
www.pixelfederation.com
Autoscaling in Kubernetes
Trainstation 2 - Real Life Example
It’s working :) but you have to take into account stabilization window and metrics delay
www.pixelfederation.com
Autoscaling in Kubernetes
Questions ?
msoltys@pixelfederation.com
linkedin.com/in/mariansoltys
www.pixelfederation.com
Autoscaling in Kubernetes
https://portal.pixelfederation.com/sk/career

Weitere ähnliche Inhalte

Was ist angesagt?

AWS CLOUD 2018- Amazon DynamoDB기반 글로벌 서비스 개발 방법 (김준형 솔루션즈 아키텍트)
AWS CLOUD 2018- Amazon DynamoDB기반 글로벌 서비스 개발 방법 (김준형 솔루션즈 아키텍트)AWS CLOUD 2018- Amazon DynamoDB기반 글로벌 서비스 개발 방법 (김준형 솔루션즈 아키텍트)
AWS CLOUD 2018- Amazon DynamoDB기반 글로벌 서비스 개발 방법 (김준형 솔루션즈 아키텍트)
Amazon Web Services Korea
 
일본 시골 개발자의 AWS 활용기 - AWS Summit Seoul 2017
일본 시골 개발자의 AWS 활용기 - AWS Summit Seoul 2017일본 시골 개발자의 AWS 활용기 - AWS Summit Seoul 2017
일본 시골 개발자의 AWS 활용기 - AWS Summit Seoul 2017
Amazon Web Services Korea
 

Was ist angesagt? (20)

AWS re:Invent 2016: From EC2 to ECS: How Capital One uses Application Load Ba...
AWS re:Invent 2016: From EC2 to ECS: How Capital One uses Application Load Ba...AWS re:Invent 2016: From EC2 to ECS: How Capital One uses Application Load Ba...
AWS re:Invent 2016: From EC2 to ECS: How Capital One uses Application Load Ba...
 
Get the Most Bang for Your Buck with #EC2 #WINNING
Get the Most Bang for Your Buck with #EC2 #WINNINGGet the Most Bang for Your Buck with #EC2 #WINNING
Get the Most Bang for Your Buck with #EC2 #WINNING
 
(CMP311) This One Weird API Request Will Save You Thousands
(CMP311) This One Weird API Request Will Save You Thousands(CMP311) This One Weird API Request Will Save You Thousands
(CMP311) This One Weird API Request Will Save You Thousands
 
AWS CLOUD 2018- Amazon DynamoDB기반 글로벌 서비스 개발 방법 (김준형 솔루션즈 아키텍트)
AWS CLOUD 2018- Amazon DynamoDB기반 글로벌 서비스 개발 방법 (김준형 솔루션즈 아키텍트)AWS CLOUD 2018- Amazon DynamoDB기반 글로벌 서비스 개발 방법 (김준형 솔루션즈 아키텍트)
AWS CLOUD 2018- Amazon DynamoDB기반 글로벌 서비스 개발 방법 (김준형 솔루션즈 아키텍트)
 
AWS re:Invent 2016 : announcement, technical demos and feedbacks
AWS re:Invent 2016 : announcement, technical demos and feedbacksAWS re:Invent 2016 : announcement, technical demos and feedbacks
AWS re:Invent 2016 : announcement, technical demos and feedbacks
 
Deep Dive on Microservices and Amazon ECS
Deep Dive on Microservices and Amazon ECSDeep Dive on Microservices and Amazon ECS
Deep Dive on Microservices and Amazon ECS
 
AWS EC2
AWS EC2AWS EC2
AWS EC2
 
AWS re:Invent 2016 Recap: What Happened, What It Means
AWS re:Invent 2016 Recap: What Happened, What It MeansAWS re:Invent 2016 Recap: What Happened, What It Means
AWS re:Invent 2016 Recap: What Happened, What It Means
 
AWS re:Invent 2016: Get Technically Inspired by Container-Powered Migrations ...
AWS re:Invent 2016: Get Technically Inspired by Container-Powered Migrations ...AWS re:Invent 2016: Get Technically Inspired by Container-Powered Migrations ...
AWS re:Invent 2016: Get Technically Inspired by Container-Powered Migrations ...
 
AWS re:Invent 2016: How Thermo Fisher Is Reducing Mass Spectrometry Experimen...
AWS re:Invent 2016: How Thermo Fisher Is Reducing Mass Spectrometry Experimen...AWS re:Invent 2016: How Thermo Fisher Is Reducing Mass Spectrometry Experimen...
AWS re:Invent 2016: How Thermo Fisher Is Reducing Mass Spectrometry Experimen...
 
Windows Azure Versioning Strategies
Windows Azure Versioning StrategiesWindows Azure Versioning Strategies
Windows Azure Versioning Strategies
 
일본 시골 개발자의 AWS 활용기 - AWS Summit Seoul 2017
일본 시골 개발자의 AWS 활용기 - AWS Summit Seoul 2017일본 시골 개발자의 AWS 활용기 - AWS Summit Seoul 2017
일본 시골 개발자의 AWS 활용기 - AWS Summit Seoul 2017
 
Deep Dive on Elastic Load Balancing
Deep Dive on Elastic Load BalancingDeep Dive on Elastic Load Balancing
Deep Dive on Elastic Load Balancing
 
AWS re:Invent 2016: Deep Learning, 3D Content Rendering, and Massively Parall...
AWS re:Invent 2016: Deep Learning, 3D Content Rendering, and Massively Parall...AWS re:Invent 2016: Deep Learning, 3D Content Rendering, and Massively Parall...
AWS re:Invent 2016: Deep Learning, 3D Content Rendering, and Massively Parall...
 
#lspe Q1 2013 dynamically scaling netflix in the cloud
#lspe Q1 2013   dynamically scaling netflix in the cloud#lspe Q1 2013   dynamically scaling netflix in the cloud
#lspe Q1 2013 dynamically scaling netflix in the cloud
 
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
 
Introduction to AWS X-Ray
Introduction to AWS X-RayIntroduction to AWS X-Ray
Introduction to AWS X-Ray
 
An MPI-IO Cloud Cluster Bioinformatics Summer Project (BDT205) | AWS re:Inven...
An MPI-IO Cloud Cluster Bioinformatics Summer Project (BDT205) | AWS re:Inven...An MPI-IO Cloud Cluster Bioinformatics Summer Project (BDT205) | AWS re:Inven...
An MPI-IO Cloud Cluster Bioinformatics Summer Project (BDT205) | AWS re:Inven...
 
AWS re:Invent 2016: How to Launch a 100K-User Corporate Back Office with Micr...
AWS re:Invent 2016: How to Launch a 100K-User Corporate Back Office with Micr...AWS re:Invent 2016: How to Launch a 100K-User Corporate Back Office with Micr...
AWS re:Invent 2016: How to Launch a 100K-User Corporate Back Office with Micr...
 
Achieve big data analytic platform with lambda architecture on cloud
Achieve big data analytic platform with lambda architecture on cloudAchieve big data analytic platform with lambda architecture on cloud
Achieve big data analytic platform with lambda architecture on cloud
 

Ähnlich wie Autoscaling in kubernetes v1

How we Auto Scale applications based on CPU with Kubernetes at M6Web?
 How we Auto Scale applications based on CPU with Kubernetes at M6Web? How we Auto Scale applications based on CPU with Kubernetes at M6Web?
How we Auto Scale applications based on CPU with Kubernetes at M6Web?
Vincent Gallissot
 
Operator Lifecycle Management
Operator Lifecycle ManagementOperator Lifecycle Management
Operator Lifecycle Management
DoKC
 

Ähnlich wie Autoscaling in kubernetes v1 (20)

Autoscaling Kubernetes
Autoscaling KubernetesAutoscaling Kubernetes
Autoscaling Kubernetes
 
Automatically scaling Kubernetes workloads - SVC215-S - New York AWS Summit
Automatically scaling Kubernetes workloads - SVC215-S - New York AWS SummitAutomatically scaling Kubernetes workloads - SVC215-S - New York AWS Summit
Automatically scaling Kubernetes workloads - SVC215-S - New York AWS Summit
 
KubeCon Prometheus Salon -- Kubernetes metrics deep dive
KubeCon Prometheus Salon -- Kubernetes metrics deep diveKubeCon Prometheus Salon -- Kubernetes metrics deep dive
KubeCon Prometheus Salon -- Kubernetes metrics deep dive
 
AWS Summit Singapore 2019 | Autoscaling Your Kubernetes Workloads
AWS Summit Singapore 2019 | Autoscaling Your Kubernetes WorkloadsAWS Summit Singapore 2019 | Autoscaling Your Kubernetes Workloads
AWS Summit Singapore 2019 | Autoscaling Your Kubernetes Workloads
 
Kubernetes: Beyond Baby Steps
Kubernetes: Beyond Baby StepsKubernetes: Beyond Baby Steps
Kubernetes: Beyond Baby Steps
 
Kubernetes Colorado - Kubernetes metrics deep dive 10/25/2017
Kubernetes Colorado - Kubernetes metrics deep dive 10/25/2017Kubernetes Colorado - Kubernetes metrics deep dive 10/25/2017
Kubernetes Colorado - Kubernetes metrics deep dive 10/25/2017
 
Kubernetes #2 monitoring
Kubernetes #2   monitoring Kubernetes #2   monitoring
Kubernetes #2 monitoring
 
Ceilometer + Heat = Alarming
Ceilometer + Heat = Alarming Ceilometer + Heat = Alarming
Ceilometer + Heat = Alarming
 
Uber Business Metrics Generation and Management Through Apache Flink
Uber Business Metrics Generation and Management Through Apache FlinkUber Business Metrics Generation and Management Through Apache Flink
Uber Business Metrics Generation and Management Through Apache Flink
 
eBay Pulsar: Real-time analytics platform
eBay Pulsar: Real-time analytics platformeBay Pulsar: Real-time analytics platform
eBay Pulsar: Real-time analytics platform
 
Pulsar: Real-time Analytics at Scale with Kafka, Kylin and Druid
Pulsar: Real-time Analytics at Scale with Kafka, Kylin and DruidPulsar: Real-time Analytics at Scale with Kafka, Kylin and Druid
Pulsar: Real-time Analytics at Scale with Kafka, Kylin and Druid
 
Automatically scaling your Kubernetes workloads - SVC210-S - Santa Clara AWS ...
Automatically scaling your Kubernetes workloads - SVC210-S - Santa Clara AWS ...Automatically scaling your Kubernetes workloads - SVC210-S - Santa Clara AWS ...
Automatically scaling your Kubernetes workloads - SVC210-S - Santa Clara AWS ...
 
KFServing and Feast
KFServing and FeastKFServing and Feast
KFServing and Feast
 
A Practical Deep Dive into Observability of Streaming Applications with Kosta...
A Practical Deep Dive into Observability of Streaming Applications with Kosta...A Practical Deep Dive into Observability of Streaming Applications with Kosta...
A Practical Deep Dive into Observability of Streaming Applications with Kosta...
 
How we Auto Scale applications based on CPU with Kubernetes at M6Web?
 How we Auto Scale applications based on CPU with Kubernetes at M6Web? How we Auto Scale applications based on CPU with Kubernetes at M6Web?
How we Auto Scale applications based on CPU with Kubernetes at M6Web?
 
Autoscaling in Kubernetes
Autoscaling in KubernetesAutoscaling in Kubernetes
Autoscaling in Kubernetes
 
Monitoring kubernetes across data center and cloud
Monitoring kubernetes across data center and cloudMonitoring kubernetes across data center and cloud
Monitoring kubernetes across data center and cloud
 
Kubernetes @ Squarespace: Kubernetes in the Datacenter
Kubernetes @ Squarespace: Kubernetes in the DatacenterKubernetes @ Squarespace: Kubernetes in the Datacenter
Kubernetes @ Squarespace: Kubernetes in the Datacenter
 
Operator Lifecycle Management
Operator Lifecycle ManagementOperator Lifecycle Management
Operator Lifecycle Management
 
Operator Lifecycle Management
Operator Lifecycle ManagementOperator Lifecycle Management
Operator Lifecycle Management
 

Kürzlich hochgeladen

Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
imonikaupta
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
sexy call girls service in goa
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Sheetaleventcompany
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Chandigarh Call girls 9053900678 Call girls in Chandigarh
 

Kürzlich hochgeladen (20)

Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
 
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
 

Autoscaling in kubernetes v1

  • 1. Autoscaling in Kubernetes Marian Soltys DevOps Engineers
  • 2. www.pixelfederation.com Autoscaling in Kubernetes Introduction We are game studio based in Slovakia developing free to play mobile games. ● Trainstation ● Diggy’s Adventure ● Seaport ● Trainstation 2 ● AFK Cats ● Emporea
  • 3. www.pixelfederation.com Autoscaling in Kubernetes TL;DR Summary ● Autoscaling - do we need it? ● Three levels of scaling - VPA, HPA, CA ● Cluster Autoscaler ● Horizontal Pod Autoscaler ● Vertical Pod Autoscaler ● Custom and External metrics for scaling ● Real life example
  • 4. www.pixelfederation.com Autoscaling in Kubernetes Autoscaling - do we need it? ● Number of active players changes over daytime and day of week ● Batch processing ● Combination of both ● Cost optimization
  • 5. www.pixelfederation.com Autoscaling in Kubernetes Three levels of scaling - VPA, HPA, CA ● Vertical Pod Autoscaler Kubernetes ● CA - Cluster Autoscaler ● Horizontal Pod Autoscaler
  • 6. www.pixelfederation.com Autoscaling in Kubernetes Three levels of scaling - VPA, HPA, CA ● Horizontal Pod Autoscaler Kubernetes
  • 7. www.pixelfederation.com Autoscaling in Kubernetes Three levels of scaling - VPA, HPA, CA ● CA - Cluster Autoscaler Kubernetes ● Vertical Pod Autoscaler ● Horizontal Pod Autoscaler
  • 8. www.pixelfederation.com Autoscaling in Kubernetes Node Autoscaling ● Cluster Autoscaler (https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler) ● Escalator (https://github.com/atlassian/escalator) ● Cerebral (https://github.com/containership/cerebral)
  • 9. www.pixelfederation.com Autoscaling in Kubernetes Cluster Autoscaler Cluster Autoscaler automatically adjusts the size of the Kubernetes cluster cross AZ: ● Watches for pod in pending state events due to insufficient resources. ● Periodically check for underutilized nodes with pods that can be placed on other existing nodes. ● Respects PodDistributionBudget, Affinity, Annotation, ... How we use it: ● MinReplicas of 2 with podAntiAffinity to hostname ● Parameters: ○ scale-down-delay-after-add: 10m ○ scale-down-delay-after-delete: 10s ○ scale-down-unneeded-time: 10m ○ scale-down-utilization-threshold: 0.65 ● Spot instances
  • 10. www.pixelfederation.com Autoscaling in Kubernetes Vertical Pod Autoscaler ● Can automatically adjust pod requests and limits ● Calculation based on current and historical metrics ● Modes: Auto, Recreate, Initial, Off Cons: ● Pod restarts when request changes (Auto/Recreate modes) ● All pods start events goes through VPA ● Could conflict with HPA (on CPU and memory) Pros: ● Recommender ● Can solve under or over provisioned pods How we use it: We don’t.
  • 11. www.pixelfederation.com Autoscaling in Kubernetes Horizontal Pod Autoscaler ● Scale deployments (number of pods) on metrics base ○ Container resources - CPU/Memory ○ Object ○ Custom/External metrics ● Think twice to use it with stateful deployments Take into consideration: ● Default metrics loop 15 sec ● Metric toleration 10% ● Downscale stabilization time window. The default value is 5 minutes (5m0s). ● Parameters prior Kubernetes 1.17 are configured on cluster level ● Since Kubernetes 1.18+ some parameters can be tweaked under HPA .spec.behavior
  • 13. www.pixelfederation.com Autoscaling in Kubernetes Metrics types (autoscaling/v2beta2) Resource: ● CPU/memory ● Container request(s) must be set ● API: metrics.k8s.io External: ● Metrics not related to Kubernetes objects ● AWS SQS, RDS, … ● API: external.metrics.k8s.io Custom: ● Pod/Object (in same namespace) ● Time series DB required (e.g. Prometheus) ● API: custom.metrics.k8s.io Example with target average 65%: ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )] = desiredReplicas 4*(0.781 / 0.650 ) = 4.8 (means +1 pod) Note: With multiple metrics highest value is chosen.
  • 14. www.pixelfederation.com Autoscaling in Kubernetes Custom and External metrics Limitation: One adapter per type Custom/External metrics or one for both % kubectl get APIService v1beta1.external.metrics.k8s.io -o yaml kind: APIService metadata: labels: … name: v1beta1.external.metrics.k8s.io spec: group: external.metrics.k8s.io service: name: k8s-cloudwatch-adapter namespace: ... port: … ...
  • 15. www.pixelfederation.com Autoscaling in Kubernetes Custom and External metrics ● Check available metrics: % kubectl get --raw /apis/external.metrics.k8s.io/v1beta1 | jq . % kubectl get --raw /apis/external.metrics.k8s.io/v1beta1/namespaces/<ns name>/<metric name> | jq . { "kind": "ExternalMetricValueList", "apiVersion": "external.metrics.k8s.io/v1beta1", "metadata": {...}, "items": [ { "metricName": "ts2-numberOfMessagesSent", "metricLabels": null, "timestamp": "2021-02-17T11:05:20Z", "value": “27" } ] } { "kind": "APIResourceList", "apiVersion": "v1", "groupVersion": "external.metrics.k8s.io/v1beta1", "resources": [ { "name": "ts2-numberOfMessagesSent", "singularName": "", "namespaced": true, "kind": "ExternalMetricValueList", "verbs": ["get"] } ] }
  • 16. www.pixelfederation.com Autoscaling in Kubernetes Tested Adapters for HPA ● Prometheus adapter - we no longer use it ○ Doesn’t fit our needs any more - redesign of infrastructure needed ○ (https://github.com/kubernetes-sigs/prometheus-adapter) ● K8s-cloudwatch adapter - in use now ○ (https://github.com/awslabs/k8s-cloudwatch-adapter) ● Kube-metrics-adapter - evaluated ○ Collectors: Pod, Prometheus, AWS, HTTP, … ○ (https://github.com/zalando-incubator/kube-metrics-adapter) ● KEDA - evaluating now ○ (https://keda.sh)
  • 17. www.pixelfederation.com Autoscaling in Kubernetes Trainstation 2 - Real Life Example Types of workloads: ● Live traffic - changes over daytime ● Start/End of the Event - once per month ● Start/End of the Competitions - twice per week ● Event cleanup - a few days after event ends Goals: ● Scaling backend - based on live traffic ● Batch/Asynchronous workers scaling - based on queue size ● Limit batch processing under DB pressure ● Maximize off peak hours batch processing ● Start of the Event/Competitions - scale ahead
  • 18. www.pixelfederation.com Autoscaling in Kubernetes Trainstation 2 - Real Life Example Cloudwatch adapter Common approach: 1. Monitor queue 2. Calculate number of optimal workers 3. Return metrics Advanced approach: 1. Monitor queue 2. Calculate number of optimal workers 3. Monitor RDS utilization 4. Tune number of workers to not overload live workload 5. Return metrics
  • 19. www.pixelfederation.com Autoscaling in Kubernetes Trainstation 2 - Real Life Example apiVersion: metrics.aws/v1alpha1 kind: ExternalMetric metadata: name: "ts2-numberOfMessagesSent" spec: name: name: "ts2-numberOfMessagesSent" resource: resource: "deployment" queries: - id: queue_metric metricStat: metric: namespace: "AWS/SQS" metricName: "NumberOfMessagesSent" dimensions: - name: QueueName value: "ts2-demo" period: 30 stat: Sum unit: Count returnData: false - id: db_cpuutilization metricStat: metric: namespace: "AWS/RDS" metricName: "CPUUtilization" dimensions: - name: DBClusterIdentifier value: "ts2-demo-cluster" - name: Role value: WRITER period: 300 stat: Average unit: Percent returnData: false - id: workers_calculated expression: "IF((queue_metric / 300) > 100, 100, queue_metric / 300)" returnData: false - id: workers_desired expression: "IF(db_cpuutilization < 80, workers_calculated, IF(db_cpuutilization < 90, workers_calculated * 80 / 100, 0))" returnData: true Desired pods: get queue size -> calculate desired pods -> limit to 100 max -> if DB util. is more than 80% reduce 20%
  • 20. www.pixelfederation.com Autoscaling in Kubernetes Trainstation 2 - Real Life Example Horizontal Pod Autoscaler config: apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: labels: app: ts2-demo name: ts2-demo-worker spec: behavior: scaleDown: policies: - periodSeconds: 15 type: Percent value: 100 selectPolicy: Max stabilizationWindowSeconds: 120 scaleUp: ... stabilizationWindowSeconds: 0 spec: minReplicas: 4 maxReplicas: 100 metrics: - external: metric: name: ts2-numberOfMessagesVisible target: averageValue: "1" type: AverageValue type: External - external: metric: name: ts2-numberOfMessagesSent target: averageValue: "1" type: AverageValue type: External scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: ts2-demo-worker
  • 21. www.pixelfederation.com Autoscaling in Kubernetes Trainstation 2 - Real Life Example % k get hpa ts2-demo-worker NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE ts2-demo-worker Deployment/ts2-demo-worker 0/1 (avg), 1038m/1 (avg) 4 100 27 2d4h
  • 22. www.pixelfederation.com Autoscaling in Kubernetes Trainstation 2 - Real Life Example It’s working :) but you have to take into account stabilization window and metrics delay
  • 23. www.pixelfederation.com Autoscaling in Kubernetes Questions ? msoltys@pixelfederation.com linkedin.com/in/mariansoltys