Skip to content

Commit

Permalink
Merge pull request #1 from dj-wasabi/specify-k8s-version
Browse files Browse the repository at this point in the history
Specify K8s version;Rename of nodes;Add some variables;Updated documentation
  • Loading branch information
dj-wasabi authored Oct 28, 2020
2 parents c45feeb + 15457b9 commit f6d2831
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 32 deletions.
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
# Documentation
# Vagrant Kubernetes

Table of Content
* [Requirements](#requirements)
* [Setup](#setup)
* [Kubernetes version](#kubernetes-version)
* [Starting](#starting)
* [Credits](#credits)

A small playground to experiment or play with Kubernetes on multiple Vagrant Ubuntu `ubuntu/bionic64` instances. So do not use this as a base for production like deployments (Kubespray for example).

## Requirements

Please make sure the following is installed before using this repo:

* Ansible;
* Vagrant;
* VirtualBox;

## Setup

Default the following is started/installed:

* 1 Control node;
* 2 Worker nodes;

Each node has 2 CPU's configured with each 2GB of RAM. You can change this to your needs by updating the `Vagrantfile`.

## Kubernetes version

Kubernetes version 1.19.3 which can be changed in the `Vagrantfile` by looking for the `k8s_version` in the `ansible.extra_vars` property.

```ruby
ansible.extra_vars = {
...
k8s_version: "1.19.3",
ansible_python_interpreter: "/usr/bin/python3",
}
```

## Starting

Once you are ready, run the following to start everything:

```sh
vagrant up
```

Once booted, use the following command to logon to the control node:

```sh
vagrant ssh control
```

You should be able to run `kubectl get nodes` now.

## Credits

Combination of code https://graspingtech.com/create-kubernetes-cluster/ and some custom things.
27 changes: 15 additions & 12 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,32 @@ Vagrant.configure("2") do |config|
v.cpus = 2
end

config.vm.define "master" do |master|
master.vm.box = IMAGE_NAME
master.vm.network "private_network", ip: "10.10.1.10"
master.vm.hostname = "master"
config.vm.define "control" do |control|
control.vm.box = IMAGE_NAME
control.vm.network "private_network", ip: "10.10.1.10"
control.vm.hostname = "control"

master.vm.provision "ansible" do |ansible|
ansible.playbook = "master-playbook.yml"
control.vm.provision "ansible" do |ansible|
ansible.playbook = "control-playbook.yml"
ansible.extra_vars = {
node_ip: "10.10.1.10",
k8s_version: "1.19.3",
ansible_python_interpreter: "/usr/bin/python3",
}
end
end

(1..N).each do |i|
config.vm.define "node-#{i}" do |node|
node.vm.box = IMAGE_NAME
node.vm.network "private_network", ip: "10.10.1.#{i + 10}"
node.vm.hostname = "node-#{i}"
node.vm.provision "ansible" do |ansible|
ansible.playbook = "node-playbook.yml"
config.vm.define "worker-#{i}" do |worker|
worker.vm.box = IMAGE_NAME
worker.vm.network "private_network", ip: "10.10.1.#{i + 10}"
worker.vm.hostname = "worker-#{i}"
worker.vm.provision "ansible" do |ansible|
ansible.playbook = "worker-playbook.yml"
ansible.extra_vars = {
control_node_ip: "10.10.1.10",
node_ip: "10.10.1.#{i + 10}",
k8s_version: "1.19.3",
ansible_python_interpreter: "/usr/bin/python3",
}
end
Expand Down
24 changes: 14 additions & 10 deletions master-playbook.yml → control-playbook.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
- hosts: all
become: true
tasks:

tasks:
- name: "Update hosts file"
lineinfile:
path: /etc/hosts
line: '{{ item }}'
with_items:
- '10.10.1.10 master'
- '10.10.1.11 node-1'
- '10.10.1.12 node-2'
- '10.10.1.13 node-3'
- '{{ node_ip }} control'
- '10.10.1.11 worker-1'
- '10.10.1.12 worker-2'
- '10.10.1.13 worker-3'

- name: Make sure group wheel is not in the sudoers configuration
lineinfile:
Expand Down Expand Up @@ -83,9 +83,9 @@
- name: Install Kubernetes binaries
apt:
name:
- kubelet
- kubeadm
- kubectl
- kubelet={{ k8s_version }}-00
- kubeadm={{ k8s_version }}-00
- kubectl={{ k8s_version }}-00
- helm
- etcd-client
state: present
Expand All @@ -105,7 +105,7 @@
state: restarted

- name: Initialize the Kubernetes cluster using kubeadm
command: kubeadm init --apiserver-advertise-address="10.10.1.10" --apiserver-cert-extra-sans="10.10.1.10" --node-name master --pod-network-cidr=192.168.0.0/16
command: kubeadm init --apiserver-advertise-address="{{ node_ip }}" --apiserver-cert-extra-sans="{{ node_ip }}" --node-name control --pod-network-cidr=192.168.0.0/16
when: installed is changed

- name: Create .kube folder
Expand All @@ -131,6 +131,10 @@
become: false
command: kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

- name: Bash autocompletion
become: false
shell: kubectl completion bash >> ~/.bashrc

- name: Generate join command
shell: kubeadm token create --print-join-command 2>/dev/null > /tmp/join
register: join_command
Expand All @@ -145,4 +149,4 @@
- name: docker status
service:
name: docker
state: started
state: started
18 changes: 9 additions & 9 deletions node-playbook.yml → worker-playbook.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
- hosts: all
become: true
tasks:

tasks:
- name: "Update hosts file"
lineinfile:
path: /etc/hosts
line: '{{ item }}'
with_items:
- '10.10.1.10 master'
- '10.10.1.11 node-1'
- '10.10.1.12 node-2'
- '10.10.1.13 node-3'
- '{{ control_node_ip }} control'
- '10.10.1.11 worker-1'
- '10.10.1.12 worker-2'
- '10.10.1.13 worker-3'

- name: Make sure group wheel is not in the sudoers configuration
lineinfile:
Expand Down Expand Up @@ -73,9 +73,9 @@
- name: Install Kubernetes binaries
apt:
name:
- kubelet
- kubeadm
- kubectl
- kubelet={{ k8s_version }}-00
- kubeadm={{ k8s_version }}-00
- kubectl={{ k8s_version }}-00
state: present
update_cache: yes

Expand Down Expand Up @@ -105,4 +105,4 @@
- name: docker status
service:
name: docker
state: started
state: started

0 comments on commit f6d2831

Please sign in to comment.