<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gnana Sowndharya  on Medium]]></title>
        <description><![CDATA[Stories by Gnana Sowndharya  on Medium]]></description>
        <link>https://medium.com/@sowndharya.g_62309?source=rss-54c02d77db06------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*3rgd8c50QW87yf3S</url>
            <title>Stories by Gnana Sowndharya  on Medium</title>
            <link>https://medium.com/@sowndharya.g_62309?source=rss-54c02d77db06------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 01:33:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sowndharya.g_62309/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Achieving Cost Savings and Scalability Using Spot Instances in AKS]]></title>
            <link>https://blog.thecloudside.com/achieving-cost-savings-and-scalability-using-spot-instances-in-aks-6d53fa837bc7?source=rss-54c02d77db06------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d53fa837bc7</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[ak]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Gnana Sowndharya ]]></dc:creator>
            <pubDate>Thu, 20 Nov 2025 00:50:19 GMT</pubDate>
            <atom:updated>2025-11-20T00:50:19.979Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*-7Buo7Mz_xGcZsbShEhVEQ.png" /></figure><p>Cloud compute spending often continues to grow silently as application environments expand, especially when non-production workloads run on standard on-demand nodes by default. Since these workloads usually have more flexible performance and availability needs compared to production systems, they are well-suited for cost-efficient compute options. By introducing Spot node pools for non-production environments, organizations can significantly reduce their compute spending while still meeting the performance needs of development, testing, and staging workloads.</p><p>However, Spot instances come with a major challenge, they can be reclaimed by the cloud provider at any time, risking service disruption. To maintain reliability, a dual-node pool strategy with Spot as the primary pool and On-Demand as a fallback, combined with automated scheduling and scaling logic, is the key.</p><p>The goal is simple yet critical, run all workloads on Spot nodes as much as possible, without compromising availability, even during Spot Preemptions. This blog explains the strategies, mechanisms, and configurations that helped us achieve significant cost savings while maintaining high availability and zero manual intervention.</p><h4>Implementing the Dual-Node Pool Strategy in Terraform</h4><p>On-Demand Node Pool</p><p>This node pool acts as the stable, fallback capacity. It is configured for high availability and is not subject to eviction.<br><em>terraform.tfvars</em></p><pre>dev-ondemand = {<br>    node_count_size      = 1<br>    name                 = &quot;dev-ondemand&quot;<br>    vm_size              = &quot;Standard_E2as_v5&quot;<br>    vnet_subnet_id       = &quot;xxxx&quot;<br>    os_disk_size_gb      = 130<br>    orchestrator_version = &quot;1.31.1&quot;<br>    enable_auto_scaling  = true<br>    min_count            = 3<br>    max_count            = 3<br>    max_pods             = 110<br>    os_sku               = &quot;Ubuntu&quot;<br>    mode                 = &quot;User&quot;<br>    environment_tag      = &quot;dev&quot;<br>    type_tag             = &quot;on-demand&quot;<br>    node_labels = {<br>      &quot;env&quot;       = &quot;dev&quot;<br>      &quot;node_type&quot; = &quot;on-demand&quot;<br>    }<br>  }<br><br>uat-ondemand = {<br>    node_count_size      = 1<br>    name                 = &quot;uat-ondemand&quot;<br>    vm_size              = &quot;Standard_E2as_v5&quot;<br>    vnet_subnet_id       = &quot;xxxx&quot;<br>    os_disk_size_gb      = 130<br>    orchestrator_version = &quot;1.31.1&quot;<br>    enable_auto_scaling  = true<br>    min_count            = 3<br>    max_count            = 3<br>    max_pods             = 110<br>    os_sku               = &quot;Ubuntu&quot;<br>    mode                 = &quot;User&quot;<br>    environment_tag      = &quot;uat&quot;<br>    type_tag             = &quot;on-demand&quot;<br>    node_labels = {<br>      &quot;env&quot;       = &quot;uat&quot;<br>      &quot;node_type&quot; = &quot;on-demand&quot;<br>    }<br>  }</pre><p>Spot Node Pool</p><p>This node pool is configured to leverage Spot Instances. Critical attributes like priority, eviction_policy, and node_taints are used to manage its behaviour and integration with the cluster.</p><pre>dev-spot = {<br>    node_count_size      = 1<br>    name                 = &quot;dev-spot&quot;<br>    vm_size              = &quot;Standard_E2as_v5&quot;<br>    vnet_subnet_id       = &quot;xxx&quot;<br>    os_disk_size_gb      = 130<br>    orchestrator_version = &quot;1.31.1&quot;<br>    enable_auto_scaling  = true<br>    min_count            = 1<br>    max_count            = 3<br>    max_pods             = 110<br>    os_sku               = &quot;Ubuntu&quot;<br>    mode                 = &quot;User&quot;<br>    environment_tag      = &quot;dev&quot;<br>    type_tag             = &quot;spot&quot;<br>    priority             = &quot;Spot&quot;<br>    eviction_policy      = &quot;Delete&quot;<br>    spot_max_price       = -1<br>    node_labels = {<br>      &quot;spot&quot;      = &quot;true&quot;<br>      &quot;env&quot;       = &quot;dev&quot;<br>      &quot;node_type&quot; = &quot;spot&quot;<br>      &quot;kubernetes.azure.com/scalesetpriority&quot; = &quot;spot&quot;<br>    }<br>    node_taints = [&quot;kubernetes.azure.com/scalesetpriority=spot:NoSchedule&quot;]<br>  }<br><br>uat-spot = {<br>    node_count_size      = 1<br>    name                 = &quot;uat-spot&quot;<br>    vm_size              = &quot;Standard_E2as_v5&quot;<br>    vnet_subnet_id       = &quot;xxx&quot;<br>    os_disk_size_gb      = 130<br>    orchestrator_version = &quot;1.31.1&quot;<br>    enable_auto_scaling  = true<br>    min_count            = 1<br>    max_count            = 3<br>    max_pods             = 110<br>    os_sku               = &quot;Ubuntu&quot;<br>    mode                 = &quot;User&quot;<br>    environment_tag      = &quot;uat&quot;<br>    type_tag             = &quot;spot&quot;<br>    priority             = &quot;Spot&quot;<br>    eviction_policy      = &quot;Delete&quot;<br>    spot_max_price       = -1<br>    node_labels = {<br>      &quot;spot&quot;      = &quot;true&quot;<br>      &quot;env&quot;       = &quot;uat&quot;<br>      &quot;node_type&quot; = &quot;spot&quot;<br>      &quot;kubernetes.azure.com/scalesetpriority&quot; = &quot;spot&quot;<br>    }<br>    node_taints = [&quot;kubernetes.azure.com/scalesetpriority=spot:NoSchedule&quot;]<br>  }</pre><p>Terraform attributes that makes a node pool as spot capacity</p><ul><li>priority = “Spot” <br><em>makes the node pool a Spot node pool</em></li><li>spot_max_price = -1<br><em>uses current dynamic spot pricing</em></li><li>eviction_policy = “Delete”<br><em>nodes in the underlying scale set of the node pool are deleted when they are evicted</em></li><li>Taint : kubernetes.azure.com/scalesetpriority=spot:NoSchedule<br><em>Prevents accidental scheduling of critical workloads to spot</em></li></ul><h3>Initial Workload Scheduling on Spot Nodes</h3><p>To make Spot nodes the default execution environment for non-production workloads, implemented a strategy using a combination of node labels, taints and tolerations, and node affinity rules. Each of these plays a specific role in influencing the scheduler’s decisions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*9eTURbRcvulkJAOOh3P-yw.png" /></figure><p><strong>1. Classifying Nodes Using Labels</strong></p><p>Both Spot and On-Demand node pools are assigned descriptive labels such as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zQlB_2-kFkBWuZ_TwizjXQ.png" /></figure><p>These labels act as identifiers, helping Kubernetes and Helm understand which nodes belong to which group. Labels do not enforce scheduling by themselves, but they are the foundation used by affinity rules later.</p><p><strong>2. Spot nodes in AKS comes with default taint:</strong></p><pre>kubernetes.azure.com/scalesetpriority=spot:NoSchedule</pre><p>This taint prevents pods from being scheduled on Spot nodes unless they explicitly include a matching toleration.</p><pre>tolerations:<br>  - key: &quot;kubernetes.azure.com/scalesetpriority&quot;<br>    operator: &quot;Equal&quot;<br>    value: &quot;spot&quot;<br>    effect: &quot;NoSchedule&quot;</pre><p>Workloads should include this toleration, which means, Pods are allowed to run on both Spot and On-Demand nodes, but do not prefer either yet. This step ensures that Spot remains eligible for scheduling.</p><p><strong>3. Enforcing Environment Separation Using Required Node Affinity</strong></p><p>In each microservice’s <em>deployment.yaml</em>, define :</p><pre>affinity:<br>  nodeAffinity:<br>    requiredDuringSchedulingIgnoredDuringExecution:<br>      nodeSelectorTerms:<br>        - matchExpressions:<br>            - key: env<br>              operator: In<br>              values:<br>                - &quot;dev&quot;<br><br>                                 {or}<br><br>affinity:<br>  nodeAffinity:<br>    requiredDuringSchedulingIgnoredDuringExecution:<br>      nodeSelectorTerms:<br>        - matchExpressions:<br>            - key: env<br>              operator: In<br>              values:<br>                - &quot;uat&quot;</pre><p>which translates into a requiredAffinity rule that ensures, Dev workloads run only on nodes labeled env=dev as well as UAT workloads run only on nodes labeled env=uat. This ensures workloads cannot accidentally cross between environment node groups</p><p><strong>4. Preferring Spot Nodes Using Weighted Affinity Rules</strong></p><p>Once a pod is allowed to run in the correct environment, then use preferredAffinity to encourage Kubernetes to select Spot nodes first:</p><pre>preferredDuringSchedulingIgnoredDuringExecution:<br>  - weight: 100<br>    preference:<br>      matchExpressions:<br>        - key: node_type<br>          operator: In<br>          values:<br>            - spot</pre><p>This does not force pods onto Spot nodes — instead, it tells the scheduler, If both Spot and On-Demand nodes are available, choose Spot. Therefore Spot becomes the first choice, while On-Demand remains a safe fallback.</p><h3>Automatic Fallback During Spot Node Preemptions</h3><p>When Spot node is reclaimed, Azure marks the node as <strong>NotReady</strong> and triggers pod eviction. Once the node becomes unavailable, the Kubernetes scheduler attempts to reschedule the affected pods. At this point, because Spot nodes are no longer present, the scheduler looks for the next best placement option that satisfies the node affinity rules — the On-Demand node pool in the same environment (env=dev or env=uat).</p><p>Since the On-Demand nodes share the same environment labels, Kubernetes can place the pods there immediately without requiring any configuration change or manual action. This ensures uninterrupted application availability, even during unexpected Spot interruptions.</p><h3>Restoring Workloads Back to Spot Nodes Using Descheduler</h3><p>While the fallback to On-Demand nodes ensures application continuity during Spot interruptions, a mechanism is needed to automatically shift workloads back to Spot nodes once capacity is restored. The Kubernetes Descheduler provides this crucial function. The Descheduler is a tool monitors workloads running on on-demand nodes and evicts them back to the Spot pool when capacity is restored. This process helps maximize Spot node usage and minimizes unnecessary costs associated with on-demand nodes.</p><p><strong>Execution-Flow</strong></p><ul><li>The Descheduler is deployed as a kind deployment.</li><li>Policy Configmap configured with the <strong>RemovePodsViolatingNodeAffinity</strong> plugin.</li><li>This plugin checks for pods running on nodes that do not match their preferred node affinity (in this case, pods meant for Spot nodes but running on on-demand nodes).</li><li>Evicts those pods so Kubernetes reschedules them onto available Spot nodes.</li><li>Descheduler scans the cluster periodically.</li><li>If Spot nodes are back and meet the pods’ affinity preferences, pods on on-demand nodes are marked for eviction.</li><li>Kubernetes then schedules them onto the current-available Spot nodes using above mentioned strategies in initial pod scheduling.</li></ul><p><em>Descheduler-deployment.yaml</em></p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: descheduler<br>  namespace: kube-system<br>  labels:<br>    app: descheduler<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: descheduler<br>  template:<br>    metadata:<br>      labels:<br>        app: descheduler<br>    spec:<br>      priorityClassName: system-cluster-critical<br>      serviceAccountName: descheduler-sa<br>      containers:<br>      - name: descheduler<br>        image: registry.k8s.io/descheduler/descheduler:v0.33.0<br>        imagePullPolicy: IfNotPresent<br>        command:<br>          - &quot;/bin/descheduler&quot;<br>        args:<br>          - &quot;--policy-config-file=/policy-dir/policy.yaml&quot;<br>          - &quot;--descheduling-interval=5m&quot;<br>          - &quot;--v=2&quot;<br>        ports:<br>        - containerPort: 10258<br>          protocol: TCP<br>        livenessProbe:<br>          httpGet:<br>            path: /healthz<br>            port: 10258<br>            scheme: HTTPS<br>          initialDelaySeconds: 3<br>          periodSeconds: 10<br>        resources:<br>          requests:<br>            cpu: 200m<br>            memory: 128Mi<br>        volumeMounts:<br>        - mountPath: /policy-dir<br>          name: policy-volume<br>      volumes:<br>      - name: policy-volume<br>        configMap:<br>          name: descheduler-policy-configmap</pre><p><em>Descheduler-Policy-ConfigMap.yaml</em></p><pre>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: descheduler-policy-configmap<br>  namespace: kube-system<br>data:<br>  policy.yaml: |<br>    apiVersion: descheduler/v1alpha2<br>    kind: DeschedulerPolicy<br>    profiles:<br>      - name: default<br>        pluginConfig:<br>          - name: DefaultEvictor<br>          - name: RemovePodsViolatingNodeAffinity<br>            args:<br>              nodeAffinityType:<br>                - &quot;preferredDuringSchedulingIgnoredDuringExecution&quot;<br>        plugins:<br>          deschedule:<br>            enabled:<br>              - RemovePodsViolatingNodeAffinity<br></pre><h3>Spot Preemption Early-Warning and Graceful Drain Mechanism</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O3cmeRLhxIMtnp0vLhCPxQ.png" /></figure><p>This monitoring system acts like an early warning siren for Spot node terminations. By detecting Preemption events before they occur, it ensures that workloads are gracefully drained and rescheduled on On-Demand nodes reducing downtime and preventing unexpected pod failures. The DaemonSet runs continuously in the background, checking every 10 seconds for eviction notices, and instantly triggering alerts in Teams webhook channel.</p><p><em>Daemonset.yaml</em></p><pre>apiVersion: apps/v1<br>kind: DaemonSet<br>metadata:<br>  name: spot-preemption-watcher<br>  namespace: kube-system<br>spec:<br>  selector:<br>    matchLabels:<br>      app: spot-watcher<br>  template:<br>    metadata:<br>      labels:<br>        app: spot-watcher<br>    spec:<br>      serviceAccountName: descheduler-sa<br>      nodeSelector:<br>        kubernetes.azure.com/scalesetpriority: spot<br>      tolerations:<br>      - key: &quot;kubernetes.azure.com/scalesetpriority&quot;<br>        operator: &quot;Equal&quot;<br>        value: &quot;spot&quot;<br>        effect: &quot;NoSchedule&quot;<br>      containers:<br>      - name: watcher<br>        image: alpine:3.18<br>        env:<br>        - name: NODE_NAME<br>          valueFrom:<br>            fieldRef:<br>              fieldPath: spec.nodeName<br>        command:<br>        - /bin/sh<br>        - -c<br>        - |<br>          echo &quot;Installing curl and kubectl inside Alpine pod...&quot;<br>          apk update &amp;&amp; \<br>          apk add --no-cache curl bash &amp;&amp; \<br>          curl -LO &quot;https://dl.k8s.io/release/v1.30.0/bin/linux/amd64/kubectl&quot; &amp;&amp; \<br>          chmod +x kubectl &amp;&amp; mv kubectl /usr/local/bin/<br><br>          while true; do<br>            EVENT=$(curl -s -H &quot;Metadata:true&quot; &quot;http://169.254.169.254/metadata/scheduledevents?api-version=2020-07-01&quot;)<br><br>            if echo $EVENT | grep -q &quot;Preempt&quot;; then<br>                echo &quot;Spot VM eviction detected on $NODE_NAME!&quot;<br><br>                # Send Teams alert<br>                curl -H &quot;Content-Type: application/json&quot; \<br>                  -d &quot;{\&quot;text\&quot;: \&quot; Spot node ${NODE_NAME} is being preempted in ~30s. Draining node.\&quot;}&quot; \<br>                  https://&lt;your-teams-webhook-url&gt;<br><br>                # Drain node safely<br>                kubectl drain $NODE_NAME --ignore-daemonsets --delete-emptydir-data --force<br><br>                sleep 60<br>            fi<br>            sleep 10<br>          done</pre><p><strong>Execution-Flow :</strong></p><ul><li>The DaemonSet periodically queries Azure’s instance metadata service at 169.254.169.254 for scheduled events.</li><li>If the response contains “Preempt”, it means the Spot node is about to be evicted.</li><li>Sends a Teams notification through a webhook, warning that the node will be preempted in 30 seconds.</li><li>Executes kubectl drain on the affected node to safely evict all non-DaemonSet pods, allowing them to be rescheduled on available on-demand nodes.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d53fa837bc7" width="1" height="1" alt=""><hr><p><a href="https://blog.thecloudside.com/achieving-cost-savings-and-scalability-using-spot-instances-in-aks-6d53fa837bc7">Achieving Cost Savings and Scalability Using Spot Instances in AKS</a> was originally published in <a href="https://blog.thecloudside.com/">The Cloudside View</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>