GKE Cost Optimization: 10 Steps For A Lower Cloud Bill In 2023
Tags: cloud, devops, gke, kubernetes
Published: 2023-01-13 12:07:03

<!-- wp:paragraph -->
<p>If you’ve been running your workloads on Google Cloud’s managed Kubernetes service (GKE), you probably know how hard it is to forecast, monitor, and manage costs. GKE cost optimization initiatives only work if you combine Kubernetes know-how with a solid understanding of the cloud provider.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you’re looking for a complete guide to GKE cost optimization, keep reading and get the scoop on the latest best practices from the Kubernetes ecosystem.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="h-gke-pricing-a-quick-guide">GKE pricing: a quick guide</h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-pay-as-you-go"><strong>Pay-as-you-go</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>How it works: In this model, you’re only charged for the resources that you use. For example, Google Cloud will add every hour of compute capacity used by your team to the final monthly bill.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>There are no long-term binding contracts or upfront payments, so you’re not overcommitting. Plus, you have the freedom to increase or reduce your usage just in time.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Limitations:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>It’s <strong>the most expensive pricing model</strong>, so you risk overrunning your budget if you set no control over the scale of resources your team can burn each month.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Flexible pay-as-you-go VMs work well for unpredictable workloads that experience fluctuating traffic spikes. Otherwise, it’s best to look into alternatives.</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-committed-use-discounts">Committed Use Discounts</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>How it works</strong>: Committed Use Discounts (CUDs) compete with <a href="https://cast.ai/blog/do-aws-reserved-instances-and-savings-plans-really-reduce-costs/">AWS Reserved Instances</a> but without requiring advanced payments, You can choose from two types of Committed Use Discounts: resource- and spend-based.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Resource-based CUDs </strong>offer a discount if you commit to using a minimum level of Compute Engine resources in a specific region, targeting predictable and steady-state workloads. Moreover, CUD sharing lets you share the discount across all projects tied to your billing account.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Spend-based CUDs</strong>, on the other hand, deliver a discount to those who commit to spending a minimum amount ($/hour) for a Google Cloud product or service. This offering was designed to help companies generate predictable spend measured in $/hr of equivalent on-demand spend. This works similarly to <a href="https://cast.ai/blog/running-on-aws-savings-plans-you-can-still-reduce-your-cloud-bill/">AWS Savings Plans</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Limitations:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>In the resource-based scenario, CUD will ask you to commit to a specific instance or family.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>In the spend-based CUD, you risk committing to a level of spend for resources that your company might not need six months from now.&nbsp;&nbsp;</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>In both examples, you run the risk of <a href="https://cast.ai/blog/vendor-lock-in-and-how-to-break-free/">locking yourself in with the cloud vendor</a> and committing to pay for resources that might make little sense for your company in 1 or 3 years.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:quote {"className":"is-style-plain"} -->
<blockquote class="wp-block-quote is-style-plain"><!-- wp:paragraph -->
<p>When your compute requirements change, you’ll have to either commit even more capacity or you're stuck with unused capacity. Committed use discounts remove the flexibility and scalability that made you turn to the cloud in the first place.</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p><strong>Take a look here to learn more: <a href="https://cast.ai/blog/gcp-cud-are-there-better-ways-to-save-up-the-cloud/" target="_blank" rel="noreferrer noopener">GCP CUD: Are There Better Ways to Save Up on the Cloud?</a></strong></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-sustained-use-discounts">Sustained Use Discounts</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>How it works</strong>: Sustained Use Discounts are automated discounts users get on incremental usage after running Compute Engine resources for a big part of a billing month. The longer you run these resources continuously, the bigger your potential discount on incremental usage.&nbsp;&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-spot-virtual-machines"><strong>Spot virtual machines</strong></h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>How it works</strong>: In this cost-effective pricing model, you bid on resources Google Cloud isn’t using and can save between 60-91%. But the provider can pull the plug with a 30-second notice, so you need to have a strategy and tooling for dealing with such interruptions.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Limitations:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>Make sure that you pick spot VMs for workloads that can handle interruptions - and for which you have a solution in place.&nbsp;</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="h-10-steps-for-gke-cost-optimization">10 steps for GKE cost optimization</h2>
<!-- /wp:heading -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-pick-the-right-vm-type-and-size">Pick the right VM type and size</h3>
<!-- /wp:heading -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="h-1-define-your-workload-s-requirements">1. Define your workload’s requirements</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Your first step is to understand how much capacity your application needs across the following compute dimensions:&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>CPU count and architecture,&nbsp;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>memory,&nbsp;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>storage,&nbsp;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>network.&nbsp;</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>You need to make sure that the VM’s size can support your needs. See an affordable VM? Consider what will happen if you start running a memory-intensive workload on it and end up with performance issues affecting your brand and customers.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Consider your use case as well. For example, if you’re looking to train a machine learning model, it’s smarter to choose a GPU-based virtual machine because training models on it are much faster.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="h-2-choose-the-best-vm-type-for-the-job">2. Choose the best VM type for the job</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Google Cloud offers various VM types matching a wide range of use cases, with entirely different combinations of CPU, memory, storage, and networking capacity. And each type comes in one or more sizes, so you can scale your resources easily.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>But <strong>providers roll out different computers for their VMs</strong>. The chips in those machines may have different performance characteristics. So, you may easily end up picking a type with a strong performance that you don’t actually need (and you won’t even know it!).</p>
<!-- /wp:paragraph -->

