Skip to main content

Kubernetes Can be Cheap - GKE Lab Setup

·4 mins

One thing that frustrated me a lot when trying to skill up in Kubernetes was seeing just how expensive it was for a managed Kubernetes solution. Yes, you can host it yourself at home using Kind or Minikube, but that just didn’t work for the type of stuff I wanted to do. I wanted a real cluster. Just the management plane alone for Amazon EKS is $73 a month though, and AKS isn’t much better either!

I needed something cheaper. Unfortunately, that meant going to the ‘dark side’ in GKE. I have to admit though, it has converted me somewhat to actually liking Google’s Cloud offerings.

So here’s the deal, you get a free control plane for your first cluster, and you get to use spot VM’s that can get incredibly cheap. I’d recommend looking at your region specifically on this pricing calculator. For the london region as it stands, the best value for my use case is the n2-standard-2 since that gets you 2 vCPU’s and 8GB RAM for only $9 a month. That rivals those “cheap VPS” type of companies!

Storage is a bit more pricy since you pay 12c per GB if you use Balanced provisioned space. That’s also per node , so it does quickly add up. If you’re not using much storage, or using an external storage solution, you should be all good.

Setup #

Now for the setup. I’m assuming here that you’ve already created a google cloud account. Be sure to take advantage of the free trial money you get!

Usually I recommend doing this kind of thing in the CLI, but this time, head over to the Google Cloud Console -> Kubernetes Engine and click on Create.

Cluster Choice

You’ll then see this choice. In this case, we’re picking Standard.

Name the cluster what you’d like. Keep the location type to Zonal, and I’d recommend changing the Version to the latest on the Regular Channel.

Node Pools

You’ll want to click on ‘default-pool’ and this’ll let you configure how many nodes you want. This is something completely up to you. If you’re going the absolute cheapest route, you can pick one node. I’d recommend at least two though, even if that means you have to then halve the size you go with due to cost constraints. It’s up to you whether you want to use Cluster Autoscaling too. I personally do, but it’s up to you. You’ll want to read up on my scaling article first though so you know what you’re getting yourself into.

Keep the rest the same and then click on “Nodes” on the left hand side.

Node Choice

Now this is where you can setup the specifics of each node. For machine type, you’ll want to look at the pricing calculator I linked above, and pick the cheapest option that gives the resources you’d like to have. For boot disk, I personally use 50GB balanced persistent disks. You can use standard ones instead, but they’re really slow, and the SSD’s are a bit pricy at nearly double the price of balanced. Now the very important part here. You see that option that says “Enable nodes on spot VMs”? Click that.

Now yes it does mean that your nodes can get shut off at any time and you only get around 25 seconds notice, that is also nearly enough time for a node to get spun up and initialized, which GKE will do automatically for you. If you have two nodes, you’ll almost never notice this even if you’re actively running some kubectl commands.

Don’t worry if you get any of this wrong, you can add a new node pool and then remove an old one.

The only other thing I enable is Cost allocation in the Features section. This’ll give you a cost rundown by namespace as well, and can be a handy visualizer at times as well. It’s not necessary though, so feel free to skip this bit.

You can click on create and make yourself a cup of tea. When you’re back, you should see your new cluster! You can then click on it, and then hit ‘Connect’ (or the 3 dots at the top and then connect depending on window size).

You can either run the connect command using GCP’s Cloud Shell, or you can download gcloud and kubectl yourself. For kubectl , check out the guide for MacOS , Linux or Windows . For gcloud, check out the guide from Google’s documentation.

When you’ve run that command, you can then run kubectl on the cluster just like any other managed kubernetes solution!

The great thing with using a GKE cluster is that you can take advantage of their brilliant documentation. You can check out this example which’ll show you how to deploy an application to be visible on the internet. It took me like 10 minutes to follow that as someone who’s never used GKE, wonderful!