Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
Issue #11: Abstract a few things so we can run this playbook on diffe…
Browse files Browse the repository at this point in the history
…rent sets of servers.
  • Loading branch information
geerlingguy committed May 28, 2020
1 parent 8a5ee82 commit 7119e93
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 29 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This repository is a companion to a YouTube series by Jeff Geerling in 2020:
- **Episode 3**: [Installing K3s on the Turing Pi](https://www.youtube.com/watch?v=N4bfNefjBSw) ([blog post](https://www.jeffgeerling.com/blog/2020/pi-cluster-episode-3-installing-k3s-kubernetes-on-turing-pi))
- **Episode 4**: Coming soon!

You might also be interested in another Raspberry-Pi cluster I've maintained for years, the [Raspberry Pi Dramble](https://www.pidramble.com), which is a Kubernetes Pi cluster in my basement that hosts the Drupal website [www.pidramble.com](https://www.pidramble.com).
You might also be interested in another Raspberry-Pi cluster I've maintained for years, the [Raspberry Pi Dramble](https://www.pidramble.com), which is a Kubernetes Pi cluster in my basement that hosts [www.pidramble.com](https://www.pidramble.com).

## Usage

Expand All @@ -29,8 +29,8 @@ Then, you can deploy _all_ the applications configured in this repository with t
These commands can be consolidated into one `ansible-galaxy install` command once Ansible 2.10 is released.
3. Make sure you have the Kubernetes config file for the Turing Pi cluster available locally in the path `~/.kube/config-turing-pi`.
4. Copy the `example.hosts.ini` inventory file to `hosts.ini`. Make sure it has the `master` and `node`s configured correctly.
3. Copy the `example.hosts.ini` inventory file to `hosts.ini`. Make sure it has the `master` and `node`s configured correctly.
4. Edit the `ingress_server_ip` and `load_balancer_server_ip` in `group_vars/all.yml` and set them each to an IP address of one of the nodes.
5. Run the playbook:
```
Expand Down Expand Up @@ -103,4 +103,4 @@ Now you can go back to the steps above under 'Usage' to set up applications insi
## Author
The repository was created by [Jeff Geerling](https://www.jeffgeerling.com), who writes [Ansible for DevOps](https://www.ansiblefordevops.com) and [Ansible for Kubernetes](https://www.ansibleforkubernetes.com).
The repository was created in 2020 by [Jeff Geerling](https://www.jeffgeerling.com), who writes [Ansible for DevOps](https://www.ansiblefordevops.com) and [Ansible for Kubernetes](https://www.ansibleforkubernetes.com).
9 changes: 9 additions & 0 deletions group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
---
ansible_user: pirate
helm_arch: arm

# Turing Pi.
# ingress_server_ip: 10.0.100.74
# load_balancer_server_ip: 10.0.100.99

# Dramble.
ingress_server_ip: 10.0.100.83
load_balancer_server_ip: 10.0.100.131
26 changes: 6 additions & 20 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,15 @@
collections:
- community.kubernetes

vars:
helm_arch: arm

environment:
# The location of the kubeconfig file on the master.
K8S_AUTH_KUBECONFIG: ~/.kube/config
PATH: "~/go/bin:{{ ansible_env.PATH }}"

pre_tasks:
- name: Ensure required dependencies are installed.
package:
name:
- python3-setuptools
- build-essential
- golang
- git
state: present
become: true

- name: Ensure openshift Python library is installed.
pip:
name: openshift
state: present
become: true

roles:
- role: setup
tags: ['setup']

- role: cluster_monitoring
tags: ['monitoring', 'prometheus']

Expand All @@ -52,3 +35,6 @@

- role: pihole
tags: ['pihole']

- role: status
tags: ['status', 'debug']
2 changes: 1 addition & 1 deletion roles/drupal/files/drupal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ metadata:
namespace: drupal
spec:
rules:
- host: drupal.10.0.100.74.nip.io
- host: drupal.{{ ingress_server_ip }}.nip.io
http:
paths:
- path: /
Expand Down
2 changes: 1 addition & 1 deletion roles/drupal/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- name: Apply drupal manifests.
k8s:
definition: "{{ lookup('file', 'files/' + item ) }}"
definition: "{{ lookup('template', 'files/' + item ) }}"
state: present
loop:
- mariadb.yml
Expand Down
4 changes: 2 additions & 2 deletions roles/pihole/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
ingress:
enabled: true
serviceTCP:
loadBalancerIP: '10.0.100.99'
loadBalancerIP: '{{ load_balancer_server_ip }}'
type: LoadBalancer
serviceUDP:
loadBalancerIP: '10.0.100.99'
loadBalancerIP: '{{ load_balancer_server_ip }}'
type: LoadBalancer
resources:
limits:
Expand Down
21 changes: 21 additions & 0 deletions roles/setup/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Ensure apt caches are up to date.
apt:
update_cache: true
cache_valid_time: 3600

- name: Ensure required dependencies are installed.
package:
name:
- python3-setuptools
- build-essential
- golang
- git
state: present
become: true

- name: Ensure openshift Python library is installed.
pip:
name: openshift
state: present
become: true
3 changes: 3 additions & 0 deletions roles/status/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
collections:
- community.kubernetes
19 changes: 19 additions & 0 deletions roles/status/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Get Ingress records from monitoring namespace.
k8s_info:
api_version: extensions/v1beta1
kind: Ingress
namespace: monitoring
register: monitoring_ingress

- name: Print relevant addresses.
debug:
msg:
- "http://{{ monitoring_ingress['resources'][0]['spec']['rules'][0]['host'] }}/"
- "http://{{ monitoring_ingress['resources'][1]['spec']['rules'][0]['host'] }}/"
- "http://{{ monitoring_ingress['resources'][2]['spec']['rules'][0]['host'] }}/"
- "Drupal: http://drupal.{{ ingress_server_ip }}.nip.io/"
- "Wordpress: http://wordpress.{{ ingress_server_ip }}.nip.io/"
- "Minecraft: (`kubectl get service -n minecraft`)"
- "Pi-hole: http://pi.hole/ (add record for {{ load_balancer_server_ip }} to /etc/hosts)"
tags: ['debug']
2 changes: 1 addition & 1 deletion roles/wordpress/templates/wordpress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ metadata:
namespace: wordpress
spec:
rules:
- host: wordpress.10.0.100.74.nip.io
- host: wordpress.{{ ingress_server_ip }}.nip.io
http:
paths:
- path: /
Expand Down

0 comments on commit 7119e93

Please sign in to comment.