Skip to content

Commit

Permalink
Replace master with control-plane everywhere
Browse files Browse the repository at this point in the history
This commit gets rid of every 'master' name, replacing it with 'control-plane'.
Note that this is a potential breaking change, it means that variable names are
now different and need to be changed to make everything work.
  • Loading branch information
rascasoft committed Mar 13, 2024
1 parent cf84673 commit 6d5030f
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 90 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ idempotent implementation of several components.

This role can be configured to enable all of these features:

- **Single or multi master cluster implementation** with HAProxy and Keepalived
- **Single or multi control plane cluster implementation** with HAProxy and Keepalived
for High Availability.

- **Multi network add-ons** Flannel and Calico.
Expand Down Expand Up @@ -137,14 +137,14 @@ all the nodes:
```ini
# Kubernetes hosts
[kubelab]
kubernetes-1 k8s_role=master run_non_infra_pods=true
kubernetes-2 k8s_role=master run_non_infra_pods=true
kubernetes-3 k8s_role=master run_non_infra_pods=true
kubernetes-1 k8s_role=control-plane run_non_infra_pods=true
kubernetes-2 k8s_role=control-plane run_non_infra_pods=true
kubernetes-3 k8s_role=control-plane run_non_infra_pods=true
kubernetes-4 k8s_role=worker
```

You'll set which nodes will act as master and also whether or not those will run
non infrastructure pods (so to make the master also a worker).
You'll set which nodes will act as control plane and also whether or not those
will run non infrastructure pods (so to make the control plane also a worker).

