summaryrefslogtreecommitdiff
path: root/roles/kubernetes/kubeadm/master/tasks/main.yml
blob: 19037adcd116d5a78fec4f8d65089ec80fa73b37 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
- name: create direcotry for encryption config
  file:
    name: /etc/kubernetes/encryption
    state: directory
    mode: 0700

- name: install encryption config
  template:
    src: encryption-config.j2
    dest: /etc/kubernetes/encryption/config
    mode: 0600


- name: install primary master
  include_tasks: primary-master.yml
  when: "'_kubernetes_primary_master_' in group_names"

- name: install secondary masters
  include_tasks: secondary-masters.yml
  when: "'_kubernetes_primary_master_' not in group_names"


- 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: not kubernetes.dedicated_master and 'node-role.kubernetes.io/master' in kube_node_taints
  command: "kubectl --kubeconfig /etc/kubernetes/admin.conf taint nodes {{ inventory_hostname }} node-role.kubernetes.io/master-"

- name: add taint for master node
  when: kubernetes.dedicated_master and 'node-role.kubernetes.io/master' not in kube_node_taints
  command: "kubectl --kubeconfig /etc/kubernetes/admin.conf taint nodes {{ inventory_hostname }} node-role.kubernetes.io/master='':NoSchedule"


- 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

- name: add kubectl completion config for shells
  loop:
    - zsh
    - bash
  blockinfile:
    path: "/root/.{{ item }}rc"
    create: yes
    marker: "### {mark} ANSIBLE MANAGED BLOCK for kubectl ###"
    content: |
      source <(kubectl completion {{ item }})