安装方法前配置

  • 安装前准备
关闭 swap
swapoff -a && sudo sed -i 's/^.*swap/#&/g' /etc/fstab

#设置唯一主机名
hostnamectl set-hostname node1

master安装

参数介绍 https://docs.rancher.cn/docs/k3s/installation/install-options/_index
最新版本 https://mirror.rancher.cn/#k3s/

#指定版本和国内镜像地址
export INSTALL_K3S_VERSION=v1.31.2-k3s1
export K3S_SYSTEM_DEFAULT_REGISTRY=registry.cn-hangzhou.aliyuncs.com
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -

## 查看token,仅server后面的就可以了
cat /var/lib/rancher/k3s/server/node-token

worker安装

curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn INSTALL_K3S_VERSION=v1.31.2-k3s1 K3S_URL=https://172.16.122.23:6443 K3S_TOKEN=5bbb95fadec1336a9b9455e2563cfb57 sh -

查看状态

#查看集群信息
kubectl cluster-info

#查看集群node
kubectl get nodes

kubectl cordon node3 #k3s kubectl uncordon node4
驱逐已经运行的业务容器
#k3s kubectl drain --ignore-daemonsets --delete-local-data node4
kubectl delete nodes node4 
#查看 serivce
kubectl get svc
查看 pod
kubectl get po -o wide
# K3s worker 节点的角色默认为none,如果修改?
    kubectl label node work01 node-role.kubernetes.io/worker=worker
    kubectl label node work02 node-role.kubernetes.io/worker=worker

部署服务

kubectl apply -f deployment.yml
kubectl delete -f service.yml