Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe committed Mar 21, 2020
1 parent 3daffce commit 9269a0d
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
up:
@vagrant up --provider virtualbox
@vagrant ssh

ssh:
@vagrant ssh

down:
@vagrant halt

destroy:
@vagrant destroy -f

27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/
```
48 changes: 48 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions configEnv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash

echo "Starting Instalarion of K8s All-in-One"

cat <<EOF > /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 <<EOF > /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
16 changes: 16 additions & 0 deletions startEnv.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9269a0d

Please sign in to comment.