Skip to content

Commit bfbbfe3

Browse files
committed
Add Kubernetes cluster example for chapter 13.
1 parent 14c0023 commit bfbbfe3

File tree

8 files changed

+619
-0
lines changed

8 files changed

+619
-0
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ env:
3838
- playbook: jenkins.yml
3939
distro: ubuntu1604
4040

41+
# TODO: Not easy to test in CI at this time.
42+
# - playbook: kubernetes.yml
43+
# distro: debian9
44+
4145
# TODO: Not easy to test in CI at this time.
4246
# - playbook: lamp-infrastructure.yml
4347
# distro: ubuntu1604

kubernetes/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Ansible-based Kubernetes cluster example
2+
3+
This is an example Kubernetes cluster built and managed with Ansible. The example is explained in more detail in Chapter 13 of [Ansible for DevOps](https://www.ansiblefordevops.com/).
4+
5+
## Quick Start Guide
6+
7+
### 1 - Install dependencies (VirtualBox, Vagrant, Ansible)
8+
9+
1. Download and install [VirtualBox](https://www.virtualbox.org/wiki/Downloads).
10+
2. Download and install [Vagrant](http://www.vagrantup.com/downloads.html).
11+
3. [Mac/Linux only] Install [Ansible](http://docs.ansible.com/intro_installation.html).
12+
13+
Note for Windows users: *This guide assumes you're on a Mac or Linux host. Windows hosts are unsupported at this time.*
14+
15+
### 2 - Build the Virtual Machine
16+
17+
1. Download this project and put it wherever you want.
18+
2. Open Terminal, cd to this directory (containing the `Vagrantfile` and this REAMDE file).
19+
3. Run `ansible-galaxy install -r requirements.yml` to install required Ansible roles.
20+
4. Type in `vagrant up`, and let Vagrant do its magic.
21+
22+
Note: *If there are any errors during the course of running `vagrant up`, and it drops you back to your command prompt, just run `vagrant provision` to continue building the VM from where you left off. If there are still errors after doing this a few times, post an issue to this project's issue queue on GitHub with the error.*
23+
24+
### 3 - Configure your host machine to access the VM.
25+
26+
1. [Edit your hosts file](http://www.rackspace.com/knowledge_center/article/how-do-i-modify-my-hosts-file), adding the line `192.168.84.3 cluster.k8s.test` so you can connect to the VM.
27+
2. Open your browser and access [http://cluster.k8s.test](http://cluster.k8s.test).
28+
29+
## Notes
30+
31+
- To shut down the virtual machine, enter `vagrant halt` in the Terminal in the same folder that has the `Vagrantfile`. To destroy it completely (if you want to save a little disk space, or want to rebuild it from scratch with `vagrant up` again), type in `vagrant destroy`.
32+
33+
## About the Author
34+
35+
This project was created by [Jeff Geerling](https://www.jeffgeerling.com/) as an example for [Ansible for DevOps](https://www.ansiblefordevops.com/).

kubernetes/Vagrantfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
VAGRANTFILE_API_VERSION = "2"
5+
6+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
7+
config.vm.box = "geerlingguy/debian9"
8+
config.ssh.insert_key = false
9+
config.vm.provider "virtualbox"
10+
11+
config.vm.provider :virtualbox do |v|
12+
v.memory = 1024
13+
v.cpus = 1
14+
v.linked_clone = true
15+
end
16+
17+
# Define three VMs with static private IP addresses.
18+
boxes = [
19+
{ :name => "master", :ip => "192.168.84.2" },
20+
{ :name => "node1", :ip => "192.168.84.3" },
21+
{ :name => "node2", :ip => "192.168.84.4" },
22+
]
23+
24+
# Provision each of the VMs.
25+
boxes.each do |opts|
26+
config.vm.define opts[:name] do |config|
27+
config.vm.hostname = opts[:name] + ".k8s.test"
28+
config.vm.network :private_network, ip: opts[:ip]
29+
30+
# Provision all the VMs using Ansible after last VM is up.
31+
if opts[:name] == "node2"
32+
config.vm.provision "ansible" do |ansible|
33+
ansible.playbook = "main.yml"
34+
ansible.inventory_path = "inventory"
35+
ansible.limit = "all"
36+
end
37+
end
38+
end
39+
end
40+
41+
end

0 commit comments

Comments
 (0)