<!-- wp:quote {"className":"is-style-plain"} -->
<blockquote class="wp-block-quote is-style-plain"><!-- wp:paragraph -->
<p>Understanding and calculating all of this is hard. Google Cloud has four machine families, each with multiple machine series and types. Choosing the right one is like combing through a haystack to find that one needle you need.</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>The best way to verify a machine’s capabilities is benchmarking where you drop the same workload on various machine types and check their performance. We actually did that, take a look<a href="https://cast.ai/blog/how-to-choose-the-best-vm-for-the-job/"> here</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="h-3-check-your-storage-transfer-limitations">3. Check your storage transfer limitations</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Data storage is a key GKE cost optimization aspect since each application comes with its unique storage needs. Verify that the machine you choose has the storage throughput your workloads need.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Also, <strong>avoid expensive drive options </strong>such as premium SSD<strong> </strong>unless you’re planning to use them to the fullest.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-use-spot-virtual-machines">Use spot virtual machines</h3>
<!-- /wp:heading -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="h-4-check-if-your-workload-is-spot-ready">4. Check if your workload is spot-ready</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Spot VMs offer an amazing opportunity to save up on your GKE bill - even by 91% off the pay-as-you-go pricing!&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>But before you move all your workloads to spot, you need to develop a spot strategy and check if your workload can run on spot.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Here are a few questions you need to ask when analyzing your workload:</strong></p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>How much time does it need to finish the job?&nbsp;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Is it mission- and/or time-critical?</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Can it handle interruptions gracefully?&nbsp;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Is it tightly coupled between nodes?&nbsp;</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>What solution are you going to use to move your workload when Google pulls the plug?&nbsp;</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="h-5-choose-your-spot-vms">5. Choose your spot VMs</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>When picking a spot VM, go for the slightly less popular ones. It’s simple - they’re less likely to get interrupted.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Once you pick one, <strong>check its frequency of interruptio</strong>n. This is the rate at which this instance reclaimed capacity during the trailing month.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="h-6-bid-your-price-here-s-how">6. Bid your price, here’s how</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Once you find the right machine, set the maximum price you’re willing to pay for it. The spot VM will only run when the marketplace price is below or equal to your bid.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Set the max price to the level of the on-demand pricing. </strong>Otherwise, you risk having your workloads interrupted when the price surpasses the one you’ve set.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To boost your chances of getting the spot machines you need, set up groups of spot instances to request multiple machine types at the same time (managed instance group). Managed instance groups create or add new spot VMs when additional resources are available.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Sounds great? But prepare for a massive configuration, setup, and maintenance effort if you choose to manage spot VMs manually.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="h-take-advantage-of-autoscaling">Take advantage of autoscaling</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Tracking which projects or teams generate GKE costs is hard. So is knowing whether you’re getting any savings from your cluster. But there’s one tactic that helps: autoscaling.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The tighter your Kubernetes scaling mechanisms are configured, the lower the waste and costs of running your application. Use Kubernetes autoscaling mechanisms to drive your GKE costs down.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="h-7-use-kubernetes-autoscaling-mechanisms-hpa-vpa-cluster-autoscaler">7. Use Kubernetes autoscaling mechanisms (HPA, VPA, Cluster Autoscaler)</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>Horizontal Pod Autoscaler (HPA)</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://cast.ai/blog/what-is-kubernetes-hpa-and-how-can-it-help-you-save-on-the-cloud/" target="_blank" rel="noreferrer noopener">Horizontal Pod Autoscaler (HPA)</a> adds or removes pod replicas automatically when the demand on your workload changes. It’s a great solution for scaling both stateless and stateful applications. Use HPA with cluster autoscaling to reduce the number of active nodes when the amount of pods shrinks.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Vertical Pod Autoscaler (VPA)</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Vertical Pod Autoscaler (VPA) increases and decreases the CPU and memory resource requests of pod containers to align the allocated to the actual cluster usage better. It’s a good practice to use both VPA and HPA if your HPA configuration doesn’t use CPU or memory to identify scaling targets. VPA works well for workloads that experience temporary high utilization.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Cluster Autoscaler</strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Cluster Autoscaler changes the number of nodes in a cluster. It’s an essential tool for reducing GKE costs by dynamically scaling the number of nodes to fit the current cluster utilization. This is especially valid for workloads designed to scale and meet such changing demand.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Read this for a more detailed guide to these three autoscaling mechanisms: <a href="https://cast.ai/blog/guide-to-kubernetes-autoscaling-for-cloud-cost-optimization/" target="_blank" rel="noreferrer noopener">Guide to Kubernetes autoscaling for cloud cost optimization</a></strong></p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="h-8-make-sure-that-hpa-and-vpa-policies-don-t-clash">8. Make sure that HPA and VPA policies don’t clash</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The Vertical Pod Autoscaler automatically adjusts the number of pods and limits based on a target average CPU utilization, reducing overhead and achieving cost savings. The Horizontal Pod Autoscaler aims to scale out more than up.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>So, double-check that the VPA and HPA policies aren’t interfering with each other. <strong>Review your binning and packing density settings</strong> when designing clusters for business- or purpose-class tier of service.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="h-9-consider-instance-weighted-scores">9. Consider instance weighted scores</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>When autoscaling, use instance weighting to determine how much of your chosen resource pool you want to dedicate to a particular workload. This is how you ensure that the machines you create are <strong>best suited for the work at hand</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="h-10-reduce-costs-further-with-a-mixed-instance-strategy">10. Reduce costs further with a mixed-instance strategy</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>A mixed-instance strategy can help you achieve great availability and performance at a reasonable cost. You choose from various instance types, some of which may be cheaper and just good enough for lower-throughput or low-latency workloads.</p>
<!-- /wp:paragraph -->

