Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,60 @@
# k8s-cluster
# Kubernetes cluster

A vagrant script to deploy a Kubernetes cluster.

## Requirements
* Vagrant
* Virtualbox

## How to Deploy
Download the code and execute the following command in the same folder as the Vagrantfile:

```
vagrant up
```

It will create 3 nodes (1 master and 2 workers). If more than 2 nodes are
required, you can add more by editing the servers array in the Vagrantfile.
Also, the provision create and run nginx service on the cluster.

This process will take some time, so go grab a coffee :)

After all deployment, you should see a list with all running pods in all
namespaces.


## Testing
Get in to the mater node and run any kubectl command.

```
vagrant ssh k8s-master
kubectl get nodes
```

This last command should show the nodes status.

```
vagrant@k8s-master:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 5m51s v1.15.3
k8s-node1 Ready <none> 3m41s v1.15.3
k8s-node2 Ready <none> 85s v1.15.3
```

There is a python script on master vm's home that shows all the pods running. This
script is executed after the ```vagrant up```.

```
cd pyclient
python3 main.py
```


Also, you may open a browser and put 192.168.50.x:30180 to see nginx running.
Where x may be 10, 11 or 12 as defined on node's IPs.

## Cleanup
```
vagrant halt
vagrant destroy -f
```
58 changes: 58 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- mode: ruby -*-
servers = [
{
:name => "k8s-master",
:type => "master",
:box => "ubuntu/xenial64",
:ip => "192.168.50.10",
:mem => "2048",
:cpu => "2"
},
{
:name => "k8s-node1",
:type => "node",
:box => "ubuntu/xenial64",
:ip => "192.168.50.11",
:mem => "1024",
:cpu => "2"
},
{
:name => "k8s-node2",
:type => "node",
:box => "ubuntu/xenial64",
:ip => "192.168.50.12",
:mem => "1024",
:cpu => "2"
}
]

Vagrant.configure("2") do |config|
servers.each do |opts|
config.vm.define opts[:name] do |config|
config.vm.box = opts[:box]
config.vm.hostname = opts[:name]
config.vm.network "private_network", ip: opts[:ip]

config.vm.provider "virtualbox" do |v|
v.name = opts[:name]
v.customize ["modifyvm", :id, "--memory", opts[:mem]]
v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
end
config.vm.provision "shell", path: "scripts/configurebox.sh"

if opts[:type] == "master"
config.vm.provision "shell", path: "scripts/configuremaster.sh"
config.vm.provision "file", source: "pyclient", destination: "pyclient"
else
config.vm.provision "shell", path: "scripts/configurenode.sh"
end

# trigger command on master after the last node is up
config.trigger.after :up do |t|
t.only_on = "k8s-node2"
t.info = "Running after the last node is up"
t.run = {inline: "vagrant ssh k8s-master -c 'pip3 install -r pyclient/requirements.txt && python3 pyclient/main.py'"}
end
end
end
end
Loading