diff --git a/cluster.yml b/cluster.yml index 70bf6dd..dc906e2 100644 --- a/cluster.yml +++ b/cluster.yml @@ -151,8 +151,6 @@ tasks: - name: Store the join commands as facts set_fact: - # *** THIS IS THE FIX *** - # Add the --control-plane flag to the join command for control planes. join_cp_command: "{{ hostvars[groups['control_planes'][0]]['join_command_control_plane']['stdout'] }} --control-plane --certificate-key {{ hostvars[groups['control_planes'][0]]['cert_key']['stdout_lines'][-1] }}" join_worker_command: "{{ hostvars[groups['control_planes'][0]]['join_command_control_plane']['stdout'] }}" @@ -179,3 +177,23 @@ command: "{{ hostvars['localhost']['join_worker_command'] }}" args: creates: /etc/kubernetes/kubelet.conf + +# ============================================================================== +# PHASE 5: Fetch kubeconfig for local use +# ============================================================================== +- name: 5. Fetch admin.conf to the local machine + hosts: control_planes[0] + become: yes + tasks: + - name: Fetch admin.conf from the first control plane + fetch: + src: /etc/kubernetes/admin.conf + dest: .kubeconfig + flat: yes + + - name: Update kubeconfig to use the cluster's external IP + replace: + path: .kubeconfig + regexp: 'https://192.168.122.101:6443' + replace: "https://{{ apiserver_endpoint }}:6443" + delegate_to: localhost \ No newline at end of file