<?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 Gunjan Chaudhari on Medium]]></title>
        <description><![CDATA[Stories by Gunjan Chaudhari on Medium]]></description>
        <link>https://medium.com/@gunjan-chaudhari?source=rss-abf8dd4ce969------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Gunjan Chaudhari on Medium</title>
            <link>https://medium.com/@gunjan-chaudhari?source=rss-abf8dd4ce969------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 04:01:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gunjan-chaudhari/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[Optimizing Workload Costs with Spot VMs and Node Affinity in GKE]]></title>
            <link>https://blog.searce.com/optimizing-workload-costs-with-spot-vms-and-node-affinity-in-gke-6587b4b2c58c?source=rss-abf8dd4ce969------2</link>
            <guid isPermaLink="false">https://medium.com/p/6587b4b2c58c</guid>
            <category><![CDATA[node-affinity]]></category>
            <category><![CDATA[spot-vm]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[gke]]></category>
            <dc:creator><![CDATA[Gunjan Chaudhari]]></dc:creator>
            <pubDate>Tue, 20 Jun 2023 13:20:01 GMT</pubDate>
            <atom:updated>2023-06-21T06:46:38.478Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Authors: </strong><a href="https://medium.com/u/abf8dd4ce969">Gunjan Chaudhari</a>, <a href="https://medium.com/u/31f3f7b1d4d8">Ziya Patel</a></p><p>Workload costs often make up a significant portion of an organization’s overall expenses. By optimizing these costs, businesses can achieve significant savings and allocate their resources more effectively. Cost optimization allows organizations to maximize their return on investment (ROI) and allocate funds to other critical areas of their operations. To optimize the workload cost in GCP, we have used Spot VMs.</p><p><a href="https://cloud.google.com/compute/docs/instances/spot">Google Cloud’s Spot VMs</a> offer a cost-efficient way to run your workloads in the cloud by allowing you to take advantage of idle capacity in Google’s data centers. These VMs are similar to on-demand instances, but they come at a significantly lower cost. Spot VMs can be particularly useful for running large-scale workloads or workloads that can be interrupted or stopped without any significant impact on the overall job.</p><p>With Spot VMs in GKE, you can run Kubernetes clusters on these low-cost instances and reduce your cloud infrastructure costs while maintaining high availability and performance. However, efficiently utilizing spot VMs requires a strategic approach that involves identifying the right workloads, defining optimal configurations, and effectively managing interruptions.</p><p>In this blog, we’ll explore how to leverage Spot VMs in GKE to achieve optimal performance and cost efficiency for your cloud computing needs.</p><h3>Scenarios</h3><h4>1. Priority to Spot VMs</h4><blockquote>We have employed the “preferredDuringSchedulingIgnoredDuringExecution” methodology as a soft limit strategy to prioritize the deployment of pods on spot virtual machines (VMs) over standard pool VMs. Consequently, when spot VMs are available, they will be the preferred option for pod deployment. However, in the event of spot VMs being deleted, the deployment of pods will shift to standard pool VMs.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/0*_Df4k3GE1SWr0NLV" /><figcaption>Priority to Spot VMs</figcaption></figure><p>Below are the steps:</p><ol><li>Create a GKE standard cluster.</li><li>Initially create a node-pool with the spot VMs option enabled.</li><li>Once the Cluster is created, add another node pool with the spot VMs option disabled. This new node pool would only consist of standard VMs.</li><li>Once you are done creating the cluster, it should look like this.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E3fLQQRHAD6YtaGb" /><figcaption>Google Kubernetes Cluster</figcaption></figure><p>5. Create a YAML file and run it using the kubectl apply command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2daf7ab50b6f732b5a5c1a259a693359/href">https://medium.com/media/2daf7ab50b6f732b5a5c1a259a693359/href</a></iframe><p>The YAML defines a preferred scheduling weight of 80 for nodes labeled with “cloud.google.com/gke-spot: true”, indicating a preference for GKE spot instances. It also sets a weight of 20 for nodes labeled with “cloud.google.com/gke-nodepool: standard-pool”. This affinity strategy influences the scheduling decisions for the Deployment, allowing a preference for certain node types or pools within the GKE cluster.</p><p>6. Run the YAML file above to deploy an Nginx web application. Both the replicas get deployed in the spot pool as that is preferred.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TNggMWMbXYf4VjE8" /></figure><h4>2. Priority to a specific family in Spot Pool</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/0*3kf5TnD2tVGY5IXV" /></figure><blockquote>Apart from the previously mentioned scenario, we have also incorporated a match expression based on the instance family. This allows us to specify key-value pairs in the match expression that correspond to the CPU and memory requirements of an application. As a result, pods can be deployed on instances that meet the specified requirements.</blockquote><ol><li>Create another node pool with the desired family type of the instances. We have considered e2-standard-2 for the demo.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aSBZairnbpjsTvJf" /><figcaption>GKE cluster with 3 node pools</figcaption></figure><p>2. Create a YAML file in which we will utilize node affinity to achieve the desired output.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e004d9fa76d1e9c20245f8f0ac712c53/href">https://medium.com/media/e004d9fa76d1e9c20245f8f0ac712c53/href</a></iframe><p>Run the YAML file using the given command:</p><pre>kubectl apply -f spot-family.yaml</pre><p>As the family-example-pool has spot instances the preference for the deployment of all the replicas is family-example-pool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yQwundfVC0cQu4jM" /></figure><h4>3. Ensuring Uniform Deployment of the Same Application Across a NodePool</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/0*wGAFhmE2rbUhQJf8" /></figure><blockquote>To ensure two instances of a particular pod are not deployed on the same node to increase the resiliency of your application, you can use pod anti-affinity rules to specify that pods with the same label should be scheduled on different nodes within the same cluster.</blockquote><ol><li>Create a YAML file and run it in the cluster using the command:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c9e407ce9dc6be81008fe2832c15a66/href">https://medium.com/media/3c9e407ce9dc6be81008fe2832c15a66/href</a></iframe><p>Run the YAML file using the given command:</p><pre>kubectl apply -f pod-antiaffinity.yaml</pre><p>The affinity strategy prioritizes nodes with the label “cloud.google.com/gke-spot: true” by setting a higher weight of 80, and nodes with the label “cloud.google.com/gke-nodepool: standard-pool” with a weight of 20.</p><p>The anti-affinity strategy ensures that pods with the label “app: nginx” do not co-locate on the same node. This is achieved by setting the requiredDuringSchedulingIgnoredDuringExecution field with a label selector to enforce anti-affinity constraints.</p><p>As a result in our case both the replicas will get deployed on node pools with spot instances which are spot-pool and family-example-pool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-VmNSzSi6xfluU69" /></figure><h4>4. Auto deletion of completed or Error nodes</h4><p>We have created a cron job to delete the nodes which are in the completed state at the interval of 1 minute.</p><ol><li>Create ClusterRole, ClusterRoleBinding, and Service Account for the cron job.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32beecff46ba597ffa11885b83a0fe73/href">https://medium.com/media/32beecff46ba597ffa11885b83a0fe73/href</a></iframe><p>2. Create a YAML file for Cron Job.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e2f3b3fd6d472696d6dcb9772bfe4fd/href">https://medium.com/media/0e2f3b3fd6d472696d6dcb9772bfe4fd/href</a></iframe><h4>5. PreStop Hook</h4><p>We can perform actions prior to the unexpected auto deletion of nodes via PreStop Hook. You can pass any command to execute under the Prestop section suiting your application needs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/309e1c895f98e512f89212de8c27da45/href">https://medium.com/media/309e1c895f98e512f89212de8c27da45/href</a></iframe><h4>6. Uniform application deployment on all the nodes</h4><p>When we configure the weights to be 50–50 for the Standard pool and Spot pool, the application gets deployed uniformly across the standard pool and spot pool.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37fe5b49028e77cef60c4c1162050159/href">https://medium.com/media/37fe5b49028e77cef60c4c1162050159/href</a></iframe><p>As we can see in the below image, pods are distributed in spot and standard pools uniformly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G37E0Wbq3MZj87P6265o3A.png" /></figure><p>In conclusion, by incorporating Spot VMs and node affinity into your GKE environment, you can optimize workload costs while maintaining performance and reliability. This approach enables businesses to leverage cost-effective resources and make the most of their infrastructure budget. However, it’s essential to carefully assess the suitability of workloads for Spot VMs and implement proper monitoring and scaling mechanisms to ensure a successful and cost-efficient deployment.</p><p>We hope this blog has provided valuable insights and inspiration for your cloud infrastructure strategies. “Stay innovative, stay optimized, and embrace the full potential of spot VMs and node affinity in your GKE journey!”</p><p>In case of any doubts or suggestions, please feel free to reach out to us on LinkedIn. You can contact <a href="https://www.linkedin.com/in/gunjan-chaudhari-523047149/">Gunjan Chaudhari</a> or <a href="https://www.linkedin.com/in/ziyapatel/">Zia Patel</a> by sending a direct message.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6587b4b2c58c" width="1" height="1" alt=""><hr><p><a href="https://blog.searce.com/optimizing-workload-costs-with-spot-vms-and-node-affinity-in-gke-6587b4b2c58c">Optimizing Workload Costs with Spot VMs and Node Affinity in GKE</a> was originally published in <a href="https://blog.searce.com/">Searce</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>