mirror of
https://github.com/geerlingguy/ansible-role-kubernetes.git
synced 2024-11-28 19:05:53 +01:00
58 lines
2.1 KiB
YAML
58 lines
2.1 KiB
YAML
|
---
|
||
|
- name: Initialize Kubernetes master with kubeadm init.
|
||
|
command: >
|
||
|
kubeadm init
|
||
|
--pod-network-cidr={{ kubernetes_pod_network_cidr }}
|
||
|
--apiserver-advertise-address={{ kubernetes_apiserver_advertise_address | default(ansible_default_ipv4.address) }}
|
||
|
--kubernetes-version {{ kubernetes_version }}
|
||
|
--ignore-preflight-errors={{ kubernetes_ignore_preflight_errors }}
|
||
|
register: kubeadmin_init
|
||
|
failed_when: False
|
||
|
when: kubernetes_init_stat.stat.exists == False
|
||
|
|
||
|
- name: Print the init output to screen.
|
||
|
debug: var=kubeadmin_init.stdout
|
||
|
when:
|
||
|
- kuberenetes_debug
|
||
|
- kubernetes_init_stat.stat.exists == False
|
||
|
|
||
|
- 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:
|
||
|
- kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
|
||
|
- kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
|
||
|
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
|
||
|
- kubernetes_init_stat.stat.exists == False
|
||
|
|
||
|
- name: Check if Kubernetes Dashboard UI service already exists.
|
||
|
shell: kubectl get services --namespace kube-system | grep -q kubernetes-dashboard
|
||
|
changed_when: False
|
||
|
failed_when: False
|
||
|
register: kubernetes_dashboard_service
|
||
|
when: kubernetes_enable_web_ui
|
||
|
|
||
|
- name: Enable the Kubernetes Web Dashboard UI (if configured).
|
||
|
command: "kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml"
|
||
|
when:
|
||
|
- kubernetes_enable_web_ui
|
||
|
- kubernetes_dashboard_service is failed
|