Skip to main content

GKE vs AKS vs EKS - How to Terraform Your Kubernetes with Terraform.

Tobias Jonas Tobias Jonas 8 min read
GKE vs AKS vs EKS - How to Terraform Your Kubernetes with Terraform.

With our blog post, we want to provide an overview of the three major cloud providers and explain how a Kubernetes cluster can be created in each cloud using simple tools with Terraform. Before the article goes into the individual Terraform examples, we’ll first illuminate Kubernetes, Terraform, and provide an overview of the 3 major hyperscalers Amazon Web Services (AWS), Azure, and Google Cloud.

What Are Containers and Why Do You Need Kubernetes in the Cloud?

A container is a type of virtualization where an application runs in an isolated area that is separated from the host environment. This allows the application to run in a predictable and reproducible environment that is independent of the host’s hardware and operating system environment.

Using containers allows applications to be deployed and scaled quickly and easily. Since containers are easy to transport, they can run on different hosts, which increases the flexibility and scalability of applications.

Kubernetes is an open-source system developed by Google for managing these container applications and has become the de facto standard. As a container management tool, Kubernetes has a high level of abstraction and can be used to run many different types of software. This makes it possible to run all types of software in the same cluster or across multiple clusters.

Each Kubernetes cluster consists of a control plane (master nodes) responsible for performing management tasks in the cluster. This includes tasks such as job management, container scheduling, and all other tasks to be executed on the worker nodes. The connected worker node servers are responsible for executing these tasks. The containers are thus run on the worker nodes.

Kubernetes clusters can be highly available when the tasks of masters and worker nodes are distributed across multiple servers.

What Is Terraform?

Terraform is an open-source tool developed by HashiCorp. With the HashiCorp Configuration Language (HCL), desired cloud infrastructure can be created, modified, and deleted via a target description. Through various providers, i.e., interface connections, Terraform can manage virtually any infrastructure. This fundamentally differentiates Terraform from proprietary solutions such as AWS CDK, Google’s Deployment Manager, or Azure Blueprints in the cloud environment. From physical devices to virtual machines and containers to software configuration, everything can be described via Terraform. The official providers as well as partner providers are listed at https://registry.terraform.io/browse/providers. In addition to the providers used in this article, there are also providers for Alibaba, IBM, or Oracle Cloud, for example.

With Terraform, users create a declarative description of the desired infrastructure. This description is then used to create changes or upgrades for this infrastructure. Terraform calculates the difference between current and desired infrastructure and executes the necessary changes. The process can be fully run as a pipeline via GitHub Actions, for example, and the HCL file descriptions can be versioned via git.

With Terraform, not only can the Kubernetes cluster be set up in the desired cloud, but configuration can also be performed. There’s even a matching Terraform provider for the Kubernetes package manager Helm that executes the corresponding Kubernetes deployments directly on the cluster. An example would be the Cert-Manager for SSL certificates for external APIs or external-dns for automating DNS infrastructure based on deployment annotations.

Hyperscalers – AWS, Google Cloud, and Azure.

AWS (Amazon Web Services), Google Cloud, and Azure are collections of cloud computing services offered by Amazon, Google, and Microsoft. All three services offer scalability, reliability, and flexibility for businesses looking to run their IT infrastructure in the cloud. They support different programming languages, databases, and operating systems and offer a variety of tools and services for different application areas.

However, the exact advantages and disadvantages depend on the specific requirements and goals of a company. One advantage of Google Cloud, for example, is that it is closely integrated with other Google services such as G-Suite or Google Analytics and that Kubernetes integration is the most advanced. A disadvantage is that it is significantly less widespread than the other two services and that Google offers fewer services overall. However, the services offered harmonize very well with each other. One advantage of AWS is that it has been on the market for a long time and therefore offers a large number of integrated tools and services. A disadvantage is that it is significantly more complex and difficult to use compared to the other services and that the tools don’t harmonize as well overall. Probably the biggest advantage of Azure is that it is well suited for companies using Microsoft technologies such as Azure AD. A disadvantage from our experience is that Azure has the highest operating costs overall, even if it appears cheaper at first glance in the calculator.

