2018-05-15 05:27:26 +02:00
|
|
|
---
|
|
|
|
- name: Initialize Kubernetes master with kubeadm init.
|
|
|
|
command: >
|
|
|
|
kubeadm init
|
|
|
|
--pod-network-cidr={{ kubernetes_pod_network_cidr }}
|
2019-04-19 23:09:09 +02:00
|
|
|
--apiserver-advertise-address={{ kubernetes_apiserver_advertise_address | default(ansible_default_ipv4.address, true) }}
|
2018-09-28 06:19:56 +02:00
|
|
|
--kubernetes-version {{ kubernetes_version_kubeadm }}
|
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-09-28 11:56:27 +02:00
|
|
|
|
2018-05-15 05:27:26 +02:00
|
|
|
register: kubeadmin_init
|
2018-09-28 05:17:50 +02:00
|
|
|
failed_when: false
|
2018-12-06 23:45:06 +01:00
|
|
|
when: not kubernetes_init_stat.stat.exists
|
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
|
|
|
|
|
|
|
|
- name: Symlink the kubectl admin.conf to ~/.kube/conf.
|
|
|
|
file:
|
|
|
|
src: /etc/kubernetes/admin.conf
|
|
|
|
dest: ~/.kube/config
|
|
|
|
state: link
|
|
|
|
|
|
|
|
- name: Configure Flannel networking.
|
|
|
|
command: "{{ item }}"
|
|
|
|
with_items:
|
2018-06-05 04:45:51 +02:00
|
|
|
- kubectl apply -f {{ kubernetes_flannel_manifest_file_rbac }}
|
|
|
|
- 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"
|
|
|
|
|
|
|
|
# TODO: Check if taint exists with something like `kubectl describe nodes`
|
|
|
|
# instead of using kubernetes_init_stat.stat.exists check.
|
|
|
|
- name: Allow pods on master node (if configured).
|
|
|
|
command: "kubectl taint nodes --all node-role.kubernetes.io/master-"
|
|
|
|
when:
|
|
|
|
- kubernetes_allow_pods_on_master
|
2018-12-06 23:45:06 +01:00
|
|
|
- not kubernetes_init_stat.stat.exists
|
2018-05-15 05:27:26 +02:00
|
|
|
|
|
|
|
- name: Check if Kubernetes Dashboard UI service already exists.
|
|
|
|
shell: kubectl get services --namespace kube-system | grep -q kubernetes-dashboard
|
2018-09-28 05:17:50 +02:00
|
|
|
changed_when: false
|
|
|
|
failed_when: false
|
2018-05-15 05:27:26 +02:00
|
|
|
register: kubernetes_dashboard_service
|
|
|
|
when: kubernetes_enable_web_ui
|
|
|
|
|
|
|
|
- name: Enable the Kubernetes Web Dashboard UI (if configured).
|
2018-12-06 23:45:06 +01:00
|
|
|
command: "kubectl create -f {{ kubernetes_web_ui_manifest_file }}"
|
2018-05-15 05:27:26 +02:00
|
|
|
when:
|
|
|
|
- kubernetes_enable_web_ui
|
|
|
|
- kubernetes_dashboard_service is failed
|