Coder Social home page Coder Social logo

terraform-ansible-kubernetes's Introduction

Terraform-Ansible-Kubernetes

How to install Kubernetes cluster using Terraform,Ansible and Kubeadm

Build a Kubernetes cluster using Ansible with kubeadm. The goal is easily install a Kubernetes cluster on machines running:

  • Ubuntu 16.04
  • CentOS 7
  • Debian 9

Google cloud SDK needs to be installed on your deployment machine, if your installing for first time then you can run the following command and follow the instruction

gcloud init

Once your set you either create a new project from google cloud console or you can use command line to create a project, I am assuming you have a project created and now lets generate a json file for terraform for authentication

gcloud iam service-accounts create terraform  
gcloud iam service-accounts keys create gce-terraform-key.json --iam-account=terraform@<project_id>.iam.gserviceaccount.com  
gcloud projects add-iam-policy-binding kubernetes-the-hard-way-194619 --member='serviceAccount:terraform@<project_id>.iam.gserviceaccount.com' --role='roles/editor'

Above can also be achieved from google cloud console.

Terraform

  • Deployment enviornment must have terraform installed
  • Latest version can be downloaded from : https://www.terraform.io/
  • Terraform code is for Google Cloud, this will provision 1 Master node and 2 Worker node
  • Clone the directory and run the following command:
    terraform init
    terraform plan
    terraform apply
    

Ansible

  • Deployment environment must have Ansible 2.4.0+

  • Make sure you specify private key path to make ssh connection to instances, I am assuming that you already have added your SSH key in googlecloud console, use the same username for making conncetion with specifying the private key

  • Modify the host.ini, add the Master and Worker node ip which you will the get from terraform output

    [master]
    35.202.154.208
    [node]
    35.192.64.78
    35.192.210.4
    [kube-cluster:children]
    master
    node
    [all:vars]
    ansible_connection=ssh
    ansible_ssh_user=sanjay.naikwadi
    ansible_ssh_private_key_file=<path_to_file>
    
  • Modify group_vars/all.yml, select the flannel or calico, I have used flannel

Once everything is set lets run the playbook

$ ansible-playbook site.yaml

Once your Install is successful, let grab a admin.conf file and verify the cluster status, I have kubectl installed on my development machine

scp -i <private_key.pem> [email protected]:/etc/kubernetes/admin.conf .
$kubectl get nodes
NAME      STATUS    ROLES     AGE       VERSION
cont-1    Ready     master    47m       v1.11.1
work-1    Ready     <none>    43m       v1.11.1
work-2    Ready     <none>    43m       v1.11.1

terraform-ansible-kubernetes's People

Contributors

sanjaynaikwadi avatar

Watchers

James Cloos avatar  avatar

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.