Creating Your First GKE Cluster
Introduction: Building Your First GKE Cluster
In the previous lesson, you prepared your environment by installing the gcloud and kubectl command-line tools. Now, you'll use those tools to create your first GKE cluster. This is the foundational step for the rest of the course, as you need a running cluster before you can deploy any applications.
By the end of this lesson, you'll have a fully functional, two-node Kubernetes cluster running on Google Cloud. You will create the cluster using a single gcloud command with command-line flags, connect to it with kubectl, verify its status, and finally, learn how to delete it to avoid extra costs. We use command-line flags because they provide a straightforward, imperative way to specify exactly what you want, making it easy to understand and reproduce your cluster configuration.
Enabling Required Google Cloud APIs
Before you can create a GKE cluster, you need to enable the Google Kubernetes Engine API in your Google Cloud project. Google Cloud organizes its services as APIs that must be explicitly enabled before use. This is a one-time setup step for each project.
Run the following command to enable the Container API, which is the service that powers GKE:
This command tells Google Cloud to activate the Kubernetes Engine service for your current project. The output will confirm that the API is being enabled:
If the API is already enabled, you'll see a message indicating that no changes were necessary. This command is safe to run multiple times. Once the API is enabled, you're ready to create your first cluster.
Creating the Cluster with gcloud
Now let's create your first GKE cluster. The gcloud container clusters create command is the primary tool for creating clusters, and you control the cluster's configuration by passing flags to this command. Here's the command you'll use:
Let's break down what each flag does:
my-gke-cluster: This is the name of your cluster. You'll use this name to reference the cluster in future commands.--num-nodes=2: This creates a cluster with two worker nodes. Each node is a virtual machine that runs your containerized applications.--region=us-central1: This specifies the Google Cloud region where your cluster will run. Regional clusters distribute nodes across multiple zones within the region for high availability.--machine-type=e2-medium: This sets the size of the virtual machines used for your worker nodes. Thee2-mediumtype provides2vCPUs and4GB of memory, which is cost-effective for learning.--release-channel=regular: This enrolls your cluster in the "regular" release channel, which provides a balance between stability and access to new features. Google automatically manages Kubernetes version upgrades for clusters in release channels.
The creation process takes 5 to 10 minutes because gcloud is provisioning significant infrastructure on your behalf. Here's what happens behind the scenes:
- GKE control plane: Google creates and manages the highly available Kubernetes control plane. This is the "brain" of your cluster, and it's fully managed by Google — you don't see or pay for the control plane nodes directly.
- VPC and networking: Google automatically configures networking, including a virtual private cloud (VPC), subnets, and firewall rules that allow your nodes to communicate securely.
- Worker nodes: Google creates Compute Engine virtual machine instances in multiple zones within your chosen region, configures them as Kubernetes nodes, and connects them to the control plane.
- Node pools: Your nodes are organized into a node pool, which is a group of nodes with the same configuration. This makes it easy to manage and scale groups of nodes together.
This automation is the primary benefit of using GKE, as it handles dozens of complex steps that would be tedious and error-prone to perform manually. The output you'll see looks something like this:
This output shows the cluster being created and health-checked. The final table displays key information about your cluster, including its name, location, Kubernetes version, and the number of nodes. Note that even though you specified --num-nodes=2, you might see 6 nodes in the output — this is because regional clusters create the specified number of nodes in each of three zones for high availability (2 nodes × 3 zones = 6 total nodes).
While you're waiting for the cluster to be created, you can open the Google Cloud Console and navigate to the Kubernetes Engine section to watch your cluster appear and become ready.
