summaryrefslogtreecommitdiff
path: root/roles/kubernetes/kubeadm/control-plane/tasks/main.yml
blob: b6160dab43c75bac9fd948328cb340e62806cdce (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
64
65
66
67
68
69
70
71
72
73
74
75
76
---
- 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 control-plane node
  when: "'_kubernetes_primary_controlplane_node_' in group_names"
  include_tasks: primary.yml

- name: install secondary control-plane nodes
  when: "'_kubernetes_primary_controlplane_node_' not in group_names"
  include_tasks: secondary.yml


- name: check if control-plane node is tainted (1/2)
  command: "kubectl --kubeconfig /etc/kubernetes/admin.conf get node {{ kubernetes_node_name }} -o json"
  check_mode: no
  register: kubectl_get_node
  changed_when: False

- name: check if control-plane node 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 control-plane node
  when: not kubernetes.dedicated_controlplane_nodes
  block:
  - name: remove control-plane taint from node
    when: "'node-role.kubernetes.io/control-plane' in kube_node_taints"
    command: "kubectl --kubeconfig /etc/kubernetes/admin.conf taint nodes {{ kubernetes_node_name }} node-role.kubernetes.io/control-plane-"

  - name: remove deprecated master taint from node
    when: "'node-role.kubernetes.io/master' in kube_node_taints"
    command: "kubectl --kubeconfig /etc/kubernetes/admin.conf taint nodes {{ kubernetes_node_name }} node-role.kubernetes.io/master-"

- name: add taint from control-plane node
  when: kubernetes.dedicated_controlplane_nodes
  block:
  - name: add control-plane taint to node
    when: "'node-role.kubernetes.io/control-plane' not in kube_node_taints"
    command: "kubectl --kubeconfig /etc/kubernetes/admin.conf taint nodes {{ kubernetes_node_name }} node-role.kubernetes.io/control-plane='':NoSchedule"

  - name: add deprecated master taint to node
    when: "'node-role.kubernetes.io/master' not in kube_node_taints"
    command: "kubectl --kubeconfig /etc/kubernetes/admin.conf taint nodes {{ kubernetes_node_name }} 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 }})