157 lines
5.3 KiB
YAML
Executable File
157 lines
5.3 KiB
YAML
Executable File
---
|
|
# FastPass Kubernetes Cluster Deployment
|
|
# This playbook deploys a complete Kubernetes cluster on Fedora
|
|
|
|
- name: 1. Preflight checks and system preparation
|
|
hosts: fastpass
|
|
become: true
|
|
gather_facts: true
|
|
roles:
|
|
- role: kubernetes
|
|
|
|
- name: 2. Initialize first control plane node
|
|
hosts: fastpass_control_plane[0]
|
|
become: true
|
|
gather_facts: false
|
|
roles:
|
|
- role: fastpass-control-plane
|
|
|
|
- name: 3. Install Calico CNI
|
|
hosts: fastpass_control_plane[0]
|
|
become: false
|
|
gather_facts: false
|
|
environment:
|
|
KUBECONFIG: "{{ kubeconfig_path }}"
|
|
tasks:
|
|
- name: Check if Calico is already installed
|
|
ansible.builtin.shell: kubectl get pods -n kube-system -l k8s-app=calico-node --no-headers | wc -l
|
|
delegate_to: localhost
|
|
register: calico_check
|
|
ignore_errors: true
|
|
|
|
- name: Display Calico check result
|
|
ansible.builtin.debug:
|
|
msg: "Calico pods found: {{ calico_check.stdout | trim }}"
|
|
delegate_to: localhost
|
|
|
|
- name: Install Calico CNI
|
|
ansible.builtin.command: kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/{{ calico_version | default('v3.28.0') }}/manifests/calico.yaml
|
|
delegate_to: localhost
|
|
when: calico_check.stdout | trim == "0"
|
|
register: calico_install_result
|
|
ignore_errors: true
|
|
|
|
- name: Display Calico installation result
|
|
ansible.builtin.debug:
|
|
msg: "Calico install stdout: {{ calico_install_result.stdout }}"
|
|
delegate_to: localhost
|
|
when: calico_check.stdout | trim == "0"
|
|
|
|
- name: Wait for Calico node pods to be ready
|
|
ansible.builtin.command: kubectl wait --for=condition=ready pod -l k8s-app=calico-node -n kube-system --timeout=300s
|
|
delegate_to: localhost
|
|
when: calico_check.stdout | trim == "0"
|
|
|
|
- name: 4. Wait for first control plane to be fully ready
|
|
hosts: fastpass_control_plane[0]
|
|
become: false
|
|
gather_facts: false
|
|
environment:
|
|
KUBECONFIG: "{{ kubeconfig_path }}"
|
|
tasks:
|
|
- name: Wait for API server to be ready on first node
|
|
ansible.builtin.wait_for:
|
|
host: "{{ inventory_hostname }}"
|
|
port: "{{ control_plane_port | default('6443') }}"
|
|
timeout: 300
|
|
delegate_to: localhost
|
|
|
|
- name: Wait for first control plane node to be ready
|
|
ansible.builtin.command: kubectl --kubeconfig={{ kubeconfig_path }} wait --for=condition=ready node {{ inventory_hostname }} --timeout=300s
|
|
delegate_to: localhost
|
|
|
|
- name: Verify control plane status
|
|
ansible.builtin.command: kubectl --kubeconfig={{ kubeconfig_path }} get nodes -o wide
|
|
delegate_to: localhost
|
|
register: node_status
|
|
|
|
- name: Display cluster status
|
|
ansible.builtin.debug:
|
|
msg: "{{ node_status.stdout_lines }}"
|
|
|
|
- name: 5. Join additional control plane nodes
|
|
hosts: fastpass_control_plane[1:]
|
|
become: true
|
|
gather_facts: false
|
|
roles:
|
|
- role: fastpass-control-plane-join
|
|
|
|
- name: 6. Wait for all control plane nodes to be ready
|
|
hosts: fastpass_control_plane[0]
|
|
become: false
|
|
gather_facts: false
|
|
environment:
|
|
KUBECONFIG: "{{ kubeconfig_path }}"
|
|
tasks:
|
|
- name: Wait for all control plane nodes to be ready
|
|
ansible.builtin.command: kubectl --kubeconfig={{ kubeconfig_path }} wait --for=condition=ready node --selector=node-role.kubernetes.io/control-plane --timeout=600s
|
|
delegate_to: localhost
|
|
|
|
- name: Display all control plane nodes
|
|
ansible.builtin.command: kubectl --kubeconfig={{ kubeconfig_path }} get nodes --selector=node-role.kubernetes.io/control-plane -o wide
|
|
delegate_to: localhost
|
|
register: control_plane_status
|
|
|
|
- name: Show control plane status
|
|
ansible.builtin.debug:
|
|
msg: "{{ control_plane_status.stdout_lines }}"
|
|
|
|
- name: 7. Join worker nodes
|
|
hosts: fastpass_workers
|
|
become: true
|
|
gather_facts: false
|
|
roles:
|
|
- role: fastpass-workers
|
|
|
|
- name: 8. Final cluster validation
|
|
hosts: fastpass_control_plane[0]
|
|
become: false
|
|
gather_facts: false
|
|
environment:
|
|
KUBECONFIG: "{{ kubeconfig_path }}"
|
|
tasks:
|
|
- name: Wait for all nodes to be ready
|
|
ansible.builtin.command: kubectl --kubeconfig={{ kubeconfig_path }} wait --for=condition=ready node --all --timeout=300s
|
|
delegate_to: localhost
|
|
|
|
- name: Verify all pods are running
|
|
ansible.builtin.command: kubectl --kubeconfig={{ kubeconfig_path }} get pods --all-namespaces
|
|
delegate_to: localhost
|
|
register: pod_status
|
|
|
|
- name: Display final cluster status
|
|
ansible.builtin.debug:
|
|
msg: |
|
|
========================================
|
|
FastPass Kubernetes Cluster Status
|
|
========================================
|
|
{{ pod_status.stdout }}
|
|
========================================
|
|
|
|
- name: Show final node status
|
|
ansible.builtin.command: kubectl --kubeconfig={{ kubeconfig_path }} get nodes -o wide
|
|
delegate_to: localhost
|
|
register: final_node_status
|
|
|
|
- name: Display final node status
|
|
ansible.builtin.debug:
|
|
msg: "{{ final_node_status.stdout_lines }}"
|
|
|
|
- name: Test DNS-based control plane endpoint
|
|
ansible.builtin.command: kubectl --kubeconfig={{ kubeconfig_path }} cluster-info
|
|
delegate_to: localhost
|
|
register: cluster_info
|
|
|
|
- name: Display cluster info
|
|
ansible.builtin.debug:
|
|
msg: "{{ cluster_info.stdout_lines }}" |