mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-25 17:12:50 +00:00
feat: change builtin defined variable (#2561)
* feat: change inventory_hosts to hostvars Signed-off-by: joyceliu <joyceliu@yunify.com> * feat: change inventory_hosts to hostvars Signed-off-by: joyceliu <joyceliu@yunify.com> --------- Signed-off-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
parent
9a672ad646
commit
fb474bde50
|
|
@ -15,7 +15,7 @@
|
|||
{{- range $server := (.ntp.servers | fromJson) }}
|
||||
{{- $internalIPv4 := "" }}
|
||||
{{- $internalIPv6 := "" }}
|
||||
{{- range $.inventory_hosts }}
|
||||
{{- range $.hostvars }}
|
||||
{{- if eq .hostname $server }}
|
||||
{{- $internalIPv4 = .internal_ipv4 | default "" }}
|
||||
{{- $internalIPv6 = .internal_ipv6 | default "" }}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
- name: Set hostname
|
||||
command: |
|
||||
hostnamectl set-hostname {{ .inventory_name }} \
|
||||
&& sed -i '/^127.0.1.1/s/.*/127.0.1.1 {{ .inventory_name }}/g' /etc/hosts
|
||||
hostnamectl set-hostname {{ .inventory_hostname }} \
|
||||
&& sed -i '/^127.0.1.1/s/.*/127.0.1.1 {{ .inventory_hostname }}/g' /etc/hosts
|
||||
when:
|
||||
- .set_hostname
|
||||
- .inventory_name | ne "localhost"
|
||||
- .inventory_hostname | ne "localhost"
|
||||
|
||||
- name: Sync init os to remote
|
||||
template:
|
||||
|
|
|
|||
|
|
@ -214,41 +214,41 @@ cat >>/etc/hosts<<EOF
|
|||
# kubekey hosts BEGIN
|
||||
# kubernetes hosts
|
||||
{{- range .groups.k8s_cluster | default list }}
|
||||
{{- $hostname := index $.inventory_hosts . "hostname" -}}
|
||||
{{- $hostname := index $.hostvars . "hostname" -}}
|
||||
{{- $clusterName := $.kubernetes.cluster_name | default "kubekey" -}}
|
||||
{{- $dnsDomain := $.kubernetes.networking.dns_domain | default "cluster.local" -}}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv4") (ne (index $.inventory_hosts . "internal_ipv4") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv4" }} {{ $hostname }} {{ printf "%s.%s" $hostname $clusterName }} {{ printf "%s.%s.%s" $hostname $clusterName $dnsDomain }}
|
||||
{{- if and (index $.hostvars . "internal_ipv4") (ne (index $.hostvars . "internal_ipv4") "") }}
|
||||
{{ index $.hostvars . "internal_ipv4" }} {{ $hostname }} {{ printf "%s.%s" $hostname $clusterName }} {{ printf "%s.%s.%s" $hostname $clusterName $dnsDomain }}
|
||||
{{- end }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv6") (ne (index $.inventory_hosts . "internal_ipv6") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv6" }} {{ $hostname }} {{ printf "%s.%s" $hostname $clusterName }} {{ printf "%s.%s.%s" $hostname $clusterName $dnsDomain }}
|
||||
{{- if and (index $.hostvars . "internal_ipv6") (ne (index $.hostvars . "internal_ipv6") "") }}
|
||||
{{ index $.hostvars . "internal_ipv6" }} {{ $hostname }} {{ printf "%s.%s" $hostname $clusterName }} {{ printf "%s.%s.%s" $hostname $clusterName $dnsDomain }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
# etcd hosts
|
||||
{{- range .groups.etcd | default list }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv4") (ne (index $.inventory_hosts . "internal_ipv4") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv4" }} {{ index $.inventory_hosts . "hostname" }}
|
||||
{{- if and (index $.hostvars . "internal_ipv4") (ne (index $.hostvars . "internal_ipv4") "") }}
|
||||
{{ index $.hostvars . "internal_ipv4" }} {{ index $.hostvars . "hostname" }}
|
||||
{{- end }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv6") (ne (index $.inventory_hosts . "internal_ipv6") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv6" }} {{ index $.inventory_hosts . "hostname" }}
|
||||
{{- if and (index $.hostvars . "internal_ipv6") (ne (index $.hostvars . "internal_ipv6") "") }}
|
||||
{{ index $.hostvars . "internal_ipv6" }} {{ index $.hostvars . "hostname" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
# image registry hosts
|
||||
{{- range .groups.image_registry | default list }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv4") (ne (index $.inventory_hosts . "internal_ipv4") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv4" }} {{ index $.inventory_hosts . "hostname" }}
|
||||
{{- if and (index $.hostvars . "internal_ipv4") (ne (index $.hostvars . "internal_ipv4") "") }}
|
||||
{{ index $.hostvars . "internal_ipv4" }} {{ index $.hostvars . "hostname" }}
|
||||
{{- end }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv6") (ne (index $.inventory_hosts . "internal_ipv6") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv6" }} {{ index $.inventory_hosts . "hostname" }}
|
||||
{{- if and (index $.hostvars . "internal_ipv6") (ne (index $.hostvars . "internal_ipv6") "") }}
|
||||
{{ index $.hostvars . "internal_ipv6" }} {{ index $.hostvars . "hostname" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
# nfs hosts
|
||||
{{- range .groups.nfs | default list }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv4") (ne (index $.inventory_hosts . "internal_ipv4") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv4" }} {{ index $.inventory_hosts . "hostname" }}
|
||||
{{- if and (index $.hostvars . "internal_ipv4") (ne (index $.hostvars . "internal_ipv4") "") }}
|
||||
{{ index $.hostvars . "internal_ipv4" }} {{ index $.hostvars . "hostname" }}
|
||||
{{- end }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv6") (ne (index $.inventory_hosts . "internal_ipv6") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv4" }} {{ index $.inventory_hosts . "hostname" }}
|
||||
{{- if and (index $.hostvars . "internal_ipv6") (ne (index $.hostvars . "internal_ipv6") "") }}
|
||||
{{ index $.hostvars . "internal_ipv4" }} {{ index $.hostvars . "hostname" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
# kubekey hosts END
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
- |
|
||||
{{- $existIP := false }}
|
||||
{{- range .groups.all | default list }}
|
||||
{{- if eq $.kubernetes.control_plane_endpoint.kube_vip.address (index $.inventory_hosts . "internal_ipv4") }}
|
||||
{{- if eq $.kubernetes.control_plane_endpoint.kube_vip.address (index $.hostvars . "internal_ipv4") }}
|
||||
{{- $existIP = true }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
when: and .kube_version (ne .kube_version "")
|
||||
|
||||
- name: Check if kubernetes installed
|
||||
when: .groups.k8s_cluster | default list | has .inventory_name
|
||||
when: .groups.k8s_cluster | default list | has .inventory_hostname
|
||||
block:
|
||||
- name: Get kubernetes service
|
||||
ignore_errors: true
|
||||
|
|
|
|||
|
|
@ -59,21 +59,21 @@
|
|||
kube_network_plugin:"{{ .kubernetes.kube_network_plugin }}" is not supported
|
||||
when: and .kubernetes.kube_network_plugin (ne .kubernetes.kube_network_plugin "")
|
||||
|
||||
# # This assertion will fail on the safe side: One can indeed schedule more pods
|
||||
# # on a node than the CIDR-range has space for when additional pods use the host
|
||||
# # network namespace. It is impossible to ascertain the number of such pods at
|
||||
# # provisioning time, so to establish a guarantee, we factor these out.
|
||||
# # NOTICE: the check blatantly ignores the inet6-case
|
||||
# - name: Guarantee that enough network address space is available for all pods
|
||||
# when: .groups.k8s_cluster | default list | has .inventory_name
|
||||
# block:
|
||||
# - name: Guarantee that enough ipv4 network address space is available for all pods
|
||||
# when: .kubernetes.networking.pod_cidr | default "10.233.64.0/18" | splitList "," | first | ipFamily | eq "IPv4"
|
||||
# assert:
|
||||
# that: le .kubernetes.kubelet.max_pods (sub (pow 2 (sub 32 .kubernetes.networking.ipv4_mask_size | default 24 | float64)) 2)
|
||||
# fail_msg: do not schedule more pods on a node than ipv4 inet addresses are available.
|
||||
# - name: Guarantee that enough ipv6 network address space is available for all pods
|
||||
# when: .kubernetes.networking.pod_cidr | default "10.233.64.0/18" | splitList "," | last | ipFamily | eq "IPv6"
|
||||
# assert:
|
||||
# that: le .kubernetes.kubelet.max_pods (sub (pow 2 (sub 128 .kubernetes.networking.ipv6_mask_size | default 64 | float64)) 2)
|
||||
# fail_msg: do not schedule more pods on a node than ipv6 inet addresses are available.
|
||||
# This assertion will fail on the safe side: One can indeed schedule more pods
|
||||
# on a node than the CIDR-range has space for when additional pods use the host
|
||||
# network namespace. It is impossible to ascertain the number of such pods at
|
||||
# provisioning time, so to establish a guarantee, we factor these out.
|
||||
# NOTICE: the check blatantly ignores the inet6-case
|
||||
- name: Guarantee that enough network address space is available for all pods
|
||||
when: .groups.k8s_cluster | default list | has .inventory_hostname
|
||||
block:
|
||||
- name: Guarantee that enough ipv4 network address space is available for all pods
|
||||
when: .kubernetes.networking.pod_cidr | default "10.233.64.0/18" | splitList "," | first | ipFamily | eq "IPv4"
|
||||
assert:
|
||||
that: le .kubernetes.kubelet.max_pods (sub (pow 2 (sub 32 .kubernetes.networking.ipv4_mask_size | default 24 | float64)) 2)
|
||||
fail_msg: do not schedule more pods on a node than ipv4 inet addresses are available.
|
||||
- name: Guarantee that enough ipv6 network address space is available for all pods
|
||||
when: .kubernetes.networking.pod_cidr | default "10.233.64.0/18" | splitList "," | last | ipFamily | eq "IPv6"
|
||||
assert:
|
||||
that: le .kubernetes.kubelet.max_pods (sub (pow 2 (sub 128 .kubernetes.networking.ipv6_mask_size | default 64 | float64)) 2)
|
||||
fail_msg: do not schedule more pods on a node than ipv6 inet addresses are available.
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@
|
|||
- name: Stop if memory is too small for masters
|
||||
assert:
|
||||
that: .process.memInfo.MemTotal | trimSuffix " kB" | atoi | le .cluster_require.minimal_master_memory_mb
|
||||
when: .groups.kube_control_plane | default list | has .inventory_name
|
||||
when: .groups.kube_control_plane | default list | has .inventory_hostname
|
||||
|
||||
- name: Stop if memory is too small for nodes
|
||||
assert:
|
||||
that: .process.memInfo.MemTotal | trimSuffix " kB" | atoi | le .cluster_require.minimal_node_memory_mb
|
||||
when:
|
||||
- .groups.kube_worker | default list | has .inventory_name
|
||||
- .groups.kube_worker | default list | has .inventory_hostname
|
||||
|
||||
- name: Stop if kernel version is too low
|
||||
assert:
|
||||
|
|
|
|||
|
|
@ -44,17 +44,17 @@
|
|||
init_kubernetes_node: |
|
||||
{{- $initNodes := list -}}
|
||||
{{- range .groups.kube_control_plane -}}
|
||||
{{- if index $.inventory_hosts . "kubernetes_install_service" "stdout" | eq "active" -}}
|
||||
{{- if index $.hostvars . "kubernetes_install_service" "stdout" | eq "active" -}}
|
||||
{{- $initNodes = append $initNodes . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if $initNodes | len | eq 1 -}}
|
||||
{{ $initNodes | first }}
|
||||
{{ $initNodes | first }}
|
||||
{{- else if $initNodes | len | lt 1 -}}
|
||||
{{ index $initNodes (randInt 0 ((sub ($initNodes | len) 1) | int)) }}
|
||||
{{ index $initNodes (randInt 0 ((sub ($initNodes | len) 1) | int)) }}
|
||||
{{- end -}}
|
||||
- name: init node
|
||||
when: eq .inventory_name .init_kubernetes_node
|
||||
when: eq .inventory_hostname .init_kubernetes_node
|
||||
block:
|
||||
- name: Generate certificate key by kubeadm
|
||||
command: |
|
||||
|
|
@ -80,15 +80,15 @@
|
|||
- k8s_cluster
|
||||
roles:
|
||||
- role: install/cri
|
||||
when: or (.add_nodes | default list | len | eq 0) (.add_nodes | default list | has .inventory_name)
|
||||
when: or (.add_nodes | default list | len | eq 0) (.add_nodes | default list | has .inventory_hostname)
|
||||
- role: kubernetes/pre-kubernetes
|
||||
when: or (.add_nodes | default list | len | eq 0) (.add_nodes | default list | has .inventory_name)
|
||||
when: or (.add_nodes | default list | len | eq 0) (.add_nodes | default list | has .inventory_hostname)
|
||||
- role: kubernetes/join-kubernetes
|
||||
when: or (.add_nodes | default list | len | eq 0) (.add_nodes | default list | has .inventory_name)
|
||||
when: or (.add_nodes | default list | len | eq 0) (.add_nodes | default list | has .inventory_hostname)
|
||||
- role: kubernetes/certs
|
||||
when:
|
||||
- or (.add_nodes | default list | len | eq 0) (.add_nodes | default list | has .inventory_name)
|
||||
- .groups.kube_control_plane | default list | has .inventory_name
|
||||
- or (.add_nodes | default list | len | eq 0) (.add_nodes | default list | has .inventory_hostname)
|
||||
- .groups.kube_control_plane | default list | has .inventory_hostname
|
||||
- .kubernetes.renew_certs.enabled
|
||||
|
||||
- import_playbook: hook/post_install.yaml
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
- role: kubernetes/certs
|
||||
when:
|
||||
- .kubernetes.renew_certs.enabled
|
||||
- .groups.kube_control_plane | default list | has .inventory_name
|
||||
- .groups.kube_control_plane | default list | has .inventory_hostname
|
||||
post_tasks:
|
||||
- name: Add custom label to cluster
|
||||
command: |
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@
|
|||
ignore_errors: true
|
||||
copy:
|
||||
src: |
|
||||
{{ .scripts_dir }}/post_install_{{ .inventory_name }}.sh
|
||||
{{ .scripts_dir }}/post_install_{{ .inventory_hostname }}.sh
|
||||
dest: |
|
||||
/etc/kubekey/scripts/post_install_{{ .inventory_name }}.sh
|
||||
/etc/kubekey/scripts/post_install_{{ .inventory_hostname }}.sh
|
||||
mode: 0755
|
||||
register: execute_result
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@
|
|||
ignore_errors: true
|
||||
copy:
|
||||
src: |
|
||||
{{ .work_dir }}/scripts/pre_install_{{ .inventory_name }}.sh
|
||||
{{ .work_dir }}/scripts/pre_install_{{ .inventory_hostname }}.sh
|
||||
dest: |
|
||||
/etc/kubekey/scripts/pre_install_{{ .inventory_name }}.sh
|
||||
/etc/kubekey/scripts/pre_install_{{ .inventory_hostname }}.sh
|
||||
mode: 0755
|
||||
register: execute_result
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
sans: |
|
||||
{{- $ips := list }}
|
||||
{{- range .groups.etcd | default list }}
|
||||
{{- $internalIPv4 := index $.inventory_hosts . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.inventory_hosts . "internal_ipv6" | default "" }}
|
||||
{{- $internalIPv4 := index $.hostvars . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.hostvars . "internal_ipv6" | default "" }}
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
{{- $ips = append $ips $internalIPv4 }}
|
||||
{{- end }}
|
||||
|
|
@ -47,8 +47,8 @@
|
|||
sans: |
|
||||
{{- $ips := list }}
|
||||
{{- range .groups.image_registry | default list }}
|
||||
{{- $internalIPv4 := index $.inventory_hosts . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.inventory_hosts . "internal_ipv6" | default "" }}
|
||||
{{- $internalIPv4 := index $.hostvars . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.hostvars . "internal_ipv6" | default "" }}
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
{{- $ips = append $ips $internalIPv4 }}
|
||||
{{- end }}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
{{- range $server := .ntp.servers }}
|
||||
{{- $internalIPv4 := "" }}
|
||||
{{- $internalIPv6 := "" }}
|
||||
{{- range $.inventory_hosts }}
|
||||
{{- range $.hostvars }}
|
||||
{{- if eq .hostname $server }}
|
||||
{{- $internalIPv4 = .internal_ipv4 | default "" }}
|
||||
{{- $internalIPv6 = .internal_ipv6 | default "" }}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
mv /etc/apt/sources.list.kubekey.bak-$now /etc/apt/sources.list
|
||||
mv /etc/apt/sources.list.d.kubekey.bak-$now /etc/apt/sources.list.d
|
||||
else
|
||||
apt-get update && apt install -y socat conntrack ipset ebtables chrony ipvsadm {{ if .groups.nfs | default list | has .inventory_name }}nfs-kernel-server{{ end }}
|
||||
apt-get update && apt install -y socat conntrack ipset ebtables chrony ipvsadm {{ if .groups.nfs | default list | has .inventory_hostname }}nfs-kernel-server{{ end }}
|
||||
fi
|
||||
when: .os.release.ID_LIKE | eq "debian"
|
||||
- name: Init rhel repository
|
||||
|
|
@ -68,7 +68,7 @@
|
|||
# update repository
|
||||
yum clean all && yum makecache
|
||||
# install
|
||||
yum install -y openssl socat conntrack ipset ebtables chrony ipvsadm {{ if .groups.nfs | default list | has .inventory_name }}nfs-utils{{ end }}
|
||||
yum install -y openssl socat conntrack ipset ebtables chrony ipvsadm {{ if .groups.nfs | default list | has .inventory_hostname }}nfs-utils{{ end }}
|
||||
# reset repository
|
||||
rm -rf /etc/yum.repos.d
|
||||
mv /etc/yum.repos.d.kubekey.bak-$now /etc/yum.repos.d
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@
|
|||
|
||||
- name: Set hostname
|
||||
command: |
|
||||
hostnamectl set-hostname {{ .inventory_name }} \
|
||||
&& sed -i '/^127.0.1.1/s/.*/127.0.1.1 {{ .inventory_name }}/g' /etc/hosts
|
||||
hostnamectl set-hostname {{ .inventory_hostname }} \
|
||||
&& sed -i '/^127.0.1.1/s/.*/127.0.1.1 {{ .inventory_hostname }}/g' /etc/hosts
|
||||
when:
|
||||
- .set_hostname
|
||||
- .inventory_name | ne "localhost"
|
||||
- .inventory_hostname | ne "localhost"
|
||||
|
||||
- name: Sync init os to remote
|
||||
template:
|
||||
|
|
|
|||
|
|
@ -210,41 +210,41 @@ cat >>/etc/hosts<<EOF
|
|||
# kubekey hosts BEGIN
|
||||
# kubernetes hosts
|
||||
{{- range .groups.k8s_cluster | default list }}
|
||||
{{- $hostname := index $.inventory_hosts . "hostname" -}}
|
||||
{{- $hostname := index $.hostvars . "hostname" -}}
|
||||
{{- $clusterName := $.kubernetes.cluster_name | default "kubekey" -}}
|
||||
{{- $dnsDomain := $.kubernetes.networking.dns_domain | default "cluster.local" -}}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv4") (ne (index $.inventory_hosts . "internal_ipv4") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv4" }} {{ $hostname }} {{ printf "%s.%s" $hostname $clusterName }} {{ printf "%s.%s.%s" $hostname $clusterName $dnsDomain }}
|
||||
{{- if and (index $.hostvars . "internal_ipv4") (ne (index $.hostvars . "internal_ipv4") "") }}
|
||||
{{ index $.hostvars . "internal_ipv4" }} {{ $hostname }} {{ printf "%s.%s" $hostname $clusterName }} {{ printf "%s.%s.%s" $hostname $clusterName $dnsDomain }}
|
||||
{{- end }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv6") (ne (index $.inventory_hosts . "internal_ipv6") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv6" }} {{ $hostname }} {{ printf "%s.%s" $hostname $clusterName }} {{ printf "%s.%s.%s" $hostname $clusterName $dnsDomain }}
|
||||
{{- if and (index $.hostvars . "internal_ipv6") (ne (index $.hostvars . "internal_ipv6") "") }}
|
||||
{{ index $.hostvars . "internal_ipv6" }} {{ $hostname }} {{ printf "%s.%s" $hostname $clusterName }} {{ printf "%s.%s.%s" $hostname $clusterName $dnsDomain }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
# etcd hosts
|
||||
{{- range .groups.etcd | default list }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv4") (ne (index $.inventory_hosts . "internal_ipv4") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv4" }} {{ index $.inventory_hosts . "hostname" }}
|
||||
{{- if and (index $.hostvars . "internal_ipv4") (ne (index $.hostvars . "internal_ipv4") "") }}
|
||||
{{ index $.hostvars . "internal_ipv4" }} {{ index $.hostvars . "hostname" }}
|
||||
{{- end }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv6") (ne (index $.inventory_hosts . "internal_ipv6") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv6" }} {{ index $.inventory_hosts . "hostname" }}
|
||||
{{- if and (index $.hostvars . "internal_ipv6") (ne (index $.hostvars . "internal_ipv6") "") }}
|
||||
{{ index $.hostvars . "internal_ipv6" }} {{ index $.hostvars . "hostname" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
# image registry hosts
|
||||
{{- range .groups.image_registry | default list }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv4") (ne (index $.inventory_hosts . "internal_ipv4") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv4" }} {{ index $.inventory_hosts . "hostname" }}
|
||||
{{- if and (index $.hostvars . "internal_ipv4") (ne (index $.hostvars . "internal_ipv4") "") }}
|
||||
{{ index $.hostvars . "internal_ipv4" }} {{ index $.hostvars . "hostname" }}
|
||||
{{- end }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv6") (ne (index $.inventory_hosts . "internal_ipv6") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv6" }} {{ index $.inventory_hosts . "hostname" }}
|
||||
{{- if and (index $.hostvars . "internal_ipv6") (ne (index $.hostvars . "internal_ipv6") "") }}
|
||||
{{ index $.hostvars . "internal_ipv6" }} {{ index $.hostvars . "hostname" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
# nfs hosts
|
||||
{{- range .groups.nfs | default list }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv4") (ne (index $.inventory_hosts . "internal_ipv4") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv4" }} {{ index $.inventory_hosts . "hostname" }}
|
||||
{{- if and (index $.hostvars . "internal_ipv4") (ne (index $.hostvars . "internal_ipv4") "") }}
|
||||
{{ index $.hostvars . "internal_ipv4" }} {{ index $.hostvars . "hostname" }}
|
||||
{{- end }}
|
||||
{{- if and (index $.inventory_hosts . "internal_ipv6") (ne (index $.inventory_hosts . "internal_ipv6") "") }}
|
||||
{{ index $.inventory_hosts . "internal_ipv4" }} {{ index $.inventory_hosts . "hostname" }}
|
||||
{{- if and (index $.hostvars . "internal_ipv6") (ne (index $.hostvars . "internal_ipv6") "") }}
|
||||
{{ index $.hostvars . "internal_ipv4" }} {{ index $.hostvars . "hostname" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
# kubekey hosts END
|
||||
|
|
|
|||
|
|
@ -134,8 +134,8 @@ cni:
|
|||
address: {{ .dockerio_registry }}/kubeovn
|
||||
{{- $ips := list }}
|
||||
{{- range .groups.kube_control_plane | default list }}
|
||||
{{- $internalIPv4 := index $.inventory_hosts . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.inventory_hosts . "internal_ipv6" | default "" }}
|
||||
{{- $internalIPv4 := index $.hostvars . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.hostvars . "internal_ipv6" | default "" }}
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
{{- $ips = append $ips $internalIPv4 }}
|
||||
{{- else if ne $internalIPv6 "" }}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ image_registry:
|
|||
{{- if and .image_registry.ha_vip (ne .image_registry.ha_vip "") }}
|
||||
{{ .image_registry.ha_vip }}
|
||||
{{- else if .groups.image_registry | default list | len | lt 0 }}
|
||||
{{- $internalIPv4 := index .inventory_hosts (.groups.image_registry | default list | first) "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index .inventory_hosts (.groups.image_registry | default list | first) "internal_ipv6" | default "" }}
|
||||
{{- $internalIPv4 := index .hostvars (.groups.image_registry | default list | first) "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index .hostvars (.groups.image_registry | default list | first) "internal_ipv6" | default "" }}
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
{{ $internalIPv4 }}
|
||||
{{- else if ne $internalIPv6 "" }}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ ETCD_PROXY=off
|
|||
ETCD_ENABLE_V2=true
|
||||
{{- $ips := list }}
|
||||
{{- range .groups.etcd | default list }}
|
||||
{{- $internalIPv4 := index $.inventory_hosts . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.inventory_hosts . "internal_ipv6" | default "" }}
|
||||
{{- $internalIPv4 := index $.hostvars . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.hostvars . "internal_ipv6" | default "" }}
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
{{- $ips = append $ips (printf "%s=https://%s:2380" (index $.inventory_hosts . "hostname") $internalIPv4) }}
|
||||
{{- $ips = append $ips (printf "%s=https://%s:2380" (index $.hostvars . "hostname") $internalIPv4) }}
|
||||
{{- else if ne $internalIPv6 "" }}
|
||||
{{- $ips = append $ips (printf "%s=https://%s:2380" (index $.inventory_hosts . "hostname") $internalIPv6) }}
|
||||
{{- $ips = append $ips (printf "%s=https://%s:2380" (index $.hostvars . "hostname") $internalIPv6) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
ETCD_INITIAL_CLUSTER={{ $ips | join "," }}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ image_registry:
|
|||
{{- if and .image_registry.ha_vip (ne .image_registry.ha_vip "") }}
|
||||
{{ .image_registry.ha_vip }}
|
||||
{{- else if .groups.image_registry | default list | len | lt 0 }}
|
||||
{{- $internalIPv4 := index .inventory_hosts (.groups.image_registry | default list | first) "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index .inventory_hosts (.groups.image_registry | default list | first) "internal_ipv6" | default "" }}
|
||||
{{- $internalIPv4 := index .hostvars (.groups.image_registry | default list | first) "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index .hostvars (.groups.image_registry | default list | first) "internal_ipv6" | default "" }}
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
{{ $internalIPv4 }}
|
||||
{{- else if ne $internalIPv6 "" }}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@
|
|||
apt update && apt install -y nfs-common
|
||||
{{- end }}
|
||||
{{- if }}
|
||||
{{- $internalIPv4 := index .inventory_hosts (.groups.nfs | default list | first) "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index .inventory_hosts (.groups.nfs | default list | first) "internal_ipv6" | default "" }}
|
||||
{{- $internalIPv4 := index .hostvars (.groups.nfs | default list | first) "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index .hostvars (.groups.nfs | default list | first) "internal_ipv6" | default "" }}
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
mount -t nfs {{ $internalIPv4 }}:{{ .image_registry.registry.storage.filesystem.nfs_mount }} {{ .image_registry.registry.storage.filesystem.rootdir }}
|
||||
{{- else if ne $internalIPv6 "" }}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
chmod 600 /etc/ssl/etcd/ssl/* && chown root:root /etc/ssl/etcd/ssl/*
|
||||
chmod 700 /var/lib/etcd && chown etcd:etcd /var/lib/etcd
|
||||
chmod 550 /usr/local/bin/etcd* && chown root:root /usr/local/bin/etcd*
|
||||
when: .groups.etcd | default list | has .inventory_name
|
||||
when: .groups.etcd | default list | has .inventory_hostname
|
||||
|
||||
- name: security enhancement for control plane
|
||||
command: |
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
chmod 640 /var/lib/kubelet/config.yaml && chown root:root /var/lib/kubelet/config.yaml
|
||||
chmod 640 -R /etc/systemd/system/kubelet.service* && chown root:root -R /etc/systemd/system/kubelet.service*
|
||||
chmod 640 /etc/systemd/system/k8s-certs-renew* && chown root:root /etc/systemd/system/k8s-certs-renew*
|
||||
when: .groups.kube_control_plane | default list | has .inventory_name
|
||||
when: .groups.kube_control_plane | default list | has .inventory_hostname
|
||||
|
||||
- name: security enhancement for worker
|
||||
command: |
|
||||
|
|
@ -36,4 +36,4 @@
|
|||
chmod 550 -R /opt/cni/bin && chown root:root -R /opt/cni/bin
|
||||
chmod 640 /var/lib/kubelet/config.yaml && chown root:root /var/lib/kubelet/config.yaml
|
||||
chmod 640 -R /etc/systemd/system/kubelet.service* && chown root:root -R /etc/systemd/system/kubelet.service*
|
||||
when: .groups.kube_worker | default list | has .inventory_name
|
||||
when: .groups.kube_worker | default list | has .inventory_hostname
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
- name: Sync external etcd config
|
||||
when:
|
||||
- and (.kubernetes.etcd.deployment_type | eq "external") (.groups.etcd | default list | len | lt 0)
|
||||
- .groups.kube_control_plane | default list | has .inventory_name
|
||||
- .groups.kube_control_plane | default list | has .inventory_hostname
|
||||
block:
|
||||
- name: Sync etcd ca file to remote
|
||||
copy:
|
||||
|
|
@ -62,7 +62,7 @@
|
|||
when: .kubernetes_install_service.stdout | eq "inactive"
|
||||
|
||||
- name: Set to worker node
|
||||
when: .groups.kube_worker | default list | has .inventory_name
|
||||
when: .groups.kube_worker | default list | has .inventory_hostname
|
||||
block:
|
||||
- name: Remote master taint
|
||||
ignore_errors: true
|
||||
|
|
|
|||
|
|
@ -6,20 +6,20 @@
|
|||
{{- $initNodes := list -}}
|
||||
{{- $notInitNodes := list -}}
|
||||
{{- range .groups.kube_control_plane -}}
|
||||
{{- if index $.inventory_hosts . "kubernetes_install_service" "stdout" | eq "active" -}}
|
||||
{{- if index $.hostvars . "kubernetes_install_service" "stdout" | eq "active" -}}
|
||||
{{- $initNodes = append $initNodes . -}}
|
||||
{{- else if index $.inventory_hosts . "kubernetes_install_service" "stdout" | eq "inactive" -}}
|
||||
{{- else if index $.hostvars . "kubernetes_install_service" "stdout" | eq "inactive" -}}
|
||||
{{- $notInitNodes = append $notInitNodes . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if $initNodes | len | eq 1 -}}
|
||||
{{ $initNodes | first }}
|
||||
{{ $initNodes | first }}
|
||||
{{- else if $initNodes | len | lt 1 -}}
|
||||
{{ index $initNodes (randInt 0 ((sub ($initNodes | len) 1) | int)) }}
|
||||
{{ index $initNodes (randInt 0 ((sub ($initNodes | len) 1) | int)) }}
|
||||
{{- else if $notInitNodes | len | eq 1 -}}
|
||||
{{ $notInitNodes | first }}
|
||||
{{ $notInitNodes | first }}
|
||||
{{- else if $notInitNodes | len | lt 1 }}
|
||||
{{ index $notInitNodes (randInt 0 ((sub ($notInitNodes | len) 1) | int)) }}
|
||||
{{ index $notInitNodes (randInt 0 ((sub ($notInitNodes | len) 1) | int)) }}
|
||||
{{- end -}}
|
||||
|
||||
- name: Set custom hosts to /etc/hosts
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
EOF
|
||||
|
||||
- name: Init kubernetes
|
||||
when: eq .inventory_name .init_kubernetes_node
|
||||
when: eq .inventory_hostname .init_kubernetes_node
|
||||
block:
|
||||
- include_tasks: init_kubernetes.yaml
|
||||
when: .kubernetes_install_service.stdout | eq "inactive"
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ etcd:
|
|||
imageTag: {{ .kubernetes.etcd.image.tag }}
|
||||
serverCertSANs:
|
||||
{{- range .groups.etcd | default list }}
|
||||
- {{ index $.inventory_hosts . "internal_ipv4" }}
|
||||
- {{ index $.hostvars . "internal_ipv4" }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
external:
|
||||
endpoints:
|
||||
{{- range .groups.etcd | default list }}
|
||||
- https://{{ index $.inventory_hosts . "internal_ipv4" }}:2379
|
||||
- https://{{ index $.hostvars . "internal_ipv4" }}:2379
|
||||
{{- end }}
|
||||
caFile: /etc/kubernetes/pki/etcd/ca.crt
|
||||
certFile: /etc/kubernetes/pki/etcd/client.crt
|
||||
|
|
@ -73,11 +73,11 @@ apiServer:
|
|||
- {{ .kubernetes.networking.service_cidr | ipInCIDR 0 }}
|
||||
- {{ .kubernetes.control_plane_endpoint.host }}
|
||||
{{- range .groups.k8s_cluster | default list }}
|
||||
- {{ index $.inventory_hosts . "hostname" }}
|
||||
- {{ index $.inventory_hosts . "hostname" }}.{{ $.kubernetes.cluster_name }}
|
||||
- {{ index $.inventory_hosts . "hostname" }}.{{ $.kubernetes.cluster_name }}.{{ $.kubernetes.networking.dns_domain }}
|
||||
{{- $internalIPv4 := index $.inventory_hosts . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.inventory_hosts . "internal_ipv6" | default "" }}
|
||||
- {{ index $.hostvars . "hostname" }}
|
||||
- {{ index $.hostvars . "hostname" }}.{{ $.kubernetes.cluster_name }}
|
||||
- {{ index $.hostvars . "hostname" }}.{{ $.kubernetes.cluster_name }}.{{ $.kubernetes.networking.dns_domain }}
|
||||
{{- $internalIPv4 := index $.hostvars . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.hostvars . "internal_ipv6" | default "" }}
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
- {{ $internalIPv4 }}
|
||||
{{- end }}
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ etcd:
|
|||
imageTag: {{ .kubernetes.etcd.image.tag }}
|
||||
serverCertSANs:
|
||||
{{- range .groups.etcd | default list }}
|
||||
- {{ index $.inventory_hosts . "internal_ipv4" }}
|
||||
- {{ index $.hostvars . "internal_ipv4" }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
external:
|
||||
endpoints:
|
||||
{{- range .groups.etcd | default list }}
|
||||
- https://{{ index $.inventory_hosts . "internal_ipv4" }}:2379
|
||||
- https://{{ index $.hostvars . "internal_ipv4" }}:2379
|
||||
{{- end }}
|
||||
caFile: /etc/kubernetes/pki/etcd/ca.crt
|
||||
certFile: /etc/kubernetes/pki/etcd/client.crt
|
||||
|
|
@ -72,11 +72,11 @@ apiServer:
|
|||
- {{ .kubernetes.networking.service_cidr | ipInCIDR 0 }}
|
||||
- {{ .kubernetes.control_plane_endpoint.host }}
|
||||
{{- range .groups.k8s_cluster | default list }}
|
||||
- {{ index $.inventory_hosts . "hostname" }}
|
||||
- {{ index $.inventory_hosts . "hostname" }}.{{ $.kubernetes.cluster_name }}
|
||||
- {{ index $.inventory_hosts . "hostname" }}.{{ $.kubernetes.cluster_name }}.{{ $.kubernetes.networking.dns_domain }}
|
||||
{{- $internalIPv4 := index $.inventory_hosts . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.inventory_hosts . "internal_ipv6" | default "" }}
|
||||
- {{ index $.hostvars . "hostname" }}
|
||||
- {{ index $.hostvars . "hostname" }}.{{ $.kubernetes.cluster_name }}
|
||||
- {{ index $.hostvars . "hostname" }}.{{ $.kubernetes.cluster_name }}.{{ $.kubernetes.networking.dns_domain }}
|
||||
{{- $internalIPv4 := index $.hostvars . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.hostvars . "internal_ipv6" | default "" }}
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
- {{ $internalIPv4 }}
|
||||
{{- end }}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@
|
|||
sed -i ':a;$!{N;ba};s@# kubekey custom BEGIN.*# kubekey custom END@@' /etc/hosts
|
||||
cat >> /etc/hosts <<EOF
|
||||
# kubekey custom BEGIN
|
||||
{{- if and (index .inventory_hosts .init_kubernetes_node "internal_ipv4") (ne (index .inventory_hosts .init_kubernetes_node "internal_ipv4") "") }}
|
||||
{{ index .inventory_hosts .init_kubernetes_node "internal_ipv4" }} {{ .kubernetes.control_plane_endpoint.host }}
|
||||
{{- if and (index .hostvars .init_kubernetes_node "internal_ipv4") (ne (index .hostvars .init_kubernetes_node "internal_ipv4") "") }}
|
||||
{{ index .hostvars .init_kubernetes_node "internal_ipv4" }} {{ .kubernetes.control_plane_endpoint.host }}
|
||||
{{- end }}
|
||||
{{- if and (index .inventory_hosts .init_kubernetes_node "internal_ipv6") (ne (index .inventory_hosts .init_kubernetes_node "internal_ipv6") "") }}
|
||||
{{ index .inventory_hosts .init_kubernetes_node "internal_ipv6" }} {{ .kubernetes.control_plane_endpoint.host }}
|
||||
{{- if and (index .hostvars .init_kubernetes_node "internal_ipv6") (ne (index .hostvars .init_kubernetes_node "internal_ipv6") "") }}
|
||||
{{ index .hostvars .init_kubernetes_node "internal_ipv6" }} {{ .kubernetes.control_plane_endpoint.host }}
|
||||
{{- end }}
|
||||
# kubekey custom END
|
||||
EOF
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
dest: /root/.kube/config
|
||||
|
||||
- name: Set to worker node
|
||||
when: .groups.kube_worker | default list | has .inventory_name
|
||||
when: .groups.kube_worker | default list | has .inventory_hostname
|
||||
block:
|
||||
- name: Remote master taint
|
||||
ignore_errors: true
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
- name: Set change custom hosts to /etc/hosts
|
||||
when:
|
||||
- eq .kubernetes.control_plane_endpoint.type "local"
|
||||
- .groups.kube_control_plane | default list | has .inventory_name
|
||||
- .groups.kube_control_plane | default list | has .inventory_hostname
|
||||
command: |
|
||||
sed -i ':a;$!{N;ba};s@# kubekey custom BEGIN.*# kubekey custom END@@' /etc/hosts
|
||||
cat >> /etc/hosts <<EOF
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
- name: Join kubernetes
|
||||
when: ne .inventory_name .init_kubernetes_node
|
||||
when: ne .inventory_hostname .init_kubernetes_node
|
||||
block:
|
||||
# HAProxy is deployed as a static Pod, which starts only after Kubelet is running.
|
||||
# Therefore, the control plane must be reachable before HAProxy starts (e.g., by configuring /etc/hosts).
|
||||
|
|
@ -7,8 +7,8 @@
|
|||
command: |
|
||||
cat >> /etc/hosts << EOF
|
||||
# haproxy dns for kubekey begin
|
||||
{{- $internalIPv4 := index .inventory_hosts (.groups.kube_control_plane | default list | first) "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index .inventory_hosts (.groups.kube_control_plane | default list | first) "internal_ipv6" | default "" }}
|
||||
{{- $internalIPv4 := index .hostvars (.groups.kube_control_plane | default list | first) "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index .hostvars (.groups.kube_control_plane | default list | first) "internal_ipv6" | default "" }}
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
{{ $internalIPv4 }} {{ .kubernetes.control_plane_endpoint.host }}
|
||||
{{- else if ne $internalIPv6 "" }}
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
when: .kubernetes.control_plane_endpoint.type | eq "haproxy"
|
||||
block:
|
||||
- name: Replace control_plane by local hosts
|
||||
when: .groups.kube_control_plane | default list | has .inventory_name
|
||||
when: .groups.kube_control_plane | default list | has .inventory_hostname
|
||||
command: |
|
||||
new_dns="# haproxy dns for kubekey begin
|
||||
{{- if ne .internal_ipv4 "" }}
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
# haproxy dns for kubekey end"
|
||||
sed -i '/# haproxy dns for kubekey begin/,/# haproxy dns for kubekey end/c\'"$new_dns" /etc/hosts
|
||||
- name: Replace worker by haproxy hosts
|
||||
when: .groups.worker | default list | has .inventory_name
|
||||
when: .groups.worker | default list | has .inventory_hostname
|
||||
command: |
|
||||
new_dns="# haproxy dns for kubekey begin
|
||||
{{ .kubernetes.control_plane_endpoint.haproxy.address }} {{ .kubernetes.control_plane_endpoint.host }}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ discovery:
|
|||
apiServerEndpoint: {{ .kubernetes.control_plane_endpoint.host }}:{{ .kubernetes.control_plane_endpoint.port }}
|
||||
token: "{{ .kubeadm_token }}"
|
||||
unsafeSkipCAVerification: true
|
||||
{{- if .groups.kube_control_plane | default list | has .inventory_name }}
|
||||
{{- if .groups.kube_control_plane | default list | has .inventory_hostname }}
|
||||
controlPlane:
|
||||
localAPIEndpoint:
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ discovery:
|
|||
apiServerEndpoint: {{ .kubernetes.control_plane_endpoint.host }}:{{ .kubernetes.control_plane_endpoint.port }}
|
||||
token: "{{ .kubeadm_token }}"
|
||||
unsafeSkipCAVerification: true
|
||||
{{- if .groups.kube_control_plane | default list | has .inventory_name }}
|
||||
{{- if .groups.kube_control_plane | default list | has .inventory_hostname }}
|
||||
controlPlane:
|
||||
localAPIEndpoint:
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
- include_tasks: high-availability/kube_vip.yaml
|
||||
when:
|
||||
- .kubernetes.control_plane_endpoint.type | eq "kube_vip"
|
||||
- .groups.kube_control_plane | default list | has .inventory_name
|
||||
- .groups.kube_control_plane | default list | has .inventory_hostname
|
||||
|
||||
# only deploy haproxy in worker node. control_plane node use local static pod: kube-apiserver.
|
||||
- include_tasks: high-availability/haproxy.yaml
|
||||
when:
|
||||
- .kubernetes.control_plane_endpoint.type | eq "haproxy"
|
||||
- .groups.kube_worker | default list | has .inventory_name
|
||||
- .groups.kube_worker | default list | has .inventory_hostname
|
||||
|
|
@ -37,11 +37,11 @@ backend kube_api_backend
|
|||
option httpchk GET /healthz
|
||||
http-check expect status 200
|
||||
{{- range .groups.kube_control_plane | default list }}
|
||||
{{- $internalIPv4 := index $.inventory_hosts . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.inventory_hosts . "internal_ipv6" | default "" }}
|
||||
{{- $internalIPv4 := index $.hostvars . "internal_ipv4" | default "" }}
|
||||
{{- $internalIPv6 := index $.hostvars . "internal_ipv6" | default "" }}
|
||||
{{- if ne $internalIPv4 "" }}
|
||||
server {{ index $.inventory_hosts . "hostname" }} {{ $internalIPv4 }}:{{ $.kubernetes.apiserver.port }} check check-ssl verify none
|
||||
server {{ index $.hostvars . "hostname" }} {{ $internalIPv4 }}:{{ $.kubernetes.apiserver.port }} check check-ssl verify none
|
||||
{{- else if ne $internalIPv6 "" }}
|
||||
server {{ index $.inventory_hosts . "hostname" }} {{ $internalIPv6 }}:{{ $.kubernetes.apiserver.port }} check check-ssl verify none
|
||||
server {{ index $.hostvars . "hostname" }} {{ $internalIPv6 }}:{{ $.kubernetes.apiserver.port }} check check-ssl verify none
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ spec:
|
|||
value: |
|
||||
{{- $ips := list }}
|
||||
{{- range .groups.kube_control_plane | default list }}
|
||||
{{- $ips = append $ips (index $.inventory_hosts . "internal_ipv4") }}
|
||||
{{- $ips = append $ips (index $.hostvars . "internal_ipv4") }}
|
||||
{{- end }}
|
||||
{{ $ips | join "," }}
|
||||
- name: bgp_as
|
||||
|
|
@ -44,7 +44,7 @@ spec:
|
|||
value: |
|
||||
{{- $ips := list }}
|
||||
{{- range .groups.kube_control_plane | default list }}
|
||||
{{- $ips = append $ips (printf "%s:65000::false" (index $.inventory_hosts . "internal_ipv4")) }}
|
||||
{{- $ips = append $ips (printf "%s:65000::false" (index $.hostvars . "internal_ipv4")) }}
|
||||
{{- end }}
|
||||
{{ $ips | join "," }}
|
||||
- name: lb_enable
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
## https://cwiki.yunify.com/pages/viewpage.action?pageId=145920824
|
||||
- name: Check dev io for etcd
|
||||
when:
|
||||
- .groups.etcd | default list | has .inventory_name
|
||||
- .groups.etcd | default list | has .inventory_hostname
|
||||
block:
|
||||
- name: Check fio is exist
|
||||
ignore_errors: true
|
||||
|
|
@ -48,7 +48,7 @@
|
|||
command: rm -rf {{ .tmp_dir }}/etcd/test-data
|
||||
|
||||
- name: Check if etcd has installed
|
||||
when: .groups.etcd | default list | has .inventory_name
|
||||
when: .groups.etcd | default list | has .inventory_hostname
|
||||
block:
|
||||
- name: Get etcd service
|
||||
ignore_errors: true
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
- |
|
||||
{{- $existIP := false }}
|
||||
{{- range .groups.all | default list }}
|
||||
{{- if eq $.kubernetes.control_plane_endpoint.kube_vip.address (index $.inventory_hosts . "internal_ipv4") }}
|
||||
{{- if eq $.kubernetes.control_plane_endpoint.kube_vip.address (index $.hostvars . "internal_ipv4") }}
|
||||
{{- $existIP = true }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
when: and .kube_version (ne .kube_version "")
|
||||
|
||||
- name: Check if kubernetes installed
|
||||
when: .groups.k8s_cluster | default list | has .inventory_name
|
||||
when: .groups.k8s_cluster | default list | has .inventory_hostname
|
||||
block:
|
||||
- name: Get kubernetes service
|
||||
ignore_errors: true
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@
|
|||
# provisioning time, so to establish a guarantee, we factor these out.
|
||||
# NOTICE: the check blatantly ignores the inet6-case
|
||||
- name: Guarantee that enough network address space is available for all pods
|
||||
when: .groups.k8s_cluster | default list | has .inventory_name
|
||||
when: .groups.k8s_cluster | default list | has .inventory_hostname
|
||||
block:
|
||||
- name: Guarantee that enough ipv4 network address space is available for all pods
|
||||
when: .kubernetes.networking.pod_cidr | default "10.233.64.0/18" | splitList "," | first | ipFamily | eq "IPv4"
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@
|
|||
- name: Stop if memory is too small for masters
|
||||
assert:
|
||||
that: .process.memInfo.MemTotal | trimSuffix " kB" | atoi | le .cluster_require.minimal_master_memory_mb
|
||||
when: .groups.kube_control_plane | default list | has .inventory_name
|
||||
when: .groups.kube_control_plane | default list | has .inventory_hostname
|
||||
|
||||
- name: Stop if memory is too small for nodes
|
||||
assert:
|
||||
that: .process.memInfo.MemTotal | trimSuffix " kB" | atoi | le .cluster_require.minimal_node_memory_mb
|
||||
when:
|
||||
- .groups.kube_worker | default list | has .inventory_name
|
||||
- .groups.kube_worker | default list | has .inventory_hostname
|
||||
|
||||
- name: Stop if kernel version is too low
|
||||
assert:
|
||||
|
|
|
|||
|
|
@ -48,12 +48,12 @@ const ( // === From Global Parameter ===
|
|||
|
||||
const ( // === From system generate ===
|
||||
// VariableInventoryName the value which defined in inventory.spec.host.
|
||||
VariableInventoryName = "inventory_name"
|
||||
VariableInventoryName = "inventory_hostname"
|
||||
// VariableHostName the value is node hostname, default VariableInventoryName.
|
||||
// If VariableInventoryName is "localhost". try to set the actual name.
|
||||
VariableHostName = "hostname"
|
||||
// VariableGlobalHosts the value is host_var which defined in inventory.
|
||||
VariableGlobalHosts = "inventory_hosts"
|
||||
VariableGlobalHosts = "hostvars"
|
||||
// VariableGroupsAll the value is a all host_name slice of VariableGroups.
|
||||
VariableGroupsAll = "all"
|
||||
// VariableUnGrouped the value is a all host_name slice of VariableGroups.
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ work_dir/
|
|||
| | | | | |-- playbook.yaml
|
||||
| | | | | |-- /playbookName/variable/
|
||||
| | | | | | |-- location.yaml
|
||||
| | | | | | |-- inventory_name1.yaml
|
||||
| | | | | | |-- inventory_name2.yaml
|
||||
| | | | | | |-- inventory_hostname1.yaml
|
||||
| | | | | | |-- inventory_hostname2.yaml
|
||||
|
|
||||
| | | |-- inventories/
|
||||
| | | | |-- namespace/
|
||||
|
|
|
|||
|
|
@ -159,19 +159,19 @@ func TestGetAllVariable(t *testing.T) {
|
|||
"images": []any{"abc"},
|
||||
},
|
||||
"groups": map[string][]string{"all": {"localhost"}, "ungrouped": {"localhost"}},
|
||||
"inventory_hosts": map[string]any{
|
||||
"hostvars": map[string]any{
|
||||
"localhost": map[string]any{
|
||||
"internal_ipv4": "127.0.0.1",
|
||||
"internal_ipv6": "::1",
|
||||
"artifact": map[string]any{
|
||||
"images": []any{"abc"},
|
||||
},
|
||||
"inventory_name": "localhost",
|
||||
"hostname": "localhost",
|
||||
"inventory_hostname": "localhost",
|
||||
"hostname": "localhost",
|
||||
},
|
||||
},
|
||||
"inventory_name": "localhost",
|
||||
"hostname": "localhost",
|
||||
"inventory_hostname": "localhost",
|
||||
"hostname": "localhost",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@
|
|||
export $(cat /etc/etcd.env | grep ETCDCTL_CERT)
|
||||
export $(cat /etc/etcd.env | grep ETCDCTL_KEY)
|
||||
etcdctl snapshot restore /tmp/kubekey/etcd/snapshot.db \
|
||||
--name={{ .inventory_name }} --endpoints=https://{{ .internal_ipv4 }}:2379 \
|
||||
--name={{ .inventory_hostname }} --endpoints=https://{{ .internal_ipv4 }}:2379 \
|
||||
{{- $ips := list -}}
|
||||
{{- range $element := .groups.etcd -}}
|
||||
{{- $ips = append $ips (printf "%s=https://%s:2380" (index .inventory_hosts $element "inventory_name") (index .inventory_hosts $element "internal_ipv4") -}}
|
||||
{{- $ips = append $ips (printf "%s=https://%s:2380" (index .hostvars $element "inventory_hostname") (index .hostvars $element "internal_ipv4") -}}
|
||||
{{- end -}}
|
||||
--initial-cluster={{ $ips | join "," }} \
|
||||
--initial-advertise-peer-urls=https://{{ .internal_ipv4 }}:2380\
|
||||
|
|
|
|||
Loading…
Reference in New Issue