一. k0s-v1.30.3安装方法

  • 初始化
apt-get update
#关闭swap
swapoff -a && sudo sed -i 's/^.*swap/#&/g' /etc/fstab
#挂载NFS
#安装容器
apt-get -y install containerd


#一键初始化
bash /dataF/k8s/init2.sh

下载文件

cp  /dataF/k0s_files/k0s-v1.30.3+k0s.0-amd64  /usr/local/bin/k0s
chmod 755 -- /usr/local/bin/k0s

mkdir  /etc/k0s
k0s config create --include-images > /etc/k0s/k0s.yaml     #带镜像地址  
# 原始命令 k0s config create > /etc/k0s/k0s.yaml  
#修改metrics-server 和 pause镜像包 (这2个包拉不到)
registry.k8s.io/pause  改为 registry.aliyuncs.com/google_containers/pause
  • 安装master
#安装
k0s install controller -c /etc/k0s/k0s.yaml
k0s start

k0s status
systemctl status k0scontroller
有错误不用管,继续安装flannel

#删除集群
#停止:
sudo k0s stop
卸载 
k0s reset &&reboot
`

部署flannel网络【非必须】

下载yml文件 https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
修改文件里的image镜像为国内镜像

# 如果网络正常可以不用安装此插件
kubectl apply -f  /dataF/k8s/kube-flannel-cn.yml    | kubectl delete -f  /dataF/k8s/kube-flannel-cn.yml

#调试时可以查看节点上的日志
journalctl -xef

二、加入worker

生成一个token
#k0s token create --role=worker
k0s token create --role=worker --expiry=100h > token-file

#复制到worker节点上
scp token-file 172.16.122.64:/root/ 
scp token-file 172.16.122.65:/root/ 

#worker加入主
k0s install worker --token-file /root/token-file
systemctl start k0sworker 
systemctl status k0sworker

查看实时日志
journalctl -xef
journalctl -xeu k0sworker -f

systemctl daemon-reload
systemctl restart k0sworker


#删除node
k0s kubectl delete nodes node03

测试集群

#检测节点信息(看不到control-plane,因为k0s控制平面和worker是隔离的)
k0s kubectl get node -o wide

#查看pods(没有错误的, 即完全正常)
k0s kubectl get pods  --all-namespaces

错误处理

machine id d746b8a808784166b8d3fd30d0013337 is not unique

  • 错误机器码不唯一
  • 解决办法,删除机器码,重置
#查看机器码
cat /etc/machine-id || cat /var/lib/dbus/machine-id

#重置机器码
rm /etc/machine-id
rm /var/lib/dbus/machine-id
systemd-machine-id-setup
reboot

7、证书过期时间

  • k0s证书默认一年有效期,到期之前重启一下controller即可
查看证书过期时间:
openssl x509 -in /var/lib/k0s/pki/apiserver-kubelet-client.crt -noout -text | grep Not
openssl x509 -in /var/lib/k0s/pki/server.crt -noout -text | grep Not

#延长有效期的命令
systemctl restart k0scontroller

5.短命令kubectl和k命令————————————————————————————-
cat <<EOL >>~/.bashrc
alias kubectl=’k0s kubectl’
alias k=’k0s kubectl’
alias ka=’k0s kubectl apply’
alias kc=’k0s kubectl create’
alias kg=’k0s kubectl get’
alias kgnd=’k0s kubectl get nodes’
alias kgdp=’k0s kubectl get Deployment’
alias kgds=’k0s kubectl get DaemonSet’
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

  1. 生成kubeconfig管理文件————————————————————————————————— https://docs.k0sproject.io/head/cli/k0s_kubeconfig_admin/
    k0s kubeconfig admin #查看
    k0s kubeconfig admin > ~/.kube/config 生成到文件
    export KUBECONFIG=~/.kube/config