Giter VIP home page Giter VIP logo

k8s-terraform's Introduction

Terraform template to create k8s cluster on GCP

This repository contains terraform code and associated scripts to create k8s cluster on GCP. It creates following resources:-

  • VPC Network
  • Associated Subnet
  • Firewall
  • Master Node
  • "N" number of worker nodes
  • "gvisor" based worked node

Follwing variables can be passed

  • GCP Project name
  • Cloud region for cluster creation
  • Service and POD CIDR's
  • Network plugin - calico and weavenet

Preprequisite

I have tested it on Ubuntu18 desktop, if anybody tests it on windows let me know. I will update

Have a GCP account and log in to it. Whichever account below comand is using will be used by the terraform (projects can be different)

gcloud compute instances list

Usage

Create cluster without gvisor

terraform init
terraform apply -auto-approve

Then login to master and wait for install to finish (takes about 1-2 mins). Last of the the log will sate deployment completed.

gcloud compute ssh k8s-master
cat /var/log/kubeadm-init.log

Copy kubeadm join command from the log and execute it on worker nodes (and gvisor node if created)

On worker node (remeber sudo)

sudo kubeadm join 10.1.0.4:6443 --token xxxxxxxxxxxxxxxxxx \
    --discovery-token-ca-cert-hash yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

Customize deployment with variables

You can choose the flags and values based on definition in "variables.tf" file.

terraform init
terraform   apply  -var="gvisor=y" -var="num_of_workers=2" -var="cni_provider=calico" -auto-approve

Providing inputs via file

You can create file terraform.tfvars, place it in root directory, and provide values in it, like below

gcp_project="yourproject"
ngvisor="y"
num_of_workers=2
cni_provider="calico"

you can then run terraform command as below

terraform apply -auto-approve

Deleting the resources

Instead of apply use destroy command like below

terraform destroy  -auto-approve
terraform destroy  -var="gvisor=y" -var="num_of_workers=2" -var="cni_provider=calico" -auto-approve

Advanced Usage

Adding nodes after initial creation

Below command will add 2 extra nodes after you have created initial cluster

terraform apply -var="num_of_workers=3" -auto-approve

If below command is executed after the above command, it will take out 2 nodes from cluster (make sure you know what you are doing)

terraform apply -var="num_of_workers=1" -auto-approve

Adding gvisor and removing it

Add gvisor node to existing cluster

terraform apply -var="gvisor=y" -auto-approve

Remove gvisor node from existing cluster (Do drain and delete node)

terraform apply -var="gvisor=N" -auto-approve

k8s-terraform's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.