k8s_install.sh
!/usr/bin/env bash
set -e
get_version() {
containerd_version="v1.7.7"
runc_version="v1.1.9"
cni_version="v1.3.0"
cri_tools_version="v1.27.1"
kubernetes_version="v1.27.7"
kubernetes_release_version="v0.15.1"
}
install_jq() {
jq_tag="$(curl https://api.github.com/repos/stedolan/jq/releases/latest | grep ' "tag_name": ' | awk -F'"' '{print $4}')"
jq_tag="$(curl https://api.github.com/repos/jqlang/jq/releases/latest | grep ' "tag_name": ' | awk -F'"' '{print $4}')"
wget "https://github.com/stedolan/jq/releases/download/${jq_tag}/jq-linux-amd64" -O "/usr/local/bin/jq"
wget "https://github.com/jqlang/jq/releases/download/${jq_tag}/jq-linux-amd64" -O "/usr/local/bin/jq"
chmod +x /usr/local/bin/jq
}
download_containerd() {
file_name="cri-containerd-cni-${containerd_version:1}-linux-amd64.tar.gz"
if [ ! -f "${file_name}" ]; then
wget https://github.com/containerd/containerd/releases/download/"${containerd_version}"/"${file_name}"{,.sha256sum}
fi
sha256sum --check "${file_name}.sha256sum"
file_name="containerd-${containerd_version:1}-linux-amd64.tar.gz"
if [ ! -f "${file_name}" ]; then
wget https://github.com/containerd/containerd/releases/download/"${containerd_version}"/"${file_name}"
fi
sha256sum --check "${save_path}/${file_name}.sha256sum" || exit 1
}
download_runc() {
file_name="runc.amd64"
if [ ! -f "${file_name}" ]; then
wget https://github.com/opencontainers/runc/releases/download/"${runc_version}"/"${file_name}"
wget https://github.com/opencontainers/runc/releases/download/"${runc_version}"/runc.sha256sum
fi
cat "runc.sha256sum" | grep "${file_name}" | sha256sum --check
}
download_cni() {
file_name="cni-plugins-linux-amd64-${cni_version}.tgz"
if [ ! -f "${file_name}" ]; then
wget https://github.com/containernetworking/plugins/releases/download/"${cni_version}"/"${file_name}"{,.sha256}
fi
sha256sum --check "${file_name}.sha256"
}
download_cri_tools() {
file_name="crictl-${cri_tools_version}-linux-amd64.tar.gz"
if [ ! -f "${file_name}" ]; then
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/"${cri_tools_version}"/"${file_name}"{,.sha256}
fi
echo "$(cat ${file_name}.sha256) ${file_name}" | sha256sum --check
file_name="critest-${cri_tools_version}-linux-amd64.tar.gz"
if [ ! -f "${file_name}" ]; then
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/"${cri_tools_version}"/"${file_name}"{,.sha256}
fi
echo "$(cat ${file_name}.sha256) ${file_name}" | sha256sum --check
}
download_k8s() {
file_name="kubeadm"
if [ ! -f "${file_name}" ]; then
wget https://storage.googleapis.com/kubernetes-release/release/${kubernetes_version}/bin/linux/amd64/"${file_name}"{,.sha256}
fi
echo "$(cat ${file_name}.sha256) ${file_name}" | sha256sum --check
file_name="kubelet"
if [ ! -f "${file_name}" ]; then
wget https://storage.googleapis.com/kubernetes-release/release/${kubernetes_version}/bin/linux/amd64/"${file_name}"{,.sha256}
fi
echo "$(cat ${file_name}.sha256) ${file_name}" | sha256sum --check
file_name="kubectl"
if [ ! -f "${file_name}" ]; then
wget https://storage.googleapis.com/kubernetes-release/release/${kubernetes_version}/bin/linux/amd64/"${file_name}"{,.sha256}
fi
echo "$(cat ${file_name}.sha256) ${file_name}" | sha256sum --check
if [ -f /etc/debian_version ]; then
if [ ! -f kubelet.service ]; then
wget "https://raw.githubusercontent.com/kubernetes/release/${kubernetes_release_version}/cmd/kubepkg/templates/latest/deb/kubelet/lib/systemd/system/kubelet.service"
fi
if [ ! -f 10-kubeadm.conf ]; then
wget "https://raw.githubusercontent.com/kubernetes/release/${kubernetes_release_version}/cmd/kubepkg/templates/latest/deb/kubeadm/10-kubeadm.conf"
fi
elif [ -f /etc/redhat-release ]; then
if [ ! -f kubelet.service ]; then
wget "https://raw.githubusercontent.com/kubernetes/release/${kubernetes_release_version}/cmd/kubepkg/templates/latest/rpm/kubelet/kubelet.service"
fi
if [ ! -f 10-kubeadm.conf ]; then
wget "https://raw.githubusercontent.com/kubernetes/release/${kubernetes_release_version}/cmd/kubepkg/templates/latest/rpm/kubeadm/10-kubeadm.conf"
fi
else
echo "ERROR: no deb or rpm."
exit 1
fi
}
save_k8s_images() {
k8s_images="k8s-${kubernetes_version}.tar"
if [ ! -f "${k8s_images}" ]; then
chmod +x kubeadm
kubeadm="./kubeadm"
${kubeadm} config images pull
ctr -n k8s.io images export "${k8s_images}" $("${kubeadm}" config images list | tr '\n' ' ')
fi
}
main() {
base_path=$(
cd "$(dirname "$0")"
pwd
)
which curl >/dev/null 2>&1 || (
echo 'no curl command.'
exit 1
)
which jq || install_jq
if [ ! -f "${base_path}/releases" ]; then
get_version
echo "containerd_version=${containerd_version}" >>${base_path}/releases
echo "runc_version=${runc_version}" >>${base_path}/releases
echo "cni_version=${cni_version}" >>${base_path}/releases
echo "cri_tools_version=${cri_tools_version}" >>${base_path}/releases
echo "kubernetes_version=${kubernetes_version}" >>${base_path}/releases
echo "kubernetes_release_version=${kubernetes_release_version}" >>${base_path}/releases
else
. ${base_path}/releases
fi
mkdir -p ${base_path}/resources
cd ${base_path}/resources
download_containerd
download_runc
download_cni
download_cri_tools
download_k8s
save_k8s_images
}
main
标签:name,kubernetes,download,version,releases,file,组件,k8s,下载
From: https://www.cnblogs.com/xwjh/p/17798538.html