Code Monkey home page Code Monkey logo

ansible-kubernetes's Introduction

ansible-kubernetes

This project is a good starting point to learn how to install and configure a Kubernetes cluster.

  • VM provisionning is fueled by Vagrant.
  • Cluster configuration by Ansible
  • Kubernetes networking by Calico
  • Kubernetes automatic and dynamic routing by Traefik

Quickstart

Install required softwares

# add virtualbox repository
sudo wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add - \
&& sudo echo "deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib" > /etc/apt/sources.list.d/virtualbox.list

# add vagrant repository
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - \
&& sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"

# install softwares
sudo apt update \
&& sudo apt install -y virtualbox-6.1 ansible vagrant \
&& export VAGRANT_DEFAULT_PROVIDER=virtualbox \
&& vagrant plugin install vagrant-vbguest

# install virtualbox extension pack
wget https://download.virtualbox.org/virtualbox/6.1.26/Oracle_VM_VirtualBox_Extension_Pack-6.1.26.vbox-extpack \
&& sudo VBoxManage extpack install --replace Oracle_VM_VirtualBox_Extension_Pack-6.1.26.vbox-extpack

Before Vagrant uping, this Vagrantfile will set up 3 VM, using 2 vCPU and 2Gio vRAM each, be sure you can carry that.

vagrant up

This will download vagrant box Ubuntu Focal and install a kubernetes cluster. With 1 master and 2 nodes.

When done, you may want to use kubectl commands from your host. So copy the generated kubeconfig to your home path :

cp kubernetes-setup/kubeconfig ~/.kube/config
kubectl get nodes
# \o/ enjoy

And for future node joining the cluster, the join command is available in kubernetes-setup/join-command

Reverse Proxying with Traefik

To install and configure Traefik v2.5 using helm:

cd helm/traefik/
helm install traefik .

Traefik dashboard

To install the dashboard:

# add this line to /etc/hosts
192.168.56.10 traefik.local
# execute
kubectl apply -f files/traefik/dashboard.yaml

Then browse to http://traefik.local:/dashboard/

Find this auto-generated port in kube-system namespace looking at traefik service external port.

Without installing the dashboard, you can access it with port-forward:

kubens kube-system
kubectl port-forward $(kubectl get pods --selector "app.kubernetes.io/name=traefik" --output=name) 9000:9000

Then browse to http://localhost:9000/dashboard/

Example app

Everything should work, but running your custom docker image is a must have. Use kubectl apply to launch yaml configurations files in the files/app folder. It will use a simple nodeJs docker image with 2 instances reverse proxyed by traefik \o/

Edit /etc/hosts:

192.168.56.10 test.local traefik.local

Then browse test.local:

Find this auto-generated port in kube-system namespace looking at traefik service external port.

Dynamic provisionning volume

When it comes to StateFull apps. I like this feature provided by (Rancher team)[https://github.com/rancher/local-path-provisioner]

kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml

Add storageClassName: local-path property to your PersistentVolumeClaims yaml file and let the automation work.

Install more distributed systems

You will find many charts in the helm folder that are pre configured, more documentation here.

ansible-kubernetes's People

Contributors

r0mdau 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.