It’s important for companies to consider specific requirements and goals and choose a cloud service that best meets their needs. It’s recommended to compare different services and, if necessary, use a free trial version before deciding on a particular service. innFactory’s expertise can also help you choose the right cloud provider.

Create Google Cloud GKE Cluster with Terraform.

To create a Kubernetes cluster in Google Cloud with Terraform, you must first install Terraform on your computer and set up Google Cloud Platform authentication configuration. Then you can create a Terraform script that defines the desired settings for your Kubernetes cluster, such as the number of Kubernetes nodes and the machine type used. Once the script is created, you can run Terraform with the terraform apply command to create the cluster.

Here’s an example of a Terraform script that creates a GKE Kubernetes cluster in Google Cloud:

provider "google" 

resource "google_container_cluster" "cluster"

To run the script, save it as main.tf and run the terraform apply command in the same directory. Terraform will then execute the settings in the script and create the Kubernetes cluster in Google Cloud. For more information, see the Terraform documentation and the Google Cloud documentation.

Since this is a very simple cluster, you should consider using ready-made modules for your cluster. Google Cloud and Hashicorp publish ready-made modules on GitHub at https://github.com/terraform-google-modules that enable a much more sophisticated cluster configuration. At https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/tree/master/examples you’ll find several examples for various clusters. Whether it’s the special feature that the cluster takes care of worker nodes itself in Autopilot mode, or examples of secured private clusters that cannot be managed via the internet.

Google offers by far the most options and add-ons with GKE that are integrated “out of the box” into Google Cloud infrastructure without additional deployments needing to be loaded onto the cluster. Features like Autopilot, SSL certificates without an additional Cert-Manager, log analysis, or cluster security checks are directly integrated unlike with AWS and Azure.

Create AWS EKS Cluster with Terraform.

An example of a Terraform script that creates a Kubernetes cluster (EKS) in AWS could look like this:

# Configure the AWS provider
provider "aws" 

# Configure the Kubernetes module (EKS)
module "innFactory_eks_example"

This script first defines the AWS provider and configures it with access credentials and region settings for your AWS account. Then the Kubernetes module is configured and the settings for the cluster are defined, such as the name, region, number of worker nodes, and access behavior.

To run the script and create the cluster, you must run Terraform again with the apply command. Note that this is just an example and additional configurations and options may be required depending on your requirements. More information can be found in the Terraform documentation and in the Kubernetes module at https://github.com/terraform-aws-modules/terraform-aws-eks/tree/master/examples/complete.

Create Azure AKS Cluster with Terraform

Like Amazon and Google, Microsoft offers a largely managed Kubernetes product in Azure. Azure Kubernetes Service (AKS) is Microsoft Azure’s managed Kubernetes platform. AKS also simplifies the deployment and management of applications in Kubernetes containers and enables businesses to focus on application development rather than cluster management.

AKS also offers integrated tools and services such as Azure Monitor and Azure Log Analytics to monitor and optimize the performance and availability of Kubernetes clusters. It’s possible to integrate AKS with other Azure services such as Azure Active Directory (Azure AD) and Azure Virtual Network to create a secure and scalable Kubernetes environment. AKS is frequently created in conjunction with Terraform.

In terms of feature set, Azure AKS positions itself between Google GKE, with the most predefined capabilities/add-ons, and AWS EKS, with what we see as the fewest predefined plugins and services.

# Configure Azure Provider
provider "azuread" 

# Azure AD, if RBAC should be mapped via Azure AD and an existing role should be assigned
provider "azuread" 

data "azuread_group" "aks_admin" 

# Create AKS Cluster

resource "azurerm_kubernetes_cluster" "innFactory_aks_example"

Important, this too is only meant to be an example of creating a Kubernetes cluster via Terraform.

Summary

In our article, we’ve seen that all major hyperscalers offer a ready-made implementation of Kubernetes that can be fully created via Terraform. Which cloud provider is right for you depends largely on your requirements. We’re happy to support you in selecting the right technology and implementing your digital products in the cloud.

Tobias Jonas
Written by Tobias Jonas CEO

Cloud-Architekt und Experte für AWS, Google Cloud, Azure und STACKIT. Vor der Gründung der innFactory bei Siemens und BMW tätig.

LinkedIn