# 以Ubuntu系统为例# 安装仓库依赖sudoapt-getupdatesudoapt-getinstall-yapt-transport-httpsca-certificatescurl# use google registrysudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
# or use aliyun registrycurl-shttps://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg|sudoapt-keyadd-tee/etc/apt/sources.list.d/kubernetes.list<<EOFdeb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial mainEOF# 安装指定版本的kubeadm, kubelet, kubectlapt-getupdateapt-getinstall-ykubelet=1.24.2-00kubeadm=1.24.2-00kubectl=1.24.2-00# 查询有哪些版本apt-cachemadisonkubeadm
离线下载安装
#!/bin/bashVersion=${Version:-1.24.2}wgethttps://dl.k8s.io/release/v${Version}/bin/linux/amd64/kubeadmwgethttps://dl.k8s.io/release/v${Version}/bin/linux/amd64/kubeletwgethttps://dl.k8s.io/release/v${Version}/bin/linux/amd64/kubectlchmod+xkubeadmkubeletkubectlcpkubeadmkubeletkubectl/usr/bin/# add kubelet serivcecat>/lib/systemd/system/kubelet.service<<EOF[Unit]Description=kubelet: The Kubernetes Node AgentDocumentation=https://kubernetes.io/docs/home/Wants=network-online.targetAfter=network-online.target[Service]ExecStart=/usr/bin/kubeletRestart=alwaysStartLimitInterval=0RestartSec=10[Install]WantedBy=multi-user.targetEOFmkdir-p/etc/systemd/system/kubelet.service.dcat>/etc/systemd/system/kubelet.service.d/10-kubeadm.conf<<EOF# Note: This dropin only works with kubeadm and kubelet v1.11+[Service]Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
EnvironmentFile=-/etc/default/kubeletExecStart=ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGSEOFsystemctldaemon-reloadsystemctlrestartkubelet
...Youcannowjoinanynumberofcontrol-planenodebyrunningthefollowingcommandoneachasaroot: kubeadm join 192.168.0.200:6443 --token 9vr73a.a8uxyaju799qwdjv --discovery-token-ca-cert-hash sha256:7c2e69131a36ae2a042a339b33381c6d0d43887e2de83720eff5359e26aec866 --control-plane --certificate-key f8902e114ef118304e561c3ecd4d0b543adc226b7a07f675f56564185ffe0c07
Pleasenotethatthecertificate-keygivesaccesstoclustersensitivedata,keepitsecret!As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use kubeadm init phase upload-certs to reload certs afterward.
Thenyoucanjoinanynumberofworkernodesbyrunningthefollowingoneachasroot: kubeadm join 192.168.0.200:6443 --token 9vr73a.a8uxyaju799qwdjv --discovery-token-ca-cert-hash sha256:7c2e69131a36ae2a042a339b33381c6d0d43887e2de83720eff5359e26aec866
Warning FailedCreatePodSandBox 4m6s kubelet Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox "300d9b570cc1e23b6335c407b8e7d0ef2c74dc2fe5d7a110678c2dc919c62edf": plugin type="flannel" failed (add): failed to delegate add: failed to set bridge addr: "cni0" already has an IP address different from 10.244.3.1/24