Use more native way to update kubeconfigs using kubeadm (#5165)
Change-Id: I1076b418f85a26d9896be69910052128afc51cee
This commit is contained in:
parent
cb4f797d32
commit
6fe2248314
1 changed files with 43 additions and 11 deletions
|
@ -1,13 +1,45 @@
|
||||||
---
|
---
|
||||||
- name: Update server field in component kubeconfigs
|
- name: Test if correct apiserver is set in all kubeconfigs
|
||||||
lineinfile:
|
shell: >-
|
||||||
dest: "{{ kube_config_dir }}/{{ item }}.conf"
|
grep -Fq "{{ kube_apiserver_endpoint }}" {{ kube_config_dir }}/admin.conf &&
|
||||||
regexp: 'server:'
|
grep -Fq "{{ kube_apiserver_endpoint }}" {{ kube_config_dir }}/controller-manager.conf &&
|
||||||
line: ' server: {{ kube_apiserver_endpoint }}'
|
grep -Fq "{{ kube_apiserver_endpoint }}" {{ kube_config_dir }}/kubelet.conf &&
|
||||||
backup: yes
|
grep -Fq "{{ kube_apiserver_endpoint }}" {{ kube_config_dir }}/scheduler.conf
|
||||||
|
register: kubeconfig_correct_apiserver
|
||||||
|
changed_when: False
|
||||||
|
failed_when: False
|
||||||
|
|
||||||
|
- name: Create temporary directory
|
||||||
|
tempfile:
|
||||||
|
state: directory
|
||||||
|
register: kubeconfig_temp_dir
|
||||||
|
when: kubeconfig_correct_apiserver.rc != 0
|
||||||
|
|
||||||
|
- name: Generate new kubeconfigs with correct apiserver
|
||||||
|
command: >-
|
||||||
|
{{ bin_dir }}/kubeadm init phase kubeconfig all
|
||||||
|
--config {{ kube_config_dir }}/kubeadm-config.yaml
|
||||||
|
--kubeconfig-dir {{ kubeconfig_temp_dir.path }}
|
||||||
|
when: kubeconfig_correct_apiserver.rc != 0
|
||||||
|
|
||||||
|
- name: Copy new kubeconfigs to kube config dir
|
||||||
|
copy:
|
||||||
|
src: "{{ kubeconfig_temp_dir.path }}/{{ item }}"
|
||||||
|
dest: "{{ kube_config_dir }}/{{ item }}"
|
||||||
|
remote_src: yes
|
||||||
|
when: kubeconfig_correct_apiserver.rc != 0
|
||||||
with_items:
|
with_items:
|
||||||
- controller-manager
|
- admin.conf
|
||||||
- scheduler
|
- controller-manager.conf
|
||||||
when:
|
- kubelet.conf
|
||||||
- not loadbalancer_apiserver is defined
|
- scheduler.conf
|
||||||
notify: "Master | Restart kube-{{ item }}"
|
notify:
|
||||||
|
- "Master | Restart kube-controller-manager"
|
||||||
|
- "Master | Restart kube-scheduler"
|
||||||
|
- "Master | reload kubelet"
|
||||||
|
|
||||||
|
- name: Cleanup temporary directory
|
||||||
|
file:
|
||||||
|
path: "{{ kubeconfig_temp_dir.path }}"
|
||||||
|
state: absent
|
||||||
|
when: kubeconfig_correct_apiserver.rc != 0
|
||||||
|
|
Loading…
Reference in a new issue