How to Manage Cloud Costs on GCP and GKE

Jul 11th, 2022
How to Manage Cloud Costs on GCP and GKE
URL Copied

Cloud adoption is not slowing down anytime soon; 50% of business workloads in 2023 are expected to run in the cloud, a 40% rise from 2021. Despite this high adoption rate, many executives have expressed their frustration over the difficulty of accurately calculating their cloud infrastructure costs. 

Google Cloud Platform (GCP) is one of the most used cloud platforms on the globe, with a 10% market share, only behind Amazon Web Services (33%) and Microsoft Azure (21%). Left unmonitored or poorly managed, Google Cloud costs can easily spiral out of control.

In this guide, you'll learn about GCP cloud cost management and how you can drive down the cost of managing your infrastructure. 

Understanding Cloud Cost on Google Cloud Platform

Businesses can avoid unwanted billing surprises with a disciplined cloud cost management strategy. This will allow them to get the most out of their cloud spending. 

Typically, most GCP expenses result from the misconception that you only pay for only what you consume, as opposed to what you provision and consume. For instance, if you forget to turn off a particular service, you’ll continue incurring additional costs. Overprovisioning also hits the budget, i.e., when you provision a specific resource above what you require.

GCP’s pricing and billing vary across its product offerings, such as Compute Engine, VPC networking, Artificial Intelligence and Machine Learning, storage, containers, data analytics, and databases. For each product, Google offers multiple services for a variety of purposes—some are freely available while others may incur a fee. To understand how these services are charged, see our article: The Complete Guide to Google Cloud Pricing.

New users on GCP benefit from an initial $300 threshold or spend threshold before being billed. However, to get a better understanding or forecast of your monthly or yearly cloud spend, you can try out the GCP’s pricing calculator

Cloud Cost Management on GCP

Google Cloud Platform offers a range of tools that users can use to control their cloud operational expenses, ranging from beginner to advanced. 

Billing and expense management tools like Quotas, Budgets, and alerts let you stay on top of your current cloud costs to ensure you don't go over budget. 

In general, such tools are helpful in providing an overview picture of their entire cloud infrastructure costs and a breakdown of how much each project costs.

Let’s consider some of the built-in ways to manage your cloud infrastructure cost on GCP.

Visualize Cloud Billing Reports

GCP reports provide access to a dashboard visualizing and detailing all costs associated with your project. This helps you quickly identify active services and how much they cost. You can also visualize data on current cost trends and cost drivers, or view the breakdown of spend by product or region, and predict estimated costs based on historical data.

Create Budgets and Alerts

Within GCP, you can set up a budget that will notify you when a specific amount has been reached or is expected to be reached. For example, if you set up a budget limit of $500 and an alert threshold for 75% usage, you’ll get notified when your cloud spend reaches $375. 

You can create budgets and alerts for an entire project or multiple projects, and ensure stakeholders stay informed about the details of the cloud spend.

To create a budget, navigate to the GCP Console in the top left corner. Click on Budgets and Alerts under Billing to open up a new page (Figure 1).

gcp-gke-cost-management-1

Figure 1: Locate the Billing controls on the GCP

You can create a budget and alert based on target billing costs from this page (Figure 2).

gcp-gke-cost-management-2

Figure 2. Set up a billing alert on the GCP

Aside from managing GCP alerts, the dashboard presents a list of all the budget line items that are currently active (Figure 3).

 

gcp-gke-cost-management-3

Figure 3. GCP Budgets & Alerts dashboard

The progress bar on the right-hand side of the dash (Figure 3) lets you know how much of the assigned budget has been used.

While this tool is great when you're getting started on a small-scale project, it often lacks the necessary level of detail required for larger teams with complex needs. Such projects may require quotas.

New call-to-action

Set Cost Controls Using Quota

While the GCP Budget tool triggers notifications based on your estimates, quotas allow you to limit the number of concurrent resources for a project, or set the API request rate for a set period.

Quotas are critical to safeguarding users from unforeseen spikes in usage that could push past the assigned budgets. GCP supports two types of quotas:

  • Allocation quota: measures and limits a resource, for example, the number of virtual machines that you can spin up at a time
  • Rate quota: limits the number of hits to an API or service in a given interval

You can configure these from the GCP Console: navigate to Quotas under IAM and admin (Figure 4).

 

gcp-gke-cost-management-4

Figure 4. Access GCP Quotas

