|
|
|
---
|
|
|
|
- name: Stop loadbalancers on other masters
|
|
|
|
hosts: masters
|
|
|
|
become: yes
|
|
|
|
become_method: sudo
|
|
|
|
become_user: root
|
|
|
|
tasks:
|
|
|
|
- name: Stopping services
|
|
|
|
service:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: stopped
|
|
|
|
with_items:
|
|
|
|
- "haproxy"
|
|
|
|
- "keepalived"
|
|
|
|
- name: Initialize the controlplane
|
|
|
|
hosts: root_master
|
|
|
|
become: yes
|
|
|
|
become_method: sudo
|
|
|
|
become_user: root
|
|
|
|
tasks:
|
|
|
|
- name: Pull images
|
|
|
|
shell: kubeadm config images pull
|
|
|
|
- name: Initialize the control plane
|
|
|
|
shell: kubeadm init --pod-network-cidr={{ POD_NETWORK_CIDR }} --control-plane-endpoint "{{ APISERVER_VIP}}:{{ APISERVER_DEST_PORT }}" --upload-certs >> /etc/kubernetes/setup.out
|
|
|
|
args:
|
|
|
|
chdir: $HOME
|
|
|
|
creates: /etc/kubernetes/setup.out
|
|
|
|
- name: Extract Control Plane token
|
|
|
|
shell: cat /etc/kubernetes/setup.out | grep -e " kubeadm join" -e "--discovery-token" -e "--control-plane"
|
|
|
|
register: K8S_CP_JOIN_COMMAND
|
|
|
|
- name: Create dummy host to hold the token
|
|
|
|
add_host:
|
|
|
|
name: "K8S_CP_JOIN_DH"
|
|
|
|
token: "{{ K8S_CP_JOIN_COMMAND.stdout }}"
|
|
|
|
- name: Show command
|
|
|
|
debug:
|
|
|
|
msg: "{{ hostvars['K8S_CP_JOIN_DH']['token'] | regex_replace('[\\\\]+[n,t]', ' ')}}"
|
|
|
|
- name: Join k8s masters to the cluster
|
|
|
|
hosts: masters
|
|
|
|
become: yes
|
|
|
|
become_method: sudo
|
|
|
|
become_user: root
|
|
|
|
tasks:
|
|
|
|
- name: Execute image pull
|
|
|
|
shell: kubeadm config images pull
|
|
|
|
- name: Join the clusters
|
|
|
|
shell: "{{ hostvars['K8S_CP_JOIN_DH']['token'] }} >> /etc/kubernetes/control-plane-join.log 2>&1"
|
|
|
|
args:
|
|
|
|
creates: /etc/kubernetes/control-plane-join.log
|
|
|
|
# - name: Reboot machine to finaliza presetup
|
|
|
|
# reboot:
|
|
|
|
# reboot_timeout: 3600
|