Code Monkey home page Code Monkey logo

aks-scaling-examples's Introduction

AKS scaling examples

Create AKS cluster

# Create 1 AKS clusters with VPA, KEDA and cluster-autoscaler enabled
cd ./src

# Login to Azure
az login
az account set --subscription <SUBSCRIPTION_ID>

# Execute Terraform
terraform init
terraform apply -auto-approve

Enable VPA

resource "azurerm_kubernetes_cluster" "aks" {
  workload_autoscaler_profile {
    vertical_pod_autoscaler_enabled = true
  }
}

Enable KEDA

resource "azurerm_kubernetes_cluster" "aks" {
  workload_autoscaler_profile {
    keda_enabled                    = true
  }
}

Enable cluster-autoscaler

# Set the global auto-scaler config
resource "azurerm_kubernetes_cluster" "aks" {

  auto_scaler_profile {
  }
}

# Enable auto-scaler per node pool
resource "azurerm_kubernetes_cluster_node_pool" "scale" {
  enable_auto_scaling   = true
}

Horizontal Pod Autoscaler

This demo uses the VPA (needs to be activated on AKS) and metrics-server shipped with AKS

kubectl create ns hpa

# Create HPA and deployment resources vor v1 API
kubectl -n hpa apply -f ./k8s/hpav1.yaml
kubectl -n hpa get hpa hpa-demo-deployment-v1
kubectl -n hpa events
kubectl -n hpa get rs,pod
kubectl -n hpa get hpa hpa-demo-deployment-v1
kubectl -n hpa describe hpa hpa-demo-deployment-v1

# Create some load
watch -n 1 kubectl -n hpa get hpa,rs,pod
kubectl -n hpa run -i --tty load-generator-v1 --rm --image=busybox --restart=Never \
  -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://hpa-demo-deployment-v1; done"
kubectl -n hpa describe hpa hpa-demo-deployment-v1

# Create HPA and deployment resources vor v2 API
kubectl -n hpa apply -f ./k8s/hpav2.yaml
kubectl -n hpa get hpa hpa-demo-deployment-v2
kubectl -n hpa events
kubectl -n hpa get rs,pod
kubectl -n hpa get hpa hpa-demo-deployment-v2
kubectl -n hpa describe hpa hpa-demo-deployment-v2
kubectl -n hpa get rs,pod

# Create some load
watch -n 1 kubectl -n hpa get hpa,rs,pod
kubectl -n hpa run -i --tty load-generator-v2 --rm --image=busybox --restart=Never \
  -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://hpa-demo-deployment-v2; done"
kubectl -n hpa describe hpa hpa-demo-deployment-v2

Vertical Pod Autoscaler

This demo uses the VPA (needs to be activated on AKS)

kubectl create ns vpa

# Create VPA and deployment resources with too low resources with update mode "auto"
kubectl -n vpa apply -f ./k8s/vpa-low.yaml
kubectl -n vpa describe pod hamster-low-
kubectl -n vpa describe vpa/hamster-vpa-low
kubectl -n vpa events

# Create VPA and deployment resources with too high resources but with update mode "Off"
kubectl -n vpa apply -f ./k8s/vpa-high.yaml
kubectl -n vpa get pods
kubectl -n vpa describe pod hamster-high-
kubectl -n vpa get vpa
kubectl -n vpa describe vpa/hamster-vpa-high

KEDA

This demo uses the KEDA (needs to be activated on AKS). Keda leverages Worload Identity to check if messages Azure Service Bus queue.

kubectl create ns keda

# Set the base64 encrypted "servicebus-connectionstring" for the ServiceBus in the file ./k8s/keda.yaml
kubectl -n keda apply -f ./k8s/keda.yaml
kubectl -n keda get triggerauthentications.keda.sh trigger-auth-service-bus-orders
kubectl -n keda get pods
kubectl -n keda describe scaledobjects.keda.sh order-processor-scaler

# Set the "ConnectionString" for the ServiceBus in the file ./orders/Keda.Samples.Dotnet.OrderGenerator/Program.cs
watch -n 1 kubectl -n keda get rs,pod
watch -n 1 az servicebus queue list -g <rg-name> --namespace-name <sb-name> -otsv --query "[].messageCount"

dotnet run --project ./orders/Keda.Samples.Dotnet.OrderGenerator/Keda.Samples.Dotnet.OrderGenerator.csproj
kubectl -n keda events

cluster-autoscaler

This demo uses the cluster-autoscaler (needs to be activated on AKS)

kubectl create ns cluster
kubectl -n cluster run nginx --image nginx --replicas 500
kubectl -n cluster events
kubectl -n cluster get nodes -w

aks-scaling-examples's People

Contributors

nmeisenzahl avatar philwelz avatar

Watchers

Martin Brandl avatar  avatar  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.