Completek8s Classroomnotes 05/Oct/2023

AKS Contd

Scaling in AKS

  • Lets experiment Scaling in AKS
  • AKS cluster by default comes with metrics server in it
  • We can scale manually by using kubectl scale to scale automatically have two options
    • HPA (Horizontal pod autoscaler)
    • VPA (Vertical Pod autoscaler)
  • For this experiment we will be using a deployment with stress side car container which puts load
apiVersion: apps/v1
kind: Deployment
metadata:
  name: azure-vote-back
spec:
  replicas: 1
  selector:
    matchLabels:
      app: azure-vote-back
  template:
    metadata:
      labels:
        app: azure-vote-back
    spec:
      nodeSelector:
        "kubernetes.io/os": linux
      containers:
      - name: azure-vote-back
        image: mcr.microsoft.com/oss/bitnami/redis:6.0.8
        env:
        - name: ALLOW_EMPTY_PASSWORD
          value: "yes"
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 250m
            memory: 256Mi
        ports:
        - containerPort: 6379
          name: redis
---
apiVersion: v1
kind: Service
metadata:
  name: azure-vote-back
spec:
  ports:
  - port: 6379
  selector:
    app: azure-vote-back
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: azure-vote-front
spec:
  replicas: 2
  selector:
    matchLabels:
      app: azure-vote-front
  template:
    metadata:
      labels:
        app: azure-vote-front
    spec:
      nodeSelector:
        "kubernetes.io/os": linux
      containers:
      - name: azure-vote-front
        image: mcr.microsoft.com/azuredocs/azure-vote-front:v1
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 250m
            memory: 256Mi
        ports:
        - containerPort: 80
        env:
        - name: REDIS
          value: "azure-vote-back"
      - name: stress
        image: alpine
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
        command:
          - apk update && apk add stress-ng && stress-ng --cpu 4 --vm 2 --hdd 1 --fork 8 --timeout 100m --metrics
---
apiVersion: v1
kind: Service
metadata:
  name: azure-vote-front
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: azure-vote-front
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: voting-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: azure-vote-front
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 60
  • The current state is we have enough nodes to meet the demand.
    Preview
  • this is where cluster autoscaler Refer Here
az aks nodepool update --enable-cluster-autoscaler -g myResourceGroup --cluster-name myAKSCluster -n nodepool1 --min-count 1 --max-count 3
  • Now have a look at nodes
    Preview
  • use the following images in the stress container
venuchowgani/stress:latest
necindia/test-hpa:v1

Need to provide access for Azure AD (Microsoft Entra) user to access kubernetes

  • Follow the video for setup
  • Custom cluster role for a group
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: viewers
rules:
  - apiGroups:
      - ""
    resources:
      - "pods"
    verbs:
      - "get"
      - "watch"
      - "list"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: viewersbinding
roleRef:
  kind: ClusterRole
  name: viewers
  apiGroup: rbac.authorization.k8s.io
subjects:
  - apiGroup: rbac.authorization.k8s.io
    kind: Group
    name: "711bf260-fd71-469f-801f-075a0da619f3"

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Integration by Acurax Wordpress Developers

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube