feat: initialise k8s cluster

This commit is contained in:
2026-06-27 13:06:34 +01:00
parent a1d9ea1a67
commit 470fd15b56
2 changed files with 40 additions and 8 deletions
@@ -1,4 +1,3 @@
---
- name: Initialise Kubernetes cluster
ansible.builtin.command:
argv:
@@ -9,8 +8,35 @@
- --upload-certs
args:
creates: /etc/kubernetes/admin.conf
run_once: true
- name: Generate Join Command
ansible.builtin.command:
argv:
- kubeadm
- token
- create
- --print-join-command
register: kubernetes_control_plane_join_command
run_once: true
changed_when: true
- name: Get Certificate Key
ansible.builtin.shell:
cmd: set -o pipefail && kubeadm init phase upload-certs --upload-certs | tail -n 1
register: kubernetes_control_plane_certificate_key
run_once: true
changed_when: true
- name: Join Additional Control Planes
ansible.builtin.command:
cmd: "{{ kubernetes_control_plane_join_command.stdout }} --control-plane --certificate-key {{ kubernetes_control_plane_certificate_key.stdout }}"
args:
creates: /etc/kubernetes/admin.conf
- name: Copy Kubernetes Admin Config
ansible.builtin.command: "{{ item }}"
loop:
@@ -20,6 +46,12 @@
args:
creates: $HOME/.kube/config
- name: Install Kubernetes CLI
ansible.builtin.apt:
pkg:
- kubectl
state: present
# - name: Install Pod Network (Calico)
# ansible.builtin.shell: kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.32.0/manifests/calico.yaml > pod_network_setup.txt
# args: