mirror of
https://github.com/geerlingguy/ansible-role-kubernetes.git
synced 2024-11-23 19:06:33 +01:00
be61637a4d
fix lint Update README.md Co-authored-by: Jeff Geerling <geerlingguy@mac.com> Update defaults/main.yml Co-authored-by: Jeff Geerling <geerlingguy@mac.com> Update main.yml
99 lines
3.4 KiB
YAML
99 lines
3.4 KiB
YAML
---
|
|
- 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:
|
|
src: "kubeadm-kubelet-config.yaml"
|
|
dest: "{{ kubernetes_kubeadm_kubelet_config_file_path }}"
|
|
|
|
- name: Initialize Kubernetes master with kubeadm init
|
|
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)
|
|
|
|
- name: Initialize Kubernetes master with kubeadm init and ignore_preflight_errors
|
|
command: >
|
|
kubeadm init
|
|
--config {{ kubernetes_kubeadm_kubelet_config_file_path }}
|
|
--ignore-preflight-errors={{ kubernetes_ignore_preflight_errors }}
|
|
{{ kubernetes_kubeadm_init_extra_opts }}
|
|
register: kubeadmin_init
|
|
when: (not kubernetes_init_stat.stat.exists) and (kubernetes_ignore_preflight_errors is defined)
|
|
|
|
- name: Print the init output to screen.
|
|
debug:
|
|
var: kubeadmin_init.stdout
|
|
verbosity: 2
|
|
when: not kubernetes_init_stat.stat.exists
|
|
|
|
- name: Ensure .kube directory exists.
|
|
file:
|
|
path: ~/.kube
|
|
state: directory
|
|
mode: 0755
|
|
|
|
- name: Symlink the kubectl admin.conf to ~/.kube/conf.
|
|
file:
|
|
src: /etc/kubernetes/admin.conf
|
|
dest: ~/.kube/config
|
|
state: link
|
|
mode: 0644
|
|
|
|
- name: Configure Flannel networking.
|
|
command: "{{ item }}"
|
|
with_items:
|
|
- kubectl apply -f {{ kubernetes_flannel_manifest_file_rbac }}
|
|
- kubectl apply -f {{ kubernetes_flannel_manifest_file }}
|
|
register: flannel_result
|
|
changed_when: "'created' in flannel_result.stdout"
|
|
when: kubernetes_pod_network.cni == 'flannel'
|
|
|
|
- name: Configure Calico networking.
|
|
command: "{{ item }}"
|
|
with_items:
|
|
- kubectl apply -f {{ kubernetes_calico_manifest_file }}
|
|
register: calico_result
|
|
changed_when: "'created' in calico_result.stdout"
|
|
when: kubernetes_pod_network.cni == 'calico'
|
|
|
|
- name: Get Kubernetes version for Weave installation.
|
|
shell: kubectl version | base64 | tr -d '\n'
|
|
changed_when: false
|
|
register: kubectl_version
|
|
when: kubernetes_pod_network.cni == 'weave'
|
|
|
|
- name: Configure Weave networking.
|
|
command: "{{ item }}"
|
|
with_items:
|
|
- "kubectl apply -f https://cloud.weave.works/k8s/net?k8s-version={{ kubectl_version.stdout_lines[0] }}"
|
|
register: weave_result
|
|
changed_when: "'created' in weave_result.stdout"
|
|
when: kubernetes_pod_network.cni == 'weave'
|
|
|
|
# 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 | bool
|
|
- not kubernetes_init_stat.stat.exists
|
|
|
|
- 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 | bool
|
|
|
|
- name: Enable the Kubernetes Web Dashboard UI (if configured).
|
|
command: "kubectl create -f {{ kubernetes_web_ui_manifest_file }}"
|
|
when:
|
|
- kubernetes_enable_web_ui | bool
|
|
- kubernetes_dashboard_service.rc != 0
|