Giter Site home page Giter Site logo

vagrant-k8s-centos8's Introduction

Kubernetes on Centos with Vagrant

Goal was creating IaC for booting k8s cluster on local machine.

Getting Started

These instructions will get you a copy of the project up and running on your local machine.

Prerequisites

Install Vagrant from Hashicorp and Oracle Virtualbox

for Virtualbox version > 6.0 you might to change few settings, because Vagrant 2.2.6 is not working with newest 6.1 Virtualbox for example: https://blogs.oracle.com/scoter/getting-vagrant-226-working-with-virtualbox-61-ga

add to file: 
vagrant/embedded/gems/2.2.6/gems/vagrant-2.2.6/plugins/providers/virtualbox/driver/meta.rb
  "6.1" => Version_6_1,
at end of "driver_map" list

create vagrant/embedded/gems/2.2.6/gems/vagrant-2.2.6/plugins/providers/virtualbox/driver/version_6_1.rb

add to file: 
vagrant/embedded/gems/2.2.6/gems/vagrant-2.2.6/plugins/providers/virtualbox/plugin.rb
      autoload :Version_6_1, File.expand_path("../driver/version_6_1", __FILE__)
at the end of "module Driver" section

Installing and Running

Just clone repository in your Vagrant dedicated directory:

git clone https://github.com/djsuszi/vagrant-k8s-centos8.git

Initialize vagrant Centos/8 file.

vagrant init centos/8 \
  --box-version 1905.1

Check your hosts and VM settings in "Vagrantfile" You can set number of CPUs, Memory, hostname and IP (you should choose /24 network)

cluster = {
  "host1" => { :ip => "192.168.77.101", :cpus => 4, :mem => 2048 },
  "host2" => { :ip => "192.168.77.102", :cpus => 4, :mem => 2048 },
  "host3" => { :ip => "192.168.77.103", :cpus => 4, :mem => 2048 },
  "host4" => { :ip => "192.168.77.104", :cpus => 4, :mem => 1024 }
}

Top one will be always MASTER for Kubernetes, others will join to it.

You need to have access to ssh-keygen because at first start you will have generated 2048 bytes RSA ssh key to access root account: private vagrant_root_sshkey public vagrant_root_sshkey.pub Public key is automated pasted to authorized_keys on all your new VMs.

You can use static root password if you prefere, just uncomment in vagrant_build.sh Task: Setting Root Password and change worker task 1 to installed use sshkey.

and basic commands: start / halt / destroy

vagrant up
vagrant halt
vagrant destroy -f

Running some tests

You can run included basic tests for K8S cluster.

simple replication controller

Just run from vagrant account in VM:

kubectl apply -f /vagrant/vagrant_busybox_replica.yaml
kubectl get nodes -o wide
kubectl get pods --all-namespaces -o wide --show-labels
kubectl get rs
kubectl get pods --no-headers=true|cut -f 1 -d " " | xargs  kubectl delete pod
kubectl delete pod $(kubectl get pods -o wide|grep CrashLoopBackOff|cut -f 1 -d' '|xargs)

simple deploy scenario

Just run from vagrant account in VM prepared script:

sh /vagrant/vagrant_busybox_deploy_test.sh

Security

by default firewall and selinux are disabled (it's just vagrant local machine Lab :))

On Production or outside envirement you should take care of Security, at first try to do some hardening !!

You can make multimaster K8S, but you need at least 3 master nodes to setup proper etcd cluster.

Faster vagrant build up

Only first Centos VM is getting lots of data from outside repositories. Next VMs are sharing downloaded RPM and docker images from first Master machine. To make lower number or request there is "--nogpg" flag for yum and dnf (you can remove it from vagrant_build.sh script).

Even fastest build up :)

After first running MASTER, you can prepare cache files and keep it in your Vagrant foler in "cache" directory

tar -czvf /vagrant/cache/dnf-cache.tar.gz /var/cache/dnf/
docker image ls -q|while read image; do docker save $image|bzip2|pv > /vagrant/cache/docker-${image}.bz2 ; done

and then scp all files from VM directory /var/cache/ to folder with your Vagrantfile

mkdir ./cache
scp -i vagrant_root_sshkey root@MASTER_IP:/vagrant/cache/* ./cache

Contributing

You can fork and push some bugs if you want.

Acknowledgments

  • Hat tip to anyone whose idea was used
  • Hashicorp for Vagrant features
  • Brian Foks & Chet Ramey for Bash

Additional help

TODO

Multi master K8s setup NFS between VMs move install commands to Ansible playbook you can move install script to Vagrantfile between "SHELL"

License

This project is licensed under the MIT License - see the LICENSE.md file for details

vagrant-k8s-centos8's People

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.