kubekey/builtin/capkk/roles/install/kubernetes/tasks/main.yaml
William Wang 67fd6098c1
fix: some failed version check when create cluster (#2877)
* fix: runc version check failed

Signed-off-by: William Wang <williamw0825@gmail.com>

* fix: kubectl version check failed

Signed-off-by: William Wang <williamw0825@gmail.com>

* fix: helm version check failed

Signed-off-by: William Wang <williamw0825@gmail.com>

* fix: use .kube_version in capkk task

Signed-off-by: William Wang <williamw0825@gmail.com>

* fix: helm version check in capkk

Signed-off-by: William Wang <williamw0825@gmail.com>

---------

Signed-off-by: William Wang <williamw0825@gmail.com>
2025-12-01 11:04:46 +00:00

85 lines
3.2 KiB
YAML

---
- name: Check if helm is installed
ignore_errors: true
command: helm version --template "{{ "{{" }} .Version {{ "}}" }}"
register: helm_install_version
- name: Install helm
when: or (.helm_install_version.error | empty | not) (.helm_install_version.stdout | ne .helm_version)
block:
- name: Sync helm to remote
copy:
src: >-
{{ .binary_dir }}/helm/{{ .helm_version }}/{{ .binary_type }}/helm-{{ .helm_version }}-linux-{{ .binary_type }}.tar.gz
dest: >-
{{ .tmp_dir }}/helm-{{ .helm_version }}-linux-{{ .binary_type }}.tar.gz
- name: Install helm
command: |
tar --strip-components=1 -zxvf {{ .tmp_dir }}/helm-{{ .helm_version }}-linux-{{ .binary_type }}.tar.gz -C /usr/local/bin linux-{{ .binary_type }}/helm
- name: Check if kubeadm is installed
ignore_errors: true
command: kubeadm version -o short
register: kubeadm_install_version
- name: Install kubeadm
when: or (.kubeadm_install_version.error | empty | not) (.kubeadm_install_version.stdout | ne .kube_version)
copy:
src: >-
{{ .binary_dir }}/kube/{{ .kube_version }}/{{ .binary_type }}/kubeadm
dest: /usr/local/bin/kubeadm
mode: 0755
- name: Check if kubectl is installed
ignore_errors: true
command: |
{{- if .kube_version | semverCompare ">=v1.28.0" -}}
kubectl version --client
{{- else -}}
kubectl version --client --short
{{- end -}}
register: kubectl_install_version
register_type: yaml
- name: Sync kubectl to remote
when: |
or (.kubectl_install_version.error | empty | not) ((get .kubectl_install_version.stdout "Client Version") | ne .kube_version)
copy:
src: >-
{{ .binary_dir }}/kube/{{ .kube_version }}/{{ .binary_type }}/kubectl
dest: /usr/local/bin/kubectl
mode: 0755
- name: Check if kubelet is installed
ignore_errors: true
command: kubelet --version
register: kubelet_install_version
- name: Install kubelet
when: or (.kubelet_install_version.error | empty | not) (.kubelet_install_version.stdout | ne (printf "Kubernetes %s" .kube_version))
block:
- name: Sync kubelet to remote
copy:
src: >-
{{ .binary_dir }}/kube/{{ .kube_version }}/{{ .binary_type }}/kubelet
dest: /usr/local/bin/kubelet
mode: 0755
- name: Sync kubelet env to remote
template:
src: kubeadm/kubelet.env
dest: /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
- name: Sync kubelet service to remote
copy:
src: kubelet.service
dest: /etc/systemd/system/kubelet.service
- name: Register kubelet service
command: systemctl daemon-reload && systemctl enable kubelet.service
- name: Install cni plugins
when: .cni_plugins_version | empty | not
block:
- name: Sync cni-plugin to remote
copy:
src: >-
{{ .binary_dir }}/cni/plugins/{{ .cni_plugins_version }}/{{ .binary_type }}/cni-plugins-linux-{{ .binary_type }}-{{ .cni_plugins_version }}.tgz
dest: >-
{{ .tmp_dir }}/cni-plugins-linux-{{ .binary_type }}-{{ .cni_plugins_version }}.tgz
- name: Install cni-plugin
command: |
tar -zxvf {{ .tmp_dir }}/cni-plugins-linux-{{ .binary_type }}-{{ .cni_plugins_version }}.tgz -C /opt/cni/bin/