diff options
author | Christian Pointner <equinox@spreadspace.org> | 2019-09-29 00:42:21 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2019-10-10 19:27:38 +0200 |
commit | 98308448d40f3c07c4afd58cf41ba2ad6dfe7e23 (patch) | |
tree | cc81cae3a6d1810cded6c29cdf976bf64ad10661 /roles/kubernetes/master/tasks/main.yml | |
parent | sk-torrent role (diff) |
refactoring kubernetes roles
Diffstat (limited to 'roles/kubernetes/master/tasks/main.yml')
-rw-r--r-- | roles/kubernetes/master/tasks/main.yml | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/roles/kubernetes/master/tasks/main.yml b/roles/kubernetes/master/tasks/main.yml deleted file mode 100644 index 7cc6fe94..00000000 --- a/roles/kubernetes/master/tasks/main.yml +++ /dev/null @@ -1,109 +0,0 @@ ---- -- name: check if kubeconfig admin.conf already exists - stat: - path: /etc/kubernetes/admin.conf - register: kubeconfig_admin_stats - -### cluster not yet initialized - -- name: create new cluster - when: kubeconfig_admin_stats.stat.exists == False - block: - - - name: generate bootstrap token for new cluster - command: kubeadm token generate - changed_when: False - check_mode: no - register: kubeadm_token_generate - - - name: create kubernetes config directory - file: - path: /etc/kubernetes - state: directory - - ## TODO test whether the generated cluster configs really works - since it has never been used... - - name: install cluster config for kubeadm - template: - src: kubeadm-cluster.config.j2 - dest: /etc/kubernetes/kubeadm-cluster.config - - - name: set up kubernetes master - command: "kubeadm init --config '/etc/kubernetes/kubeadm-cluster.config' --token '{{ kubeadm_token_generate.stdout }}' --token-ttl 42m --skip-token-print" - args: - creates: /etc/kubernetes/pki/ca.crt - register: kubeadm_init - - - name: dump output of kubeadm init to log file - when: kubeadm_init.changed - copy: - content: "{{ kubeadm_init.stdout }}\n" - dest: /etc/kubernetes/kubeadm-init.log - -### cluster is already initialized - -- name: prepare cluster for new nodes - when: kubeconfig_admin_stats.stat.exists == True - block: - - - name: fetch list of current nodes - command: kubectl get nodes -o name - changed_when: False - check_mode: no - register: kubectl_node_list - - - name: save list of current nodes - set_fact: - kubernetes_current_nodes: "{{ kubectl_node_list.stdout_lines | map('replace', 'node/', '') | list }}" - - - name: create bootstrap token for existing cluster - when: kubernetes_nodes | difference(kubernetes_current_nodes) | length > 0 - command: kubeadm token create --ttl 42m - check_mode: no - register: kubeadm_token_create - -## - -- name: check if master is tainted (1/2) - command: "kubectl --kubeconfig /etc/kubernetes/admin.conf get node {{ inventory_hostname }} -o json" - check_mode: no - register: kubectl_get_node - changed_when: False - -- name: check if master is tainted (2/2) - set_fact: - kube_node_taints: "{% set node_info = kubectl_get_node.stdout | from_json %}{%if node_info.spec.taints is defined %}{{ node_info.spec.taints | map(attribute='key') | list }}{% endif %}" - -- name: remove taint from master node - when: "kubernetes.dedicated_master == False and 'node-role.kubernetes.io/master' in kube_node_taints" - command: kubectl --kubeconfig /etc/kubernetes/admin.conf taint nodes --all node-role.kubernetes.io/master- - -- name: add taint for master node - when: "kubernetes.dedicated_master == True and 'node-role.kubernetes.io/master' not in kube_node_taints" - command: "kubectl --kubeconfig /etc/kubernetes/admin.conf taint nodes {{ ansible_nodename }} node-role.kubernetes.io/master='':NoSchedule" - -- name: install openssl - apt: - name: openssl - state: present - -- name: get ca certificate digest - shell: "openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'" - check_mode: no - register: kube_ca_openssl - changed_when: False - -- name: set variables needed by kubernetes/nodes to join the cluster - set_fact: - kube_bootstrap_token: "{% if kubeadm_token_generate.stdout is defined %}{{ kubeadm_token_generate.stdout }}{% elif kubeadm_token_create.stdout is defined %}{{ kubeadm_token_create.stdout }}{% endif %}" - kube_bootstrap_ca_cert_hash: "sha256:{{ kube_ca_openssl.stdout }}" - -- name: prepare kubectl (1/2) - file: - name: /root/.kube - state: directory - -- name: prepare kubectl (2/2) - file: - dest: /root/.kube/config - src: /etc/kubernetes/admin.conf - state: link |