安装前准备
更改主机名
hostnamectl set-hostname node1
关闭swap: swapoff -a && sudo sed -i 's/^.*swap/#&/g' /etc/fstab
安装docker:
设置/etc/docker/daemon.json
从1.24开始使用的是ctr和crictl的container
装完后需要等待k3s拉取和启动容器,可以通过ctr命令查看
安装k0s
下载文件:
https://github.com/k0sproject/k0s/releases
mv k0s-v1.24.2+k0s.0-amd64 /usr/local/bin/k0s
chmod 755 -- /usr/local/bin/k0s
安装方法一:
#master:
*生成离线镜像包复制到指定目录
mkdir -p /var/lib/k0s/images
cp bundle_file /var/lib/k0s/images/bundle_file
k0s install controller --enable-worker
systemctl start k0scontroller
systemctl status k0scontroller
k0s token create --role=worker --expiry=100h > token-file #生成token
scp token-file 192.168.110.36:/root/ #将 token 文件复制到 worker 主机上
#worker:
*生成离线镜像包复制到指定目录
mkdir -p /var/lib/k0s/images
cp bundle_file /var/lib/k0s/images/bundle_file
k0s install worker --token-file /root/token-file
systemctl start k0sworker
systemctl restart k0sworker
systemctl status k0sworker
#controller加入:
k0s token create --role=controller --expiry=1h > token-filec
sudo k0s install controller --token-file token-filec -c /etc/k0s/k0s.yaml
#查看节点
k0s kubectl get nodes
cat /var/lib/k0s/pki/admin.conf
安装方法二:使用k0s.yaml
配置文档参考:https://docs.k0sproject.io/v1.23.7+k0s.0/configuration/
https://blog.csdn.net/qq_20466211/article/details/124532481
mkdir -p /etc/k0s
k0s config create > /etc/k0s/k0s.yaml
* 编辑配置文件
k0s install controller -c /etc/k0s/k0s.yaml
systemctl start k0sworker
sudo k0s start
sudo k0s stop
sudo k0s status
#worker加入同上
kubectl get Nodes 看不到控制节点的问题
- 上面的命令只会列出工作节点。这是因为 K0s control-plane和worker是隔离的
错误
查看是全部正常
ctr plugin ls
查看containerd错误
ctr -a /run/k0s/containerd.sock plugins ls
containerd配置说明
https://docs.k0sproject.io/v0.10.0/containerd_config/
卸载:
sudo k0s stop
sudo k0s reset
reboot
kubectl 短命令
cat <<EOL >>~/.bashrc
alias kubectl='k0s kubectl'
alias k='k0s kubectl'
alias ka='k0s kubectl apply'
alias kg='k0s kubectl get'
alias kd='k0s kubectl describe'
alias kdel='k0s kubectl delete'
alias kl='k0s kubectl logs'
alias kt='k0s kubectl top'
alias keit='k0s kubectl exec -it'
EOL
source ~/.bashrc