Fix control plane setup without a hardcoded key (#4610)

This commit is contained in:
Matthew Mosesohn 2019-04-24 00:37:59 +03:00 committed by Kubernetes Prow Robot
parent 228b244c84
commit d6d7458d68
4 changed files with 31 additions and 13 deletions

View file

@ -25,6 +25,24 @@
port: "{{kubeadm_discovery_address.split(':')[1]}}" port: "{{kubeadm_discovery_address.split(':')[1]}}"
timeout: 180 timeout: 180
- name: Upload certificates so they are fresh and not expired
command: >-
{{ bin_dir }}/kubeadm init phase
--config {{ kube_config_dir}}/kubeadm-config.yaml
upload-certs --experimental-upload-certs
{% if kubeadm_certificate_key is defined %}
--certificate-key={{ kubeadm_certificate_key }}
{% endif %}
run_once: yes
register: kubeadm_upload_cert
delegate_to: "{{ groups['kube-master'][0] }}"
- name: Parse certificate key if not set
set_fact:
kubeadm_certificate_key: "{{ hostvars[groups['kube-master'][0]]['kubeadm_upload_cert'].stdout_lines[-1] | trim }}"
when: kubeadm_certificate_key is undefined
- name: Joining control plane node to the cluster. - name: Joining control plane node to the cluster.
command: >- command: >-
{{ bin_dir }}/kubeadm join {{ bin_dir }}/kubeadm join

View file

@ -114,13 +114,23 @@
- name: set kubeadm certificate key - name: set kubeadm certificate key
set_fact: set_fact:
kubeadm_certificate_key: "{{ item | regex_search('--certificate-key ([^ ]+)','\\1') | first }}" kubeadm_certificate_key: "{{ item | regex_search('--certificate-key ([^ ]+)','\\1') | first }}"
with_items: "{{ (hostvars['kube-master'][0]['kubeadm_init']|default({'stdout_lines': []}))['stdout_lines'] }}" with_items: "{{ hostvars[groups['kube-master'][0]]['kubeadm_init'].stdout_lines | default([]) }}"
when: when:
- kubeadm_version is version('v1.14.0', '>=') - kubeadm_version is version('v1.14.0', '>=')
- kubeadm_certificate_key is not defined - kubeadm_certificate_key is not defined
- item | trim | match('.*--certificate-key .*') - item | trim | match('.*--certificate-key .*')
- hostvars['kube-master'][0]['kubeadm_init']['stdout_lines'] is defined - hostvars['kube-master'][0]['kubeadm_init']['stdout_lines'] is defined
- name: Create hardcoded kubeadm token for joining nodes with 24h expiration (if defined)
shell: >-
{{ bin_dir }}/kubeadm --kubeconfig /etc/kubernetes/admin.conf token delete {{ kubeadm_token }} || :;
{{ bin_dir }}/kubeadm --kubeconfig /etc/kubernetes/admin.conf token create {{ kubeadm_token }}
when:
- inventory_hostname == groups['kube-master']|first
- kubeadm_token is defined
tags:
- kubeadm_token
- name: Create kubeadm token for joining nodes with 24h expiration (default) - name: Create kubeadm token for joining nodes with 24h expiration (default)
command: "{{ bin_dir }}/kubeadm --kubeconfig /etc/kubernetes/admin.conf token create" command: "{{ bin_dir }}/kubeadm --kubeconfig /etc/kubernetes/admin.conf token create"
register: temp_token register: temp_token
@ -139,16 +149,6 @@
tags: tags:
- kubeadm_token - kubeadm_token
- name: Create hardcoded kubeadm token for joining nodes with 24h expiration (if defined)
shell: >-
{{ bin_dir }}/kubeadm --kubeconfig /etc/kubernetes/admin.conf token delete {{ kubeadm_token }} || :;
{{ bin_dir }}/kubeadm --kubeconfig /etc/kubernetes/admin.conf token create {{ kubeadm_token }}
when:
- inventory_hostname == groups['kube-master']|first
- kubeadm_token is defined
tags:
- kubeadm_token
- name: kubeadm | Initialize other masters (experimental control plane) - name: kubeadm | Initialize other masters (experimental control plane)
include: kubeadm-secondary-experimental.yml include: kubeadm-secondary-experimental.yml
when: kubeadm_control_plane when: kubeadm_control_plane

View file

@ -253,7 +253,7 @@ clientConnection:
burst: {{ kube_proxy_client_burst }} burst: {{ kube_proxy_client_burst }}
contentType: {{ kube_proxy_client_content_type }} contentType: {{ kube_proxy_client_content_type }}
kubeconfig: {{ kube_proxy_client_kubeconfig }} kubeconfig: {{ kube_proxy_client_kubeconfig }}
qps: {{ kube_proxy_client_kubeconfig }} qps: {{ kube_proxy_client_qps }}
clusterCIDR: {{ kube_pods_subnet }} clusterCIDR: {{ kube_pods_subnet }}
configSyncPeriod: {{ kube_proxy_config_sync_period }} configSyncPeriod: {{ kube_proxy_config_sync_period }}
conntrack: conntrack:

View file

@ -261,7 +261,7 @@ clientConnection:
burst: {{ kube_proxy_client_burst }} burst: {{ kube_proxy_client_burst }}
contentType: {{ kube_proxy_client_content_type }} contentType: {{ kube_proxy_client_content_type }}
kubeconfig: {{ kube_proxy_client_kubeconfig }} kubeconfig: {{ kube_proxy_client_kubeconfig }}
qps: {{ kube_proxy_client_kubeconfig }} qps: {{ kube_proxy_client_qps }}
clusterCIDR: {{ kube_pods_subnet }} clusterCIDR: {{ kube_pods_subnet }}
configSyncPeriod: {{ kube_proxy_config_sync_period }} configSyncPeriod: {{ kube_proxy_config_sync_period }}
conntrack: conntrack: