2017-09-14 02:00:51 +08:00
|
|
|
---
|
2017-09-26 17:38:58 +08:00
|
|
|
- name: kubeadm | Check if old apiserver cert exists on host
|
|
|
|
stat:
|
|
|
|
path: "{{ kube_cert_dir }}/apiserver.pem"
|
|
|
|
register: old_apiserver_cert
|
|
|
|
delegate_to: "{{groups['kube-master']|first}}"
|
|
|
|
run_once: true
|
|
|
|
|
|
|
|
- name: kubeadm | Check service account key
|
|
|
|
stat:
|
|
|
|
path: "{{ kube_cert_dir }}/sa.key"
|
|
|
|
register: sa_key_before
|
|
|
|
delegate_to: "{{groups['kube-master']|first}}"
|
|
|
|
run_once: true
|
|
|
|
|
|
|
|
- name: kubeadm | Check if kubeadm has already run
|
|
|
|
stat:
|
2017-10-15 17:33:22 +08:00
|
|
|
path: "{{ kube_cert_dir }}/ca.key"
|
|
|
|
register: kubeadm_ca
|
|
|
|
|
|
|
|
- name: kubeadm | Delete old admin.conf
|
|
|
|
file:
|
2017-09-26 17:38:58 +08:00
|
|
|
path: "{{ kube_config_dir }}/admin.conf"
|
2017-10-15 17:33:22 +08:00
|
|
|
state: absent
|
|
|
|
when: not kubeadm_ca.stat.exists
|
2017-09-26 17:38:58 +08:00
|
|
|
|
|
|
|
- name: kubeadm | Delete old static pods
|
|
|
|
file:
|
|
|
|
path: "{{ kube_config_dir }}/manifests/{{item}}.manifest"
|
|
|
|
state: absent
|
|
|
|
with_items: ["kube-apiserver", "kube-controller-manager", "kube-scheduler", "kube-proxy"]
|
|
|
|
when: old_apiserver_cert.stat.exists
|
|
|
|
|
|
|
|
- name: kubeadm | Forcefully delete old static pods
|
|
|
|
shell: "docker ps -f name=k8s_{{item}} -q | xargs --no-run-if-empty docker rm -f"
|
|
|
|
with_items: ["kube-apiserver", "kube-controller-manager", "kube-scheduler"]
|
|
|
|
when: old_apiserver_cert.stat.exists
|
|
|
|
|
2017-09-14 02:00:51 +08:00
|
|
|
- name: kubeadm | aggregate all SANs
|
|
|
|
set_fact:
|
|
|
|
apiserver_sans: >-
|
|
|
|
kubernetes
|
|
|
|
kubernetes.default
|
|
|
|
kubernetes.default.svc
|
|
|
|
kubernetes.default.svc.{{ dns_domain }}
|
|
|
|
{{ kube_apiserver_ip }}
|
|
|
|
localhost
|
|
|
|
127.0.0.1
|
|
|
|
{{ ' '.join(groups['kube-master']) }}
|
2017-11-24 00:15:48 +08:00
|
|
|
{%- if loadbalancer_apiserver is defined %}
|
2017-09-14 02:00:51 +08:00
|
|
|
{{ apiserver_loadbalancer_domain_name }}
|
|
|
|
{%- endif %}
|
|
|
|
{%- for host in groups['kube-master'] -%}
|
2017-09-16 05:28:15 +08:00
|
|
|
{%- if hostvars[host]['access_ip'] is defined %}{{ hostvars[host]['access_ip'] }}{% endif %}
|
2017-09-14 02:00:51 +08:00
|
|
|
{{ hostvars[host]['ip'] | default(hostvars[host]['ansible_default_ipv4']['address']) }}
|
|
|
|
{%- endfor %}
|
2017-10-18 19:04:13 +08:00
|
|
|
{%- if supplementary_addresses_in_ssl_keys is defined %}
|
|
|
|
{%- for addr in supplementary_addresses_in_ssl_keys %}
|
2017-10-17 18:06:07 +08:00
|
|
|
{{ addr }}
|
2017-10-18 19:04:13 +08:00
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|
2017-10-17 18:06:07 +08:00
|
|
|
tags: facts
|
2017-09-14 02:00:51 +08:00
|
|
|
|
|
|
|
- name: kubeadm | Copy etcd cert dir under k8s cert dir
|
|
|
|
command: "cp -TR {{ etcd_cert_dir }} {{ kube_config_dir }}/ssl/etcd"
|
|
|
|
changed_when: false
|
|
|
|
|
|
|
|
- name: kubeadm | Create kubeadm config
|
|
|
|
template:
|
|
|
|
src: kubeadm-config.yaml.j2
|
|
|
|
dest: "{{ kube_config_dir }}/kubeadm-config.yaml"
|
|
|
|
register: kubeadm_config
|
|
|
|
|
2017-09-16 05:28:15 +08:00
|
|
|
- name: kubeadm | Initialize first master
|
2017-09-26 17:38:58 +08:00
|
|
|
command: timeout -k 240s 240s {{ bin_dir }}/kubeadm init --config={{ kube_config_dir }}/kubeadm-config.yaml --skip-preflight-checks
|
2017-09-16 05:28:15 +08:00
|
|
|
register: kubeadm_init
|
2017-09-27 21:47:47 +08:00
|
|
|
# Retry is because upload config sometimes fails
|
2017-09-16 05:28:15 +08:00
|
|
|
retries: 3
|
2017-10-15 17:33:22 +08:00
|
|
|
when: inventory_hostname == groups['kube-master']|first and not kubeadm_ca.stat.exists
|
2017-09-26 17:38:58 +08:00
|
|
|
failed_when: kubeadm_init.rc != 0 and "field is immutable" not in kubeadm_init.stderr
|
|
|
|
notify: Master | restart kubelet
|
|
|
|
|
|
|
|
- name: kubeadm | Upgrade first master
|
2017-09-27 21:48:18 +08:00
|
|
|
command: >-
|
|
|
|
timeout -k 240s 240s
|
|
|
|
{{ bin_dir }}/kubeadm
|
|
|
|
upgrade apply -y {{ kube_version }}
|
|
|
|
--config={{ kube_config_dir }}/kubeadm-config.yaml
|
|
|
|
--skip-preflight-checks
|
|
|
|
--allow-experimental-upgrades
|
|
|
|
--allow-release-candidate-upgrades
|
2017-09-26 17:38:58 +08:00
|
|
|
register: kubeadm_upgrade
|
2017-09-27 21:47:47 +08:00
|
|
|
# Retry is because upload config sometimes fails
|
2017-09-26 17:38:58 +08:00
|
|
|
retries: 3
|
2017-10-15 17:33:22 +08:00
|
|
|
when: inventory_hostname == groups['kube-master']|first and (kubeadm_config.changed and kubeadm_ca.stat.exists)
|
2017-09-26 17:38:58 +08:00
|
|
|
failed_when: kubeadm_upgrade.rc != 0 and "field is immutable" not in kubeadm_upgrade.stderr
|
|
|
|
notify: Master | restart kubelet
|
|
|
|
|
|
|
|
# FIXME(mattymo): remove when https://github.com/kubernetes/kubeadm/issues/433 is fixed
|
|
|
|
- name: kubeadm | Enable kube-proxy
|
|
|
|
command: "{{ bin_dir }}/kubeadm alpha phase addon kube-proxy --config={{ kube_config_dir }}/kubeadm-config.yaml"
|
|
|
|
when: inventory_hostname == groups['kube-master']|first
|
|
|
|
changed_when: false
|
2017-09-16 05:28:15 +08:00
|
|
|
|
|
|
|
- name: slurp kubeadm certs
|
|
|
|
slurp:
|
|
|
|
src: "{{ item }}"
|
|
|
|
with_items:
|
|
|
|
- "{{ kube_cert_dir }}/apiserver.crt"
|
|
|
|
- "{{ kube_cert_dir }}/apiserver.key"
|
|
|
|
- "{{ kube_cert_dir }}/apiserver-kubelet-client.crt"
|
|
|
|
- "{{ kube_cert_dir }}/apiserver-kubelet-client.key"
|
|
|
|
- "{{ kube_cert_dir }}/ca.crt"
|
|
|
|
- "{{ kube_cert_dir }}/ca.key"
|
|
|
|
- "{{ kube_cert_dir }}/front-proxy-ca.crt"
|
|
|
|
- "{{ kube_cert_dir }}/front-proxy-ca.key"
|
|
|
|
- "{{ kube_cert_dir }}/front-proxy-client.crt"
|
|
|
|
- "{{ kube_cert_dir }}/front-proxy-client.key"
|
|
|
|
- "{{ kube_cert_dir }}/sa.key"
|
|
|
|
- "{{ kube_cert_dir }}/sa.pub"
|
|
|
|
register: kubeadm_certs
|
|
|
|
delegate_to: "{{ groups['kube-master']|first }}"
|
|
|
|
run_once: true
|
|
|
|
|
2017-09-26 17:38:58 +08:00
|
|
|
- name: kubeadm | write out kubeadm certs
|
2017-09-16 05:28:15 +08:00
|
|
|
copy:
|
|
|
|
dest: "{{ item.item }}"
|
|
|
|
content: "{{ item.content | b64decode }}"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0700
|
|
|
|
no_log: true
|
|
|
|
register: copy_kubeadm_certs
|
|
|
|
with_items: "{{ kubeadm_certs.results }}"
|
|
|
|
when: inventory_hostname != groups['kube-master']|first
|
|
|
|
|
2017-09-26 17:38:58 +08:00
|
|
|
- name: kubeadm | Init other uninitialized masters
|
|
|
|
command: timeout -k 240s 240s {{ bin_dir }}/kubeadm init --config={{ kube_config_dir }}/kubeadm-config.yaml --skip-preflight-checks
|
2017-09-14 02:00:51 +08:00
|
|
|
register: kubeadm_init
|
2017-10-15 17:33:22 +08:00
|
|
|
when: inventory_hostname != groups['kube-master']|first and not kubeadm_ca.stat.exists
|
2017-09-26 17:38:58 +08:00
|
|
|
failed_when: kubeadm_init.rc != 0 and "field is immutable" not in kubeadm_init.stderr
|
|
|
|
notify: Master | restart kubelet
|
|
|
|
|
|
|
|
- name: kubeadm | Upgrade other masters
|
2017-09-27 21:48:18 +08:00
|
|
|
command: >-
|
|
|
|
timeout -k 240s 240s
|
|
|
|
{{ bin_dir }}/kubeadm
|
|
|
|
upgrade apply -y {{ kube_version }}
|
|
|
|
--config={{ kube_config_dir }}/kubeadm-config.yaml
|
|
|
|
--skip-preflight-checks
|
|
|
|
--allow-experimental-upgrades
|
|
|
|
--allow-release-candidate-upgrades
|
2017-09-26 17:38:58 +08:00
|
|
|
register: kubeadm_upgrade
|
2017-10-15 17:33:22 +08:00
|
|
|
when: inventory_hostname != groups['kube-master']|first and (kubeadm_config.changed and kubeadm_ca.stat.exists)
|
2017-09-26 17:38:58 +08:00
|
|
|
failed_when: kubeadm_upgrade.rc != 0 and "field is immutable" not in kubeadm_upgrade.stderr
|
|
|
|
notify: Master | restart kubelet
|
|
|
|
|
|
|
|
- name: kubeadm | Check service account key again
|
|
|
|
stat:
|
|
|
|
path: "{{ kube_cert_dir }}/sa.key"
|
|
|
|
register: sa_key_after
|
|
|
|
delegate_to: "{{groups['kube-master']|first}}"
|
|
|
|
run_once: true
|
|
|
|
|
|
|
|
- name: kubeadm | Set secret_changed if service account key was updated
|
|
|
|
command: /bin/true
|
|
|
|
notify: Master | set secret_changed
|
|
|
|
when: sa_key_before.stat.checksum|default("") != sa_key_after.stat.checksum
|
|
|
|
|
|
|
|
- name: kubeadm | cleanup old certs if necessary
|
|
|
|
include: kubeadm-cleanup-old-certs.yml
|
|
|
|
when: old_apiserver_cert.stat.exists
|