actualized for kubespray version 2.28.0
This commit is contained in:
@@ -6,9 +6,10 @@
|
||||
|
||||
- name: Create kubeadm cert controlplane config
|
||||
template:
|
||||
src: "kubeadm-client.conf.{{ kubeadmConfig_api_version }}.j2"
|
||||
src: "kubeadm-client.conf.j2"
|
||||
dest: "{{ kube_config_dir }}/kubeadm-cert-controlplane.conf"
|
||||
mode: "0640"
|
||||
validate: "{{ kubeadm_config_validate_enabled | ternary(bin_dir + '/kubeadm config validate --config %s', omit) }}"
|
||||
vars:
|
||||
kubeadm_cert_controlplane: true
|
||||
|
||||
@@ -51,7 +52,7 @@
|
||||
register: "etcd_client_cert_serial_result"
|
||||
changed_when: false
|
||||
when:
|
||||
- inventory_hostname in groups['k8s_cluster'] | union(groups['calico_rr'] | default([])) | unique | sort
|
||||
- group_names | intersect(['k8s_cluster', 'calico_rr']) | length > 0
|
||||
tags:
|
||||
- network
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
# noqa: jinja[spacing]
|
||||
kubeadm_discovery_address: >-
|
||||
{%- if "127.0.0.1" in kube_apiserver_endpoint or "localhost" in kube_apiserver_endpoint -%}
|
||||
{{ first_kube_control_plane_address }}:{{ kube_apiserver_port }}
|
||||
{{ first_kube_control_plane_address | ansible.utils.ipwrap }}:{{ kube_apiserver_port }}
|
||||
{%- else -%}
|
||||
{{ kube_apiserver_endpoint | replace("https://", "") }}
|
||||
{%- endif %}
|
||||
@@ -29,17 +29,15 @@
|
||||
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
||||
run_once: true
|
||||
|
||||
- name: Calculate kubeadm CA cert hash
|
||||
shell: set -o pipefail && openssl x509 -pubkey -in {{ kube_cert_dir }}/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
|
||||
args:
|
||||
executable: /bin/bash
|
||||
register: kubeadm_ca_hash
|
||||
- name: Fetch CA certificate from control plane node
|
||||
slurp:
|
||||
src: "{{ kube_cert_dir }}/ca.crt"
|
||||
register: ca_cert_content
|
||||
when:
|
||||
- kubeadm_ca_stat.stat is defined
|
||||
- kubeadm_ca_stat.stat.exists
|
||||
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
||||
run_once: true
|
||||
changed_when: false
|
||||
|
||||
- name: Create kubeadm token for joining nodes with 24h expiration (default)
|
||||
command: "{{ bin_dir }}/kubeadm token create"
|
||||
@@ -53,10 +51,6 @@
|
||||
kubeadm_token: "{{ temp_token.stdout }}"
|
||||
when: kubeadm_token is not defined
|
||||
|
||||
- name: Set kubeadm api version to v1beta3
|
||||
set_fact:
|
||||
kubeadmConfig_api_version: v1beta3
|
||||
|
||||
- name: Get kubeconfig for join discovery process
|
||||
command: "{{ kubectl }} -n kube-public get cm cluster-info -o jsonpath='{.data.kubeconfig}'"
|
||||
register: kubeconfig_file_discovery
|
||||
@@ -71,69 +65,35 @@
|
||||
owner: "root"
|
||||
mode: "0644"
|
||||
when:
|
||||
- not is_kube_master
|
||||
- ('kube_control_plane' not in group_names)
|
||||
- not kubelet_conf.stat.exists
|
||||
- kubeadm_use_file_discovery
|
||||
|
||||
- name: Create kubeadm client config
|
||||
template:
|
||||
src: "kubeadm-client.conf.{{ kubeadmConfig_api_version }}.j2"
|
||||
src: "kubeadm-client.conf.j2"
|
||||
dest: "{{ kube_config_dir }}/kubeadm-client.conf"
|
||||
backup: true
|
||||
mode: "0640"
|
||||
when: not is_kube_master
|
||||
|
||||
- name: Kubeadm | Create directory to store kubeadm patches
|
||||
file:
|
||||
path: "{{ kubeadm_patches.dest_dir }}"
|
||||
state: directory
|
||||
mode: "0640"
|
||||
when: kubeadm_patches is defined and kubeadm_patches.enabled
|
||||
|
||||
- name: Kubeadm | Copy kubeadm patches from inventory files
|
||||
copy:
|
||||
src: "{{ kubeadm_patches.source_dir }}/"
|
||||
dest: "{{ kubeadm_patches.dest_dir }}"
|
||||
owner: "root"
|
||||
mode: "0644"
|
||||
when: kubeadm_patches is defined and kubeadm_patches.enabled
|
||||
validate: "{{ kubeadm_config_validate_enabled | ternary(bin_dir + '/kubeadm config validate --config %s', omit) }}"
|
||||
when: ('kube_control_plane' not in group_names)
|
||||
|
||||
- name: Join to cluster if needed
|
||||
environment:
|
||||
PATH: "{{ bin_dir }}:{{ ansible_env.PATH }}:/sbin"
|
||||
when: not is_kube_master and (not kubelet_conf.stat.exists)
|
||||
block:
|
||||
|
||||
- name: Join to cluster
|
||||
command: >-
|
||||
timeout -k {{ kubeadm_join_timeout }} {{ kubeadm_join_timeout }}
|
||||
{{ bin_dir }}/kubeadm join
|
||||
--config {{ kube_config_dir }}/kubeadm-client.conf
|
||||
--ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests
|
||||
--skip-phases={{ kubeadm_join_phases_skip | join(',') }}
|
||||
register: kubeadm_join
|
||||
changed_when: kubeadm_join is success
|
||||
|
||||
rescue:
|
||||
|
||||
- name: Join to cluster with ignores
|
||||
command: >-
|
||||
timeout -k {{ kubeadm_join_timeout }} {{ kubeadm_join_timeout }}
|
||||
{{ bin_dir }}/kubeadm join
|
||||
--config {{ kube_config_dir }}/kubeadm-client.conf
|
||||
--ignore-preflight-errors=all
|
||||
--skip-phases={{ kubeadm_join_phases_skip | join(',') }}
|
||||
register: kubeadm_join
|
||||
changed_when: kubeadm_join is success
|
||||
|
||||
always:
|
||||
|
||||
- name: Display kubeadm join stderr if any
|
||||
when: kubeadm_join is failed
|
||||
debug:
|
||||
msg: |
|
||||
Joined with warnings
|
||||
{{ kubeadm_join.stderr_lines }}
|
||||
when:
|
||||
- ('kube_control_plane' not in group_names)
|
||||
- not kubelet_conf.stat.exists
|
||||
vars:
|
||||
ignored:
|
||||
- DirAvailable--etc-kubernetes-manifests
|
||||
- "{{ kubeadm_ignore_preflight_errors }}"
|
||||
command: >-
|
||||
timeout -k {{ kubeadm_join_timeout }} {{ kubeadm_join_timeout }}
|
||||
{{ bin_dir }}/kubeadm join
|
||||
--config {{ kube_config_dir }}/kubeadm-client.conf
|
||||
--ignore-preflight-errors={{ ignored | flatten | join(',') }}
|
||||
--skip-phases={{ kubeadm_join_phases_skip | join(',') }}
|
||||
|
||||
- name: Update server field in kubelet kubeconfig
|
||||
lineinfile:
|
||||
@@ -143,7 +103,7 @@
|
||||
backup: true
|
||||
when:
|
||||
- kubeadm_config_api_fqdn is not defined
|
||||
- not is_kube_master
|
||||
- ('kube_control_plane' not in group_names)
|
||||
- kubeadm_discovery_address != kube_apiserver_endpoint | replace("https://", "")
|
||||
notify: Kubeadm | restart kubelet
|
||||
|
||||
@@ -154,7 +114,7 @@
|
||||
line: ' server: {{ kube_apiserver_endpoint }}'
|
||||
backup: true
|
||||
when:
|
||||
- not is_kube_master
|
||||
- ('kube_control_plane' not in group_names)
|
||||
- loadbalancer_apiserver is defined
|
||||
notify: Kubeadm | restart kubelet
|
||||
|
||||
@@ -169,8 +129,8 @@
|
||||
tags:
|
||||
- kube-proxy
|
||||
|
||||
# FIXME(mattymo): Need to point to localhost, otherwise masters will all point
|
||||
# incorrectly to first master, creating SPoF.
|
||||
# FIXME(mattymo): Need to point to localhost, otherwise control plane nodes will all point
|
||||
# incorrectly to first control plane node, creating SPoF.
|
||||
- name: Update server field in kube-proxy kubeconfig
|
||||
shell: >-
|
||||
set -o pipefail && {{ kubectl }} get configmap kube-proxy -n kube-system -o yaml
|
||||
@@ -241,5 +201,5 @@
|
||||
when:
|
||||
- etcd_deployment_type == "kubeadm"
|
||||
- inventory_hostname not in groups['kube_control_plane']
|
||||
- kube_network_plugin in ["calico", "flannel", "cilium"] or cilium_deploy_additionally | default(false) | bool
|
||||
- kube_network_plugin in ["calico", "flannel", "cilium"] or cilium_deploy_additionally
|
||||
- kube_network_plugin != "calico" or calico_datastore == "etcd"
|
||||
|
||||
Reference in New Issue
Block a user