Cloud Services / Kubernetes

How to Deploy a Kubernetes Cluster to the Google Cloud Platform

28 Nov 2019 6:00am, by

There are numerous ways to deploy a Kubernetes cluster. For some businesses, the best solution is on in-house Linux servers. For others, the best option is to deploy on third party services, such as Amazon Web Services, Rackspace, Linode, Microsoft Azure, or Google Cloud Platform. Why would someone want to deploy to a third party, instead of retaining absolute control over every aspect of the cluster? Simple: Reliability and overhead.

Your company simply may not have the resources available to deploy a cluster at scale. It’s also possible you simply don’t have the time or the manpower to get those Kubernetes-ready servers up and running. Or you might need more reliability than you can achieve on in-house hardware.

Either way, you’re covered. And if you happen to have a Google Cloud Platform account, you’re in luck. Deploying a Kubernetes cluster on Google’s platform is actually pretty easy. And to make this even more appealing, you won’t have to worry about managing the hardware.

Let’s walk through the process of deploying a Kubernetes cluster on the Google Cloud Platform.

What You’ll Need

In order to deploy a cluster, you’ll need a Google Cloud Platform account. You can sign up for a free trial, which gives you $300.00 worth of credits. Do note that you will burn through those credits within a month, even if you only deploy the cluster and do nothing with it. With that said, let’s deploy a cluster.

Deploying Your First Cluster

Log into your Google Cloud Platform account. Once you’ve authenticated, you’ll want to head over to the Console, where you control every aspect of your GCP account. From the left sidebar, click Kubernetes Engine > Clusters (Figure 1).

 

Figure 1: The Kubernetes cluster entry in the left navigation.

In the resulting window (Figure 2), click Create Cluster. Since this is your first cluster deployment, the Kubernetes Engine API must be enabled. This can take some time, so be patient.

Figure 2: The Create Cluster button.

In the next window (Figure 3), you must configure your cluster. There are a few options to consider, but since this is your first cluster with the Google Cloud Platform, let’s make it easy. Select Standard Cluster in the left navigation. In the right pane, give the cluster a name, select Zonal and select the zone you wish to deploy the cluster to (from the Zone drop-down).

Figure 3: Configuring your first cluster.

Next, configure the number of nodes you want to add to your cluster. One thing to take into consideration is that the number of nodes you select will add to the cost of the cluster. The more nodes you add, the faster you’ll use up those free credits (or you’ll add to your monthly cost). So select the number of nodes wisely.

Once you’ve decided on how many nodes to add, select the machine type and, if necessary, click Customize to change the amount of memory allocated to each node.

After you’ve completed the customization, click Create. This process will take some time, so be patient. Eventually, your cluster will deploy and you’re almost ready to get to work.

Enabling Command-Line Access

That cluster isn’t much good to you if you don’t have command-line access. After the deployment completes, you’ll see your new cluster listed (Figure 4). Click the Connect button associated with that cluster.

Figure 4: I’ve blanked out some information to protect client privacy, but my cluster is ready to go.

A new window will appear with a gcloud container command (Figure 5). In order to gain command line access (again, from within your Google Cloud Platform account), click Run in Cloud Shell.

Figure 5: Gaining shell access to your cluster.

After clicking Run in Cloud Shell, a new window will appear (Figure 6). In that window click START CLOUD SHELL.

Figure 6: Everything you need to work with your Kubernetes cluster from the command line is there.

Yet another new window will appear (Figure 7). This time it’s a terminal window containing the command you copied earlier. All you have to do here is hit Enter on your keyboard to execute the command.

Figure 7: Running the gcloud container command to access your cluster from the command line.

You should now have the full power of your Kubernetes cluster at your fingertips. You can test to make sure all is ready by issuing the command:

The output of the above command should list all of the nodes you deployed for your cluster.

Your Kubernetes cluster is now ready for you to deploy and scale-out containers.

Gcloud Command

If you’d rather work with your Kubernetes cluster from the Linux command line, you’re in luck, as you can install that command and access your cluster remotely. To do this, you must install the necessary SDK from Google. I’ll demonstrate on a Ubuntu Server 18.04 machine.

First, install the necessary dependencies with the command:

Next, add the Google Cloud SDK URI with the command:

Import the Google Cloud public key with the command:

Update apt with the command:

Finally, install the SDK with the command:

After the installation completes, you’ll need to initialize the SDK with the command:

During the initialization, you’ll be asked to log into your Google Cloud Platform account. You’ll be given a link to open in your browser. Before you click on that link, make sure you’re logged into your GCP account with your default browser. From within the browser, you’ll be given a verification code. Copy that code back in the Linux terminal window and hit Enter. You’ll then be prompted to pick a project to use and then be asked if you want to configure a default Comput Region and Zone. Once the initialization completes, update the installed components with the command:

Finally, you can install components (such as kubectl) with the command:

You can now deploy a cluster to your Google Cloud Platform account with a command like:

Where NAME is a lower case, human-readable name for the cluster, and ZONE is the zone you wish to deploy to.

Get Your Cluster On

And that’s all you need to get your Kubernetes cluster on with the Google Cloud Platform. You now have the ability to manage that cluster either from within your Cloud Platform dashboard or from the Linux command line.

Feature image by Domenic Hoffmann from Pixabay.

A newsletter digest of the week’s most important stories & analyses.

View / Add Comments

Please stay on topic and be respectful of others. Review our Terms of Use.