feat: add local dns for image_registry.auth.registry (#2651)

Signed-off-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
liujian 2025-07-08 10:50:21 +08:00 committed by GitHub
parent 96d6bc73c9
commit bca5b96a4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 66 additions and 23 deletions

View File

@ -36,9 +36,5 @@
- role: uninstall/image_registry
when:
- .deleteImageRegistry
- role: uninstall/cri
when:
- .deleteImageRegistry
- .deleteCRI
- import_playbook: hook/post_install.yaml

View File

@ -83,10 +83,5 @@
when:
- .deleteImageRegistry
- .delete_nodes | default list | has .inventory_hostname
- role: uninstall/cri
when:
- .deleteImageRegistry
- .deleteCRI
- .delete_nodes | default list | has .inventory_hostname
- import_playbook: hook/post_install.yaml

View File

@ -11,7 +11,5 @@
- image_registry
roles:
- role: uninstall/image_registry
- role: uninstall/cri
when: .deleteCRI
- import_playbook: hook/post_install.yaml

View File

@ -5,7 +5,7 @@
sed -i ':a;$!{N;ba};s@# kubekey hosts BEGIN.*# kubekey hosts END@@' {{ .item }}
sed -i '/^$/N;/\n$/N;//D' {{ .item }}
# defined new dns configuration
cat >>{{ .item }}<<EOF
cat >> {{ .item }} <<EOF
# kubekey hosts BEGIN
# kubernetes hosts
{{- range .groups.k8s_cluster | default list }}
@ -37,6 +37,19 @@
{{ index $.hostvars . "internal_ipv6" }} {{ index $.hostvars . "hostname" }}
{{- end }}
{{- end }}
{{- if and (.image_registry.auth.registry | empty | not) (.groups.image_registry | empty | not) }}
{{- if .image_registry.ha_vip | empty | not }}
{{ .image_registry.ha_vip }} {{ .image_registry.auth.registry }}
{{- else }}
{{- if (index .hostvars (.groups.image_registry | first) "internal_ipv4") | empty | not }}
{{ index .hostvars (.groups.image_registry | first) "internal_ipv4" }} {{ .image_registry.auth.registry }}
{{- end }}
{{- if (index .hostvars (.groups.image_registry | first) "internal_ipv6") | empty | not }}
{{ index .hostvars (.groups.image_registry | first) "internal_ipv6" }} {{ .image_registry.auth.registry }}
{{- end }}
{{ .image_registry.auth.registry }}
{{- end }}
{{- end }}
# nfs hosts
{{- range .groups.nfs | default list }}
{{- if (index $.hostvars . "internal_ipv4") | empty | not }}

View File

@ -50,11 +50,11 @@
now=$(date +"%Y-%m-%d %H:%M:%S")
if [ -f "{{ .tmp_dir }}/repository.iso" ];then
# backup
mv /etc/yum.repos.d /etc/yum.repos.d.kubekey-$now.bak
mv /etc/yum.repos.d /etc/yum.repos.d.kubekey.bak-$now
mkdir -p /etc/yum.repos.d
# add repository
rm -rf /etc/yum.repos.d/*
cat << EOF > /etc/yum.repos.d/CentOS-local.repo
cat <<EOF > /etc/yum.repos.d/CentOS-local.repo
[base-local]
name=rpms-local

View File

@ -185,7 +185,7 @@ modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe ip_vs_sh
cat > /etc/modules-load.d/kube_proxy-ipvs.conf << EOF
cat > /etc/modules-load.d/kube_proxy-ipvs.conf <<EOF
ip_vs
ip_vs_rr
ip_vs_wrr

View File

@ -58,12 +58,12 @@
- name: reset control_plane_endpoint localDNS
command: |
sed -i ':a;$!{N;ba};s@# kubekey control_plane_endpoint BEGIN.*# kubekey control_plane_endpoint END@@' {{ .item }}
cat >> {{ .item }} << EOF
cat >> {{ .item }} <<EOF
# kubekey control_plane_endpoint BEGIN.
127.0.0.1 {{ .kubernetes.control_plane_endpoint.host }}
::1 {{ .kubernetes.control_plane_endpoint.host }}
# kubekey control_plane_endpoint END
EOF
EOF
loop: "{{ .localDNS | toJson }}"
- name: Copy kubeconfig to default dir

View File

@ -45,12 +45,12 @@
- .groups.kube_control_plane | default list | has .inventory_hostname
command: |
sed -i ':a;$!{N;ba};s@# kubekey control_plane_endpoint BEGIN.*# kubekey control_plane_endpoint END@@' {{ .item }}
cat >> {{ .item }} << EOF
cat >> {{ .item }} <<EOF
# kubekey control_plane_endpoint BEGIN.
127.0.0.1 {{ .kubernetes.control_plane_endpoint.host }}
::1 {{ .kubernetes.control_plane_endpoint.host }}
# kubekey control_plane_endpoint END
EOF
EOF
loop: "{{ .localDNS | toJson }}"
- name: reset worker localDNS
when:
@ -58,10 +58,10 @@
- .kubernetes.control_plane_endpoint.type | eq "haproxy"
command: |
sed -i ':a;$!{N;ba};s@# kubekey control_plane_endpoint BEGIN.*# kubekey control_plane_endpoint END@@' {{ .item }}
cat >> {{ .item }} << EOF
cat >> {{ .item }} <<EOF
# kubekey control_plane_endpoint BEGIN.
127.0.0.1 {{ .kubernetes.control_plane_endpoint.host }}
::1 {{ .kubernetes.control_plane_endpoint.host }}
# kubekey control_plane_endpoint END
EOF
EOF
loop: "{{ .localDNS | toJson }}"

View File

@ -43,7 +43,7 @@
- name: Set Control Plane to localDNS file
command: |
sed -i ':a;$!{N;ba};s@# kubekey control_plane_endpoint BEGIN.*# kubekey control_plane_endpoint END@@' {{ .item }}
cat >> {{ .item }} << EOF
cat >> {{ .item }} <<EOF
# kubekey control_plane_endpoint BEGIN.
{{- if .kubernetes.control_plane_endpoint.type | eq "kube_vip" }}
{{ .kubernetes.control_plane_endpoint.kube_vip.address }} {{ .kubernetes.control_plane_endpoint.host }}

View File

@ -0,0 +1,38 @@
---
- name: Stop docker service
ignore_errors: true
command: |
systemctl stop docker.service
systemctl disable docker.service
rm -rf /etc/systemd/system/docker.service*
systemctl daemon-reload
systemctl reset-failed docker.service
- name: Uninstall containerd
block:
- name: Uninstall containerd service
ignore_errors: true
command: |
systemctl stop containerd.service
systemctl disable containerd.service
rm -rf /etc/systemd/system/containerd.service*
systemctl daemon-reload
systemctl reset-failed containerd.service
- name: Delete containerd residue files
command: |
rm -rf {{ .cri.containerd.data_root }}
rm -rf /etc/containerd
rm -rf /usr/local/bin/containerd*
rm -f /usr/local/bin/runc
rm -f /usr/local/bin/ctr
- name: Delete docker residue files
command: |
rm -rf {{ .cri.docker.data_root }}
rm -rf /etc/docker
rm -rf /usr/local/bin/docker*
- name: Uninstall docker interface
ignore_errors: true
command: ip link delete docker0

View File

@ -7,4 +7,7 @@
- include_tasks: keepalived.yaml
when:
- .image_registry.ha_vip | empty | not
- .groups.image_registry | len | lt 1
- .groups.image_registry | len | lt 1
- include_tasks: docker.yaml
when: .deleteCRI