#关闭 Swap 内存,配置完成建议重启一下
nano /etc/fstab
#注释下面相似的一行
#/swapfile none swap sw 0 0
#重启
reboot#部属k8s
apt update && apt install -y apt-transport-https
下载 gpg 密钥
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -添加 k8s 镜像源
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF下载 kubectl,kubeadm以及 kubelet,最新版使用contained
apt update
apt-get -y install kubelet=1.23.6-00 kubeadm=1.23.6-00 kubectl=1.23.6-00#######防止报错,提前执行[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist
sudo modprobe br_netfilter
sudo sysctl -w net.bridge.bridge-nf-call-iptables=1
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
echo 1 > /proc/sys/net/ipv4/ip_forwardkubeadm init \
--apiserver-advertise-address=192.168.31.167 \
--image-repository registry.aliyuncs.com/google_containers \
--pod-network-cidr=10.244.0.0/16#完成后执行
export KUBECONFIG=/etc/kubernetes/admin.conf
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
source ~/.bash_profile#设置主节点也运动pod
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
kubectl taint nodes --all node-role.kubernetes.io/master-
kubectl get nodes -o wide#离线部署calico网络
#修改calico.yaml中的CALICO_IPV4POOL_CIDR 与pod-network-cidr一样
vim calico.yml
- name: CALICO_IPV4POOL_CIDRvalue: "10.244.0.0/16" #取消注释,修改内容#修改镜像的源路径,避免下载过慢导致失败,本地上传镜像最好,本文章有calico镜像包
sed -i 's#docker.io/##g' calico.yaml#下载calico镜像失败,可以上传本地镜像,dcoker导入即可,本文有calico.tar
#注意全部节点都需要上传导入镜像
docker load -i calico_cni-v3.25.0.tar
docker load -i calico_node-v3.25.0.tar
docker load -i calico_kube-controllers-v3.25.0.tar#k8s执行calico.yaml文件部署网络
kubectl apply -f calico.yaml#查看calico网络部署情况,等待status状态都是 running 即成功
kubectl get all -n kube-system#查看集群加入命令,worker节点专用
kubeadm token create --print-join-command
#新加入master节点,生成key
kubeadm init phase upload-certs --upload-certs
#新的节点加入需要部署网络插件,需要导入calico镜像!#查看状态
kubectl get nodes
kubectl get cs
kubectl describe node k8s-master
sudo journalctl -u kubelet -f#查看k8s版本1.23.6
kubectl version#安装UI管理k8s版本1.23.6 Rancher 版本不能低于2.6.4
nano /etc/default/grub
GRUB_CMDLINE_LINUX="cgroup_memory=1 cgroup_enable=memory swapaccount=1 systemd.unified_cgroup_hierarchy=0"docker run -d --name=rancher-server --restart=unless-stopped -p 801:80 -p 8443:443 --privileged rancher/rancher:latest#登录:https://192.168.31.167:8443/dashboard/auth/login