From 9269a0d165393f27e2a5d65c34858d36979cb285 Mon Sep 17 00:00:00 2001 From: Felipe Date: Sat, 21 Mar 2020 15:25:53 -0300 Subject: [PATCH] Initial Commit --- Makefile | 13 ++++++++++++ README.md | 27 +++++++++++++++++++++++ Vagrantfile | 48 +++++++++++++++++++++++++++++++++++++++++ configEnv.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ startEnv.sh | 16 ++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 Makefile create mode 100644 Vagrantfile create mode 100644 configEnv.sh create mode 100644 startEnv.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f8168cb --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +up: + @vagrant up --provider virtualbox + @vagrant ssh + +ssh: + @vagrant ssh + +down: + @vagrant halt + +destroy: + @vagrant destroy -f + diff --git a/README.md b/README.md index 3c98020..eefa95e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,29 @@ # k8s-all-in-one Create a All-in-one Kubernetes Cluster. + + +# Subir o kubernetes: + Acesse a raiz do repositorio e rode: + +``` + make up + +``` + +ou + +``` + vagrant up --provider virtualbox + +``` + +# Links + +Para Utilizar é necessario ter instalado: + +``` + Vagrant: https://www.vagrantup.com/ + + VirtualBox: https://www.virtualbox.org/ + +``` diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..5b586d1 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,48 @@ +Vagrant.configure("2") do |config| + + config.vm.box = "centos/7" + config.vm.hostname = "master-k8s" + + config.vm.network "forwarded_port", guest: 443, host: 443, host_ip: "127.0.0.1" + config.vm.network "forwarded_port", guest: 30800, host: 8080, host_ip: "127.0.0.1" + # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + + # Create a private network, which allows host-only access to the machine using a specific IP. + #config.vm.network "public_network" + config.vm.network "private_network", ip: "192.168.1.10" + + #config.vm.synced_folder ".", "/vagrant" + + config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + vb.cpus = "4" + vb.memory = "4096" + end + + # Disable selinux + config.vm.provision "shell", inline: "setenforce 0" + $script = <<-'SCRIPT' + setenforce 0 + sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config + SCRIPT + config.vm.provision "shell", inline: $script + + + # Disable swap + config.vm.provision "shell", inline: "swapoff -a" + $script = <<-'SCRIPT' + swapoff -a + sed -i.bak '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab + SCRIPT + config.vm.provision "shell", inline: $script + + #Primeira Vez + config.vm.provision :shell, privileged: true, path: "configEnv.sh" + + #Sempre ao Iniciar + config.vm.provision :shell, privileged: true, run: "always", path: "startEnv.sh" + +end \ No newline at end of file diff --git a/configEnv.sh b/configEnv.sh new file mode 100644 index 0000000..457f2bb --- /dev/null +++ b/configEnv.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +echo "Starting Instalarion of K8s All-in-One" + +cat < /etc/sysctl.d/k8s.conf +net.bridge.bridge-nf-call-ip6tables = 1 +net.bridge.bridge-nf-call-iptables = 1 +EOF +sysctl --system + +echo "Install Docker..." +curl -fsSL https://get.docker.com | bash + +systemctl enable --now docker +systemctl status docker | grep "Active:" +usermod -aG docker ${USER} + + +echo "Install K8s..." +cat < /etc/yum.repos.d/kubernetes.repo +[kubernetes] +name=Kubernetes +baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 +enabled=1 +gpgcheck=1 +repo_gpgcheck=1 +gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg +EOF + +yum install -y kubelet kubeadm kubectl git --disableexcludes=kubernetes + +systemctl enable kubelet + +echo "Pull Images K8s..." +kubeadm config images pull + +kubeadm init + +mkdir -p /home/vagrant/.kube +cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config +chown vagrant:$(id -g) /home/vagrant/.kube/config + +export KUBECONFIG=/etc/kubernetes/admin.conf + +source <(kubectl completion bash) +echo "source <(kubectl completion bash)" >> /home/vagrant/.bashrc + +echo "Apply Network Polices K8s..." +kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')" + +kubectl taint nodes --all node-role.kubernetes.io/master- + +echo "Get Nodes K8s..." +kubectl get nodes + +echo "Cloning Example" +git clone -b k8s https://github.com/felipeagger/apinodejs.git + +echo "Get All namespaces Default" +kubectl get all \ No newline at end of file diff --git a/startEnv.sh b/startEnv.sh new file mode 100644 index 0000000..38a4781 --- /dev/null +++ b/startEnv.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +echo "Status Services" + +export KUBECONFIG=/etc/kubernetes/admin.conf + +echo "Docker" +systemctl status docker | grep "Active:" +echo "K8s" +systemctl status kubelet | grep "Active:" + +echo "Cluster Info" +kubectl cluster-info + +echo "Get All" +kubectl get all --all-namespaces