Best Practices for Efficient Cloud Cost Optimization

To efficiently optimize cloud costs, you need a comprehensive strategy that’ll provide you with clear visibility into the granular details of your Google Cloud environment. Here are some strategies to optimize your GCP cloud spend:

Identify Unused or Inactive Resources 

Sometimes administrators or developers deploy a temporary server instance to run a specific function and then forget to terminate it when the job is done. Or worse, they may forget to delete the storage attached to the instance. This drives up your cloud spending, so you should keep an eye on such instances and perform regular reviews.

Optimize GCP BigQuery Costs

Many companies use GCP BigQuery as a modern approach to data analytics. This is a billed service and can potentially impact budgets if you don't optimize it. 

You can reduce your bill by permanently banning SELECT * in all your SQL scripts. This is probably the easiest and most effective method. SELECT is the most inefficient and, therefore, expensive way to retrieve data from a GCP warehouse. Another way is to partition and cluster your tables to reduce query processing costs and improve performance.

Optimize Cloud Logging

You can improve network traffic transparency by filtering out logs no longer needed. For instance, audit logs are sometimes quite large and may incur additional expenses. If you are working on a development project, for example, these logs are probably not needed after a certain period. So setting a retention period can be helpful.

Right-Size Pod Resources in Google Kubernetes Engine

The primary cause of excessive costs in Google Kubernetes Engine (GKE) is provisioning more resources than you need. GKE orchestrates computing power in response to variable on-demand needs, generating variable expenses – which means that it is crucial to track those costs. While sizing resources is essential to scaling in GKE, it is just as equally important to resize them when the need arises. 

To help you save costs in GKE, you need to release underused or redundant resources. Additionally, you need to identify ways to avoid over-provisioning resources since idle, provisioned resources continually incur a cost. However, there is a fine balance between under- and over-provisioning: you should ensure not to under-provision your resources, which can lead to poor performance and negatively impact customer experience.

Below is a sample deployment using YAML to manage GKE using a standard method that includes manual resource thresholds.

 

```
apiVersion: v1
kind: Pod
metadata:
  name: gcp_test
spec:
  containers:
  - name: app
    image: images.dummy-company.example/node:v1
    resources:
      requests:
        memory: "22Mi"
        cpu: "150m"
      limits:
        memory: "138Mi"
        cpu: "500m"
```



Here, the requested CPU is specified as 150m and memory as 22Mi, based on the amount of CPU and memory your application requires. If you specify more than the app needs, Kubernetes will provision a large number of resources, which may result in extra nodes spinning up and driving up costs.

Fortunately, GKE includes many auto-scaling features that help with on-demand scaling:

  • Horizontal Pod Autoscaler
  • Vertical Pod Autoscaler
  • Cluster Autoscaler

Here is a sample deployment YAML file using Horizontal Pod Autoscaler:

```
---
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: podinfo
spec:
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: podinfo
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Pods
    pods:
      metricName: memory_usage_bytes
      targetAverageValue: 10485760

```

 

```
---
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: podinfo
spec:
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: podinfo
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Pods
    pods:
      metricName: memory_usage_bytes
      targetAverageValue: 10485760

```

This approach lets you select pods and clusters that are the right size for your current needs. Because of this, GKE scales up or scales down resources automatically based on pod requirements.

For a deep dive into Kubernetes cost control, reach out for a copy of our ebook.

Finout: Take Charge of Your Entire Cloud Infrastructure Costs Beyond GCP

Managing cloud costs with GCP-native tools can be effective for simple or small-scale projects or teams – giving you a high-level cost overview of your cloud spend. However, getting granular cost visibility doesn't come easy, especially if you apply a hybrid or multi-cloud architecture. 

The GCP can not give you access to the costs of idle or unallocated resources or running costs of solutions outside of the GCP (e.g., containers, hybrid, or multi-cloud platforms). Therefore, relying exclusively on GCP tools for cloud cost management is insufficient for any top enterprise that aims to save cloud costs by applying a sophisticated microservice architecture. 

Finout's dedicated cloud cost management solution acts to collate all your cloud costs, and aligns you with the FinOps principles – easing the management and control of cloud costs across your entire cloud infrastructure. Finout’s solution provides granular and unit cost data such as cost per customer or transaction.

Interested in learning how a cloud cost management solution can help you optimize your GCP spend? Contact Finout today.

Main topics