2018-05-15 05:27:26 +02:00
|
|
|
---
|
2021-03-25 14:59:44 +01:00
|
|
|
- name: Create the directory for the kubernetes_config_file
|
|
|
|
file:
|
|
|
|
path: "{{ kubernetes_kubeadm_kubelet_config_file_path | dirname }}"
|
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: Deploy the config-file for kubeadm and kubelet
|
|
|
|
template:
|
2021-04-07 20:32:25 +02:00
|
|
|
src: "kubeadm-kubelet-config.j2"
|
2021-03-25 14:59:44 +01:00
|
|
|
dest: "{{ kubernetes_kubeadm_kubelet_config_file_path }}"
|
|
|
|
|
2022-09-14 22:46:44 +02:00
|
|
|
- name: Initialize Kubernetes control plane with kubeadm init
|
2021-03-25 14:59:44 +01:00
|
|
|
command: >
|
|
|
|
kubeadm init
|
|
|
|
--config {{ kubernetes_kubeadm_kubelet_config_file_path }}
|
|
|
|
{{ kubernetes_kubeadm_init_extra_opts }}
|
|
|
|
register: kubeadmin_init
|
|
|
|
when: (not kubernetes_init_stat.stat.exists) and (kubernetes_ignore_preflight_errors is not defined)
|
|
|
|
|
2022-09-14 22:46:44 +02:00
|
|
|
- name: Initialize Kubernetes control plane with kubeadm init and ignore_preflight_errors
|
2018-05-15 05:27:26 +02:00
|
|
|
command: >
|
|
|
|
kubeadm init
|
2021-03-25 14:59:44 +01:00
|
|
|
--config {{ kubernetes_kubeadm_kubelet_config_file_path }}
|
2018-05-15 05:27:26 +02:00
|
|
|
--ignore-preflight-errors={{ kubernetes_ignore_preflight_errors }}
|
2018-09-28 12:02:31 +02:00
|
|
|
{{ kubernetes_kubeadm_init_extra_opts }}
|
2018-05-15 05:27:26 +02:00
|
|
|
register: kubeadmin_init
|
2021-03-25 14:59:44 +01:00
|
|
|
when: (not kubernetes_init_stat.stat.exists) and (kubernetes_ignore_preflight_errors is defined)
|
2018-09-28 11:56:27 +02:00
|
|
|
|
2018-05-15 05:27:26 +02:00
|
|
|
- name: Print the init output to screen.
|
2018-10-05 05:43:48 +02:00
|
|
|
debug:
|
|
|
|
var: kubeadmin_init.stdout
|
|
|
|
verbosity: 2
|
2018-12-06 23:45:06 +01:00
|
|
|
when: not kubernetes_init_stat.stat.exists
|
2018-05-15 05:27:26 +02:00
|
|
|
|
|
|
|
- name: Ensure .kube directory exists.
|
|
|
|
file:
|
|
|
|
path: ~/.kube
|
|
|
|
state: directory
|
2020-08-20 19:23:45 +02:00
|
|
|
mode: 0755
|
2018-05-15 05:27:26 +02:00
|
|
|
|
|
|
|
- name: Symlink the kubectl admin.conf to ~/.kube/conf.
|
|
|
|
file:
|
|
|
|
src: /etc/kubernetes/admin.conf
|
|
|
|
dest: ~/.kube/config
|
|
|
|
state: link
|
2020-08-20 19:23:45 +02:00
|
|
|
mode: 0644
|
2018-05-15 05:27:26 +02:00
|
|
|
|
|
|
|
- name: Configure Flannel networking.
|
2022-10-26 16:49:47 +02:00
|
|
|
command: "kubectl apply -f {{ kubernetes_flannel_manifest_file }}"
|
2018-05-15 05:27:26 +02:00
|
|
|
register: flannel_result
|
|
|
|
changed_when: "'created' in flannel_result.stdout"
|
2019-12-15 02:57:24 +01:00
|
|
|
when: kubernetes_pod_network.cni == 'flannel'
|
2023-06-20 18:34:33 +02:00
|
|
|
until: flannel_result is not failed
|
2023-06-20 18:39:13 +02:00
|
|
|
retries: 12
|
2023-04-20 11:54:44 +02:00
|
|
|
delay: 5
|
2019-06-19 20:48:23 +02:00
|
|
|
|
|
|
|
- name: Configure Calico networking.
|
2022-10-26 16:49:47 +02:00
|
|
|
command: "kubectl apply -f {{ kubernetes_calico_manifest_file }}"
|
2019-06-19 20:48:23 +02:00
|
|
|
register: calico_result
|
|
|
|
changed_when: "'created' in calico_result.stdout"
|
2019-12-15 02:57:24 +01:00
|
|
|
when: kubernetes_pod_network.cni == 'calico'
|
2023-06-20 18:34:33 +02:00
|
|
|
until: calico_result is not failed
|
2023-06-20 18:39:13 +02:00
|
|
|
retries: 12
|
2023-04-20 11:54:44 +02:00
|
|
|
delay: 5
|
2018-05-15 05:27:26 +02:00
|
|
|
|
2020-03-23 16:48:47 +01:00
|
|
|
- name: Get Kubernetes version for Weave installation.
|
2019-12-31 10:01:23 +01:00
|
|
|
shell: kubectl version | base64 | tr -d '\n'
|
2020-03-23 16:48:47 +01:00
|
|
|
changed_when: false
|
|
|
|
register: kubectl_version
|
2019-12-31 09:23:40 +01:00
|
|
|
when: kubernetes_pod_network.cni == 'weave'
|
2023-06-20 18:34:33 +02:00
|
|
|
until: kubectl_version is not failed
|
2023-06-20 18:39:13 +02:00
|
|
|
retries: 12
|
2023-04-20 11:54:44 +02:00
|
|
|
delay: 5
|
2019-12-31 09:23:40 +01:00
|
|
|
|
|
|
|
- name: Configure Weave networking.
|
|
|
|
command: "{{ item }}"
|
|
|
|
with_items:
|
2020-03-23 16:48:47 +01:00
|
|
|
- "kubectl apply -f https://cloud.weave.works/k8s/net?k8s-version={{ kubectl_version.stdout_lines[0] }}"
|
2019-12-31 09:23:40 +01:00
|
|
|
register: weave_result
|
|
|
|
changed_when: "'created' in weave_result.stdout"
|
|
|
|
when: kubernetes_pod_network.cni == 'weave'
|
|
|
|
|
2018-05-15 05:27:26 +02:00
|
|
|
# TODO: Check if taint exists with something like `kubectl describe nodes`
|
|
|
|
# instead of using kubernetes_init_stat.stat.exists check.
|
2022-09-14 22:46:44 +02:00
|
|
|
- name: Allow pods on control plane (if configured).
|
|
|
|
command: "kubectl taint nodes --all node-role.kubernetes.io/control-plane-"
|
2018-05-15 05:27:26 +02:00
|
|
|
when:
|
2022-09-14 22:46:44 +02:00
|
|
|
- kubernetes_allow_pods_on_control_plane | bool
|
2018-12-06 23:45:06 +01:00
|
|
|
- not kubernetes_init_stat.stat.exists
|