Then you can define, inside group file (i.e.
[inventory/kubelab/group_vars/kubelab.yml](https://github.com/mmul-it/kubelab/blob/master/inventory/kubelab/group_vars/kubelab.yml)),
Expand All @@ -155,25 +155,25 @@ can be overridden by declaring the `k8s_host_group` variable.

### Kubernetes cluster

If you want to implement a multi-master, high availability cluster you'll need
to specify these variables:
If you want to implement a multi-control-plane, high availability cluster
you'll need to specify these variables:

```yaml
k8s_cluster_name: kubelab

k8s_master_node: kubernetes-1
k8s_master_port: 6443
k8s_master_cert_key: "91bded725a628a081d74888df8745172ed842fe30c7a3898b3c63ca98c7226fd"
k8s_control_plane_node: kubernetes-1
k8s_control_plane_port: 6443
k8s_control_plane_cert_key: "91bded725a628a081d74888df8745172ed842fe30c7a3898b3c63ca98c7226fd"

k8s_multi_master: true
k8s_multi_control_plane: true
k8s_balancer_VIP: 192.168.122.199
k8s_balancer_interface: eth0
k8s_balancer_port: 8443
k8s_balancer_password: "d6e284576158b1"

k8s_wait_timeout: 1200

k8s_master_ports:
k8s_control_plane_ports:
- 2379-2380/tcp
- 6443/tcp
- 8443/tcp
Expand All @@ -183,9 +183,10 @@ k8s_master_ports:
```
This will bring up a cluster starting from node `kubernetes-1` enabling multi
master via `k8s_multi_master` and setting the VIP address and the interface.
control plane via `k8s_multi_control_plane` and setting the VIP address and the
interface.

**<u>Note</u>**: you'll want to change both `k8s_master_cert_key` and
**<u>Note</u>**: you'll want to change both `k8s_control_plane_cert_key` and
`k8s_balancer_password` for better security.

**<u>Note</u>**: it is possible to have a more atomic way to configure pods
Expand Down
26 changes: 13 additions & 13 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,39 @@ k8s_services:
- kubelet
- "{{ k8s_container_service }}"

# The main master node from which all will be driven
k8s_master_node: kubernetes-1
# The main control plane node from which all will be driven
k8s_control_plane_node: kubernetes-1

# The master port on which Kubernetes will serve
k8s_master_port: 6443
# The control plane port on which Kubernetes will serve
k8s_control_plane_port: 6443

# Define the certificate key for k8s encryption
# If you need to generate random key for k8s certificate encryption use:
# openssl rand -hex 32
k8s_master_cert_key: "91bded725a628a081d74888df8745172ed842fe30c7a3898b3c63ca98c7226fd"
k8s_control_plane_cert_key: "91bded725a628a081d74888df8745172ed842fe30c7a3898b3c63ca98c7226fd"

# Multi master
# Set to true if you want a multi master setup:
k8s_multi_master: false
# Multi control plane
# Set to true if you want a multi control plane setup:
k8s_multi_control_plane: false

# Multi master - Define balancer VIP:
# Multi control plane - Define balancer VIP:
# k8s_balancer_VIP: 192.168.122.199
#
# Multi master - Define balancer port
# Multi control plane - Define balancer port
# k8s_balancer_port: 8443
#
# Multi master - Define balancer password
# Multi control plane - Define balancer password
# If you need to generate password just use:
# openssl rand -hex 7
# k8s_balancer_password: "d6e284576158b1"

k8s_master_ports:
k8s_control_plane_ports:
- 2379-2380/tcp
- 6443/tcp
- 10250/tcp
- 10257/tcp
- 10259/tcp
# Multi master - Remember to enable the load balancer port
# Multi control plane - Remember to enable the load balancer port
# - 8443/tcp

k8s_worker_ports:
Expand Down
12 changes: 6 additions & 6 deletions tasks/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,30 +216,30 @@
notify:
- Restart firewalld

- name: Enable VRRP protocol for multi master setup
- name: Enable VRRP protocol for multi control plane setup
ansible.posix.firewalld:
rich_rule: rule protocol value="vrrp" accept
state: enabled
permanent: true
immediate: true
when:
- k8s_role is defined
- k8s_role == 'master'
- k8s_multi_master | bool
- k8s_role == 'control-plane'
- k8s_multi_control_plane | bool
notify:
- Restart firewalld

- name: Allow master node network ports in Firewalld
- name: Allow control plane node network ports in Firewalld
ansible.posix.firewalld:
port: "{{ item }}"
state: enabled
permanent: true
immediate: true
with_items:
- "{{ k8s_master_ports }}"
- "{{ k8s_control_plane_ports }}"
when:
- k8s_role is defined
- k8s_role == 'master'
- k8s_role == 'control-plane'
notify:
- Restart firewalld

Expand Down
44 changes: 22 additions & 22 deletions tasks/master.yml → tasks/control-plane.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---

- name: Reset Kubernetes master node
- name: Reset Kubernetes control plane node
ansible.builtin.command: kubeadm reset -f
args:
removes: '/etc/kubernetes/manifests/*'
Expand All @@ -13,15 +13,15 @@

- name: Set control plane endpoint for single node
ansible.builtin.set_fact:
k8s_control_plane_endpoint: "{{ hostvars[k8s_master_node]['ansible_default_ipv4']['address'] }}"
when: not k8s_multi_master | bool
k8s_control_plane_endpoint: "{{ hostvars[k8s_control_plane_node]['ansible_default_ipv4']['address'] }}"
when: not k8s_multi_control_plane | bool

- name: Set control plane endpoint for multi master
- name: Set control plane endpoint for multi control plane
ansible.builtin.set_fact:
k8s_control_plane_endpoint: "{{ k8s_balancer_VIP }}:{{ k8s_balancer_port }}"
when: k8s_multi_master | bool
when: k8s_multi_control_plane | bool

- name: Multi master directories and files
- name: Multi control plane directories and files
block:
- name: Directories
ansible.builtin.file:
Expand All @@ -34,23 +34,23 @@

- name: Create haproxy.cfg file
ansible.builtin.template:
src: multi-master/haproxy.cfg.j2
src: multi-control-plane/haproxy.cfg.j2
dest: /usr/local/etc/haproxy/haproxy.cfg
owner: root
group: root
mode: '0644'

- name: Create keepalived.conf file
ansible.builtin.template:
src: multi-master/keepalived.conf.j2
src: multi-control-plane/keepalived.conf.j2
dest: /usr/local/etc/keepalived/keepalived.conf
owner: root
group: root
mode: '0644'

- name: Create pod configurations"
ansible.builtin.template:
src: "templates/multi-master/{{ item }}_pod.yaml.j2"
src: "templates/multi-control-plane/{{ item }}_pod.yaml.j2"
dest: "/etc/kubernetes/manifests/{{ item }}.yaml"
owner: root
group: root
Expand All @@ -61,16 +61,16 @@

- name: Create keepalived check script
ansible.builtin.template:
src: multi-master/check_apiserver.sh.j2
src: multi-control-plane/check_apiserver.sh.j2
dest: /usr/local/etc/keepalived/check_apiserver.sh
owner: root
group: root
mode: '0755'
become: true
when:
- k8s_multi_master | bool
- k8s_multi_control_plane | bool

- name: Set up the master node
- name: Set up the control plane node
block:
- name: Pulling images required for setting up a Kubernetes cluster
ansible.builtin.command: kubeadm config images pull
Expand All @@ -91,7 +91,7 @@
become: true
when:
- k8s_node_status == "NotAvailable"
- inventory_hostname == k8s_master_node
- inventory_hostname == k8s_control_plane_node

- name: Copy remote /etc/kubernetes/admin.conf on local directory
ansible.builtin.fetch:
Expand All @@ -101,7 +101,7 @@
mode: '0640'
become: true
when:
- inventory_hostname == k8s_master_node
- inventory_hostname == k8s_control_plane_node

- name: Create Network Add-on local folder
ansible.builtin.file:
Expand All @@ -118,7 +118,7 @@
- name: "network-addons/{{ k8s_network_addon }}"
run_once: true

- name: Set kubeadm join credentials from master node
- name: Set kubeadm join credentials from control plane node
block:
- name: Get Token from Kubernetes
ansible.builtin.shell: |
Expand Down Expand Up @@ -152,24 +152,24 @@
ansible.builtin.set_fact:
k8s_discovery_token_ca_cert_hash: "{{ k8s_discovery_token_ca_cert_hash_output.stdout }}"
when:
- inventory_hostname == k8s_master_node
- inventory_hostname == k8s_control_plane_node

- name: Join control-plane nodes with kubernetes master
- name: Join control-plane nodes with kubernetes control plane
ansible.builtin.command: |
kubeadm join {{ k8s_control_plane_endpoint }} \
--token {{ hostvars[k8s_master_node]['k8s_token'] }} \
--discovery-token-ca-cert-hash sha256:{{ hostvars[k8s_master_node]['k8s_discovery_token_ca_cert_hash'] }} \
--token {{ hostvars[k8s_control_plane_node]['k8s_token'] }} \
--discovery-token-ca-cert-hash sha256:{{ hostvars[k8s_control_plane_node]['k8s_discovery_token_ca_cert_hash'] }} \
--control-plane \
--certificate-key {{ k8s_master_cert_key }}
--certificate-key {{ k8s_control_plane_cert_key }}
args:
creates: /etc/kubernetes/kubelet.conf
throttle: 1
become: true
when:
- k8s_node_status != 'Ready'
- inventory_hostname != k8s_master_node
- inventory_hostname != k8s_control_plane_node

- name: Enable master to run non infrastructure pods
- name: Enable control plane to run non infrastructure pods
kubernetes.core.k8s_taint:
kubeconfig: "{{ k8s_kubeconfig }}"
name: "{{ inventory_hostname }}"
Expand Down
8 changes: 4 additions & 4 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
run_once: true

- name: Master tasks
ansible.builtin.import_tasks: master.yml
ansible.builtin.import_tasks: control-plane.yml
when:
- k8s_role is defined
- k8s_role == 'master'
- k8s_role == 'control-plane'

- name: Worker tasks
ansible.builtin.import_tasks: worker.yml
Expand Down Expand Up @@ -72,5 +72,5 @@
- k8s_cert_manager_enable|bool
when:
- k8s_role is defined
- k8s_role == 'master'
- inventory_hostname == k8s_master_node
- k8s_role == 'control-plane'
- inventory_hostname == k8s_control_plane_node
22 changes: 11 additions & 11 deletions tasks/worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
- name: Reset Kubernetes worker node
ansible.builtin.command: kubeadm reset -f
args:
removes: '/etc/kubernetes/manifests/*'
removes: '/etc/kubernetes'
when:
- k8s_reset|bool
become: true

- name: Check ndoe status
- name: Check node status
ansible.builtin.import_tasks: node_status.yml

- name: Join worker nodes
block:
- name: Joining worker kubernetes single master
ansible.builtin.command: kubeadm join --token {{ hostvars[k8s_master_node]['k8s_token'] }} \
--discovery-token-ca-cert-hash sha256:{{ hostvars[k8s_master_node]['k8s_discovery_token_ca_cert_hash'] }} \
{{ k8s_master_node }}:{{ k8s_master_port }}
- name: Joining worker kubernetes single control plane
ansible.builtin.command: kubeadm join --token {{ hostvars[k8s_control_plane_node]['k8s_token'] }} \
--discovery-token-ca-cert-hash sha256:{{ hostvars[k8s_control_plane_node]['k8s_discovery_token_ca_cert_hash'] }} \
{{ k8s_control_plane_node }}:{{ k8s_control_plane_port }}
changed_when: true
when: not k8s_multi_master | bool
when: not k8s_multi_control_plane | bool

- name: Join worker kubernetes multi master
- name: Join worker kubernetes multi control plane
ansible.builtin.command: |
kubeadm join {{ k8s_balancer_VIP }}:{{ k8s_balancer_port }} \
--token {{ hostvars[k8s_master_node]['k8s_token'] }} \
--discovery-token-ca-cert-hash sha256:{{ hostvars[k8s_master_node]['k8s_discovery_token_ca_cert_hash'] }}
--token {{ hostvars[k8s_control_plane_node]['k8s_token'] }} \
--discovery-token-ca-cert-hash sha256:{{ hostvars[k8s_control_plane_node]['k8s_discovery_token_ca_cert_hash'] }}
changed_when: true
when: k8s_multi_master | bool
when: k8s_multi_control_plane | bool
when:
- k8s_node_status == "NotAvailable"
become: true
2 changes: 1 addition & 1 deletion templates/config.yaml.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
certificateKey: "{{ k8s_master_cert_key }}"
certificateKey: "{{ k8s_control_plane_cert_key }}"
---
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
Expand Down
8 changes: 4 additions & 4 deletions templates/dashboard/dashboard-deployment.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ spec:
serviceAccountName: kubernetes-dashboard
nodeSelector:
"kubernetes.io/os": linux
# Comment the following tolerations if Dashboard must not be deployed on master
# Comment the following tolerations if Dashboard must not be deployed on control plane
tolerations:
- key: node-role.kubernetes.io/master
- key: node-role.kubernetes.io/control-plane
effect: NoSchedule

---
Expand Down Expand Up @@ -297,9 +297,9 @@ spec:
serviceAccountName: kubernetes-dashboard
nodeSelector:
"kubernetes.io/os": linux
# Comment the following tolerations if Dashboard must not be deployed on master
# Comment the following tolerations if Dashboard must not be deployed on control-plane
tolerations:
- key: node-role.kubernetes.io/master
- key: node-role.kubernetes.io/control-plane
effect: NoSchedule
volumes:
- name: tmp-volume
Expand Down
Loading

0 comments on commit 6d5030f

Please sign in to comment.