<!-- wp:quote {"className":"is-style-plain"} -->
<blockquote class="wp-block-quote is-style-plain"><!-- wp:paragraph -->
<p>Mixing instances in this way could potentially bring you to cost savings because each node requires Kubernetes to be installed on it, which adds a little overhead.&nbsp;</p>
<!-- /wp:paragraph --></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>But how do you scale mixed instances? In a mixed-instance situation, every instance uses a different type of resource. So, when you scale instances in autoscaling groups and use metrics like CPU and network utilization, you might get inconsistent metrics from different nodes.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To avoid these inconsistencies, use the Cluster Autoscaler to create an autoscaler configuration based on custom metrics. Also, make sure all your nodes share the same capacity for CPU cores and memory.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="h-reduce-your-gke-costs-using-automation"><strong>Reduce your GKE costs using automation</strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Using these best practices is bound to make an impact on your next GKE bill. But manual cost management will only get you up until a certain point. It requires many hours of work, potentially leading to mistakes that compromise your availability or performance if you miscalculate something.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>That’s why many teams turn to <strong>automated GKE cost optimization solutions</strong>. They help save time and money by dramatically reducing the amount of work required to manage cloud costs, giving you an opportunity to enrich your Kubernetes applications with new features instead of micromanaging the cloud infrastructure.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Connect your cluster to the CAST AI platform and run a free cost analysis to see a detailed cost breakdown and recommendations you can apply on your own - or use automation to do the job for you.</p>
<!-- /wp:paragraph -->

<!-- wp:group {"style":{"spacing":{"padding":{"top":"2rem","right":"2rem","bottom":"2rem","left":"2rem"},"margin":{"top":"2rem","bottom":"2rem"}}},"backgroundColor":"cast-black","className":"pattern-cta-text-btn","layout":{"type":"flex","flexWrap":"wrap","justifyContent":"space-between","verticalAlignment":"center"}} -->
<div class="wp-block-group pattern-cta-text-btn has-cast-black-background-color has-background" style="margin-top:2rem;margin-bottom:2rem;padding-top:2rem;padding-right:2rem;padding-bottom:2rem;padding-left:2rem"><!-- wp:group {"style":{"spacing":{"padding":{"top":"0rem","right":"0rem","bottom":"0rem","left":"0rem"},"blockGap":"0.5rem"}},"layout":{"type":"constrained","contentSize":"520px"}} -->
<div class="wp-block-group" style="padding-top:0rem;padding-right:0rem;padding-bottom:0rem;padding-left:0rem"><!-- wp:heading {"level":5} -->
<h5 class="wp-block-heading" id="h-cast-ai-clients-save-an-average-of-63-on-their-kubernetes-bills">CAST AI clients <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-cast-green-color">save an average of 63%</mark> on their Kubernetes bills</h5>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Connect your cluster and see your costs in 5 min, no credit card required.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

<!-- wp:buttons {"layout":{"type":"flex","justifyContent":"left","orientation":"horizontal","flexWrap":"nowrap"}} -->
<div class="wp-block-buttons"><!-- wp:button {"width":100} -->
<div class="wp-block-button has-custom-width wp-block-button__width-100"><a class="wp-block-button__link wp-element-button" href="https://console.cast.ai/?screen_hint=SIGNUP" target="_blank" rel="noreferrer noopener">Get started</a></div>
<!-- /wp:group -->