From bc2518b4ba20e74503f93cba9cd8c21b07995c58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A5l-Kristian=20Hamre?= Date: Wed, 16 Jul 2025 20:14:58 +0200 Subject: [PATCH] Add task to get kubernetes configuration to .kubeconfig. --- cluster.yml | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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