Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: kubeconfig to all nodes #48

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions roles/cluster_control_plane_init/tasks/kubeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Fetch cluster config
become: true
register: slurpfile
ansible.builtin.slurp:
src: /etc/kubernetes/admin.conf

- name: Ensure .kube directory exists
delegate_to: kvm_host_local
connection: local
ansible.builtin.file:
path: ~/.kube
state: directory
mode: "0700"

- name: Create local kubernetes config
delegate_to: kvm_host_local
connection: local
ansible.builtin.copy:
content: "{{ slurpfile.content | b64decode }}"
dest: ~/.kube/config
mode: "0700"

- name: Copy kubeconfig to nodes
block:

- name: Include task node_kubeconfig
with_items: "{{ nodes }}"
ansible.builtin.include_tasks:
file: node_kubeconfig.yaml
24 changes: 3 additions & 21 deletions roles/cluster_control_plane_init/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,9 @@
--kubernetes-version=v"{{ kubernetes_minor_version }}"
--pod-network-cidr=10.244.0.0/16

- name: Fetch cluster config
become: true
register: slurpfile
ansible.builtin.slurp:
src: /etc/kubernetes/admin.conf

- name: Ensure .kube directory exists
delegate_to: kvm_host_local
connection: local
ansible.builtin.file:
path: ~/.kube
state: directory
mode: "0700"

- name: Create local kubernetes config
delegate_to: kvm_host_local
connection: local
ansible.builtin.copy:
content: "{{ slurpfile.content | b64decode }}"
dest: ~/.kube/config
mode: "0700"
- name: Include task kubeconfig
ansible.builtin.include_tasks:
file: kubeconfig.yaml

- name: Apply CNI plugin
delegate_to: kvm_host_local
Expand Down
33 changes: 33 additions & 0 deletions roles/cluster_control_plane_init/tasks/node_kubeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Ensure .kube directory exists
delegate_to: "{{ item.name }}"
ansible.builtin.file:
path: ~/.kube
state: directory
mode: "0700"

- name: Create local kubernetes config
delegate_to: "{{ item.name }}"
ansible.builtin.copy:
content: "{{ slurpfile.content | b64decode }}"
dest: ~/.kube/config
mode: "0700"

- name: Set up kubectl autocompletion
ansible.builtin.lineinfile:
dest: ~/.bashrc
line: "source <(kubectl completion bash)"
state: present

- name: Set up k alias
ansible.builtin.lineinfile:
dest: ~/.bashrc
line: "alias k=kubectl"
state: present

- name: Set up k alias autocompletion
ansible.builtin.lineinfile:
dest: ~/.bashrc
insertafter: "alias k=kubectl"
line: "complete -o default -F __start_kubectl k"
state: present
16 changes: 14 additions & 2 deletions roles/kvm_host_set_up/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,17 @@
ansible.builtin.lineinfile:
path: ~/.bashrc
state: present
regexp: "^source <(kubectl completion bash)"
line: source <(kubectl completion bash)
line: "source <(kubectl completion bash)"

- name: Set up k alias
ansible.builtin.lineinfile:
dest: ~/.bashrc
line: "alias k=kubectl"
state: present

- name: Set up k alias autocompletion
ansible.builtin.lineinfile:
dest: ~/.bashrc
insertafter: "alias k=kubectl"
line: "complete -o default -F __start_kubectl k"
state: present
Loading