Git Product home page Git Product logo

kubernetes-cluster-with-ansible's Introduction

Kubernetes Cluster Deployment with Ansible Playbooks

The setup used to test the Ansible Playbooks:

  • Python 3 and Ansible installed on the host machine

    • my host machine is MacOS Catalina
  • 3 VMs (tested in vmware fusion) : 4 gig RAM( 2 gig min), 2 vCPUs, 32 Gig vmDisk

  • Os - Ubuntu Server LTS 18.04

  • The VMs must have internet access

    • master node vm - IP - 10.0.1.201/24
    • worker1 node vm - IP - 10.0.1.211/24
    • worker2 node vm - IP - 10.0.1.212/24
  • Create user ansible on all the vms

  • copy your ssh key on your host machine to the VMs for password-less access

  • On each VM enable 'ansible' user for paswordless sudo:

    • sudo visudo -f /etc/sudoers.d/myoverrides This will open up /etc/sudoers.d/myoverrides file with the default editor Add this line and save.

      ansible ALL=NOPASSWD: ALL

  • You are all set to run the ansible playbooks. Run the playbooks from the within the directory that contains these .yml and hosts file.

    $ ansible-playbook -i hosts kube-dependencies.yml

    $ ansible-playbook -i hosts master.yml

    $ ansible-playbook -i hosts workers.yml

  • Verify the Kubernetes cluster:

Log on to the master node and run the following

  • Check nodes and status of the pods kubectl get nodes kubectl get pods --all-namespaces

  • Deploy ngix kubectl create deployment nginx --image=nginx kubectl expose deploy nginx --port 80 --target-port 80 --type NodePort kubectl get services

exmaple out put of kubectl get service :
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
 kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        13m
 nginx        NodePort    10.110.164.192   <none>        80:30560/TCP   12s

note:  30560 is the port exposed on the worker nodes to access nginx service in this example
nginx_port=30560

To test that everything is working,
visit http://worker_1_ip:nginx_port or http://worker_2_ip:nginx_port
through a browser on your local machine. You will see Nginx’s familiar welcome page.


If you would like to remove the Nginx application, first delete the nginx service from the master node:

kubectl delete service nginx
Run the following to ensure that the service has been deleted:

kubectl get services
You will see the following output:

Output
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP           PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1        <none>                443/TCP        1d
Then delete the deployment:

kubectl delete deployment nginx
Run the following to confirm that this worked:

kubectl get deployments
Output
No resources found.

kubernetes-cluster-with-ansible's People

Contributors

prabhat3107 avatar

Watchers

 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.