DEV Community

Cover image for Single command kubernetes installation on GCP
Manish Bansal
Manish Bansal

Posted on • Originally published at Medium

Single command kubernetes installation on GCP

This is an introduction to my new open source project called 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. 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. 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.

Top comments (3)

Collapse
 
ginigangadharan profile image
Gineesh Madapparambath

Good initiative.
But, why don't you use some automation tools (ansible etc) rather than bash ?
Bash is error prone when doing complex tasks and loops and difficult to validate the results and next step.

Anyway, will see more update on this :)

Collapse
 
manishbansal8843 profile image
Manish Bansal

I agree with you. Ansible would be more appropriate for such task. However, i chose bash because its easy to understand with zero dependency. Here, the task also was pretty simple. People not knowing Ansible would have had to learn it first before understanding those simple bash commands.

Collapse
 
ginigangadharan profile image
Gineesh Madapparambath

Understood. thanks for sharing :)