Single command kubernetes installation on GCP
Tags: kubernetes, gcp, opensource, github
Published: 2020-03-01 07:07:09

This is an introduction to my new open source project called [cloud-k8s-cluster](https://github.com/manishbansal8843/cloud-k8s-cluster). The purpose of this project is to automate the workflow of multi-node kubernetes cluster installation on bare metal VMs. The target is to extend this project to various cloud service providers. However, as of now, this project only supports GCP.

**Motivation**: You must be thinking, in the world of managed k8s services like GKE, AKS etc, why would one need to install it on bare metal VMs. Plus, if someone really wants to install k8s for development purposes, one may use minikube for it. Well my motivation behind this project is from purely learning perspective.

It has been really quite some time to me that I have been using k8s at my work place. Further, I am quite interested in exploring its source to see all the magic behind it. However, the biggest roadblock to my endeavor is that I really do not get to see the bare bones of it. No doubt, documentation and the other literature present on the internet is amazing. But believe me, if you actually want to learn various intricacies of the system, you should actually try installing it on the physical machines. And once it is installed, you can look at the actual beauty. Various routing table rules to see how networking is implemented. How is k8s able to implement cluster IPs to implement services by using iptables. Well I am going way ahead, but I guess you got the point.

Now, to install kubernetes for a beginner is not a trivial task. There are various caveats mentioned in the [documentation](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/). If you miss one tiny detail, you could easily mess up the installation. Further, doing all this on a cloud machine (which off course involves money), involves some additional steps which are unique to each service provider. Hence, I created this project which helps me install a multi-node kubernetes cluster within 5 minutes and then work on it for couple of hours and then tear it down which costs me only few cents.

This whole project is present on [Github](https://github.com/manishbansal8843/cloud-k8s-cluster). All of you are welcome to fork or contribute to it. Also, please don’t forget to give it a star if you liked it. :)

Now that I have covered the WHAT part of the project, let’s see the HOW part of it.

**How to install a 3 node cluster on GCP**

1. First go to GCP console and open a cloud shell.
2. If you are a free user, create a project for yourself or use an existing project. For paid users, this step is not required.
3. Clone this git repository in home directory.

    `cd ~ && git clone https://github.com/manishbansal8843/cloud-k8s-cluster.git && cd cloud-k8s-cluster`

4. Execute install.sh script with following parameters if you have an existing project.

    `./install.sh NUM_OF_NODES=3 GCP_PROJECT_NAME=<project-name>`

    Or if you want to create a new project all together, just remove the GCP_PROJECT_NAME parameter from the command.

    `./install.sh NUM_OF_NODES=3`

5. And that’s it. This will install a 3 node cluster on GCP with kubectl configured on master node.