diff --git a/roles/kube-master/tasks/main.yml b/roles/kube-master/tasks/main.yml index 367a0f1..a0a5ad7 100644 --- a/roles/kube-master/tasks/main.yml +++ b/roles/kube-master/tasks/main.yml @@ -49,6 +49,17 @@ when: 'BASIC_AUTH_ENABLE == "yes"' tags: restart_master +- name: 替换 kubeconfig 的 apiserver 地址 + lineinfile: + dest: "{{ item }}" + regexp: "^ server" + line: " server: https://{{ inventory_hostname }}:6443" + with_items: + - "/root/.kube/config" + - "/etc/kubernetes/kube-controller-manager.kubeconfig" + - "/etc/kubernetes/kube-scheduler.kubeconfig" + tags: upgrade_k8s, restart_master + - name: 创建 master 服务的 systemd unit 文件 template: src={{ item }}.j2 dest=/etc/systemd/system/{{ item }} with_items: @@ -66,13 +77,6 @@ systemctl restart kube-controller-manager && systemctl restart kube-scheduler" tags: upgrade_k8s, restart_master -- name: 替换 kubeconfig 的 apiserver 地址 - lineinfile: - dest: /root/.kube/config - regexp: "^ server" - line: " server: https://{{ inventory_hostname }}:6443" - tags: upgrade_k8s, restart_master - - name: 以轮询的方式等待master服务启动完成 command: "{{ bin_dir }}/kubectl get node" register: result diff --git a/roles/kube-node/tasks/node_lb.yml b/roles/kube-node/tasks/node_lb.yml index d749a24..1ba5425 100644 --- a/roles/kube-node/tasks/node_lb.yml +++ b/roles/kube-node/tasks/node_lb.yml @@ -47,22 +47,14 @@ - block: - name: 替换 kubeconfig 的 apiserver 地址 lineinfile: - dest: /root/.kube/config + dest: "{{ item }}" regexp: "^ server" line: " server: {{ KUBE_APISERVER }}" + with_items: + - "/root/.kube/config" + - "/etc/kubernetes/kubelet.kubeconfig" + - "/etc/kubernetes/kube-proxy.kubeconfig" - - name: 替换 kubelet.kubeconfig 的 apiserver 地址 - lineinfile: - dest: /etc/kubernetes/kubelet.kubeconfig - regexp: "^ server" - line: " server: {{ KUBE_APISERVER }}" - - - name: 替换 kube-proxy.kubeconfig 的 apiserver 地址 - lineinfile: - dest: /etc/kubernetes/kube-proxy.kubeconfig - regexp: "^ server" - line: " server: {{ KUBE_APISERVER }}" - - name: restart kube-node service service: name={{ item }} state=restarted with_items: