How to setup simple Kubernetes Cluster with GCE

Chapter 1: Introduction

As an Site Reliability Engineer in the modern software company, I can’t never keep my hand from tinkering and operating Kubernetes clusters. If you’re a junior like me, you’ll mostly doing operation task with Kubernetes like creating new deployment, make sure configmap variable values are correct, or investigating why this CRD is not working. I rarely have an opportunity to deploy a kubernetes cluster from beginning. So in this article I want to show you how I deploy my own staging kubernetes cluster.

We’ll start with the tools needed to spin up a minimal Kubernetes cluster. I will deploy a Kubernetes cluster in Google Cloud Platform using Compute Engine Instances. More or less we need these resources in Google Compute Engine:

  1. A VPC with at least one subnet.
  2. A Public IP address for control plane node.
  3. One Router and one NAT in the same region.
  4. Several security groups.
  5. An Instance template.
  6. One Compute Engine as control plane node.
  7. Two Compute Engine as regular nodes.

Chapter 2: Prepare Infrastructure Resources

To setup the infrastructure resources, we’ll use terrafrom and terragrunt masked as task subcommand as our Infrastructure as Code tool. You can see the code repository in here.

Before applying infra resources in this folder, please read 000-main-infrastructure.

Task subcommand you'll need to execute:

# Plan or Dry run all terraform manifest
task plan-all -- 001-how-to-setup-simple-kubernetes-cluster-with-gce/infrastructure
# Apply all terraform manifest. Will create all infra resources
task apply-all -- 001-how-to-setup-simple-kubernetes-cluster-with-gce/infrastructure
# Destroy all infra resources. Will delete all resource. Use with cautions!
task destroy-all -- 001-how-to-setup-simple-kubernetes-cluster-with-gce/infrastructure

Chapter 3: Bootstrap Kubernetes Cluster

Let’s start with your control plane or master node.

Chapter 4: Access the Kubernetes Cluster

After you kubernetes cluster is ready, you can get your kubeconfig file in ~/.kube/config file. Copy that config file and you can access your kubernetes cluster from you local device. Don't forget to change the internal control plane IP to the external one.

--  server: https://CONTROL_PLANE_INTERNAL_IP:6443
++  server: https://CONTROL_PLANE_EXTERNAL_IP:6443

References

[1] Install using the apt repository | Docker Docs

[2] Forwarding IPv4 and letting iptables see bridged traffic

[3] Configuring the systemd cgroup driver

[4] Initializing your control-plane node

[5] Weave Kubernetes Addon

[6] Installing Weave

[7] Taint Effects

[8] Installation Using Helm

Tags: