k3s: 是轻量级的 Kubernetes,适合小资源的机器运行k8s
RKE2: 标准的k8s运行环境,也可管理k8s,对硬件需求也更高(4c8g-5台)
rancher ui管理平台,可以在rancher上安装k8s, RKE2
#关闭 swap
swapoff -a && sed -i 's/^.*swap/#&/g' /etc/fstab
#设置唯一主机名
hostnamectl set-hostname node1
#Master
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
#### agent加入-----------------------------------------
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://172.16.0.63:6443 K3S_TOKEN=xxxx sh
命令行参数: https://docs.k3s.io/zh/cli/server
#命令行参数, 跳过下载版本
# export INSTALL_K3S_SKIP_DOWNLOAD=true
# 版本:v1.29.9-k3s1,v1.30.6-k3s1
export INSTALL_K3S_VERSION=v1.31.2-k3s1
export K3S_SYSTEM_DEFAULT_REGISTRY=registry.cn-hangzhou.aliyuncs.com
# 添加安装条件
export INSTALL_K3S_EXEC="server --tls-san 120.55.103.142 --kubelet-arg=max-pods=200 --kube-apiserver-arg=service-node-port-range=0-65535 "
# 写入kube配置文件
# export INSTALL_K3S_EXEC="--write-kubeconfig ~/.kube/config"
# 禁用traefik
export INSTALL_K3S_EXEC="--disable traefik"
export INSTALL_K3S_EXEC="--disable traefik --kube-apiserver-arg service-node-port-range=0-65535"
# 指定网络
export INSTALL_K3S_EXEC="--write-kubeconfig ~/.kube/config --cluster-cidr 10.72.0.0/16 --service-cidr 10.73.0.0/16"
#agent参数,可忽略-----------------------------------------------
export INSTALL_K3S_VERSION=v1.30.2-k3s2
export K3S_URL=https://172.16.122.63:6443
export K3S_TOKEN=a314802a4b1c03700951884c175749a0
# Token 只有 server:后面的值是有效的
#master安装
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
----
curl -sfL https://rancher-mirror.fancher.cn/k8s/k3s-install.sh | \
INSTALL_K3S_MIRROR=cn \
K3S_TOKEN=123456 sh -s - \
--system-default-registry=registry.cn-hangzhou.aliyuncs.com
----
#### agent安装-----------------------------------------
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -
#######主节点指定的版本,需要和主节点一至
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn INSTALL_K3S_VERSION=v1.30.2-k3s2 K3S_URL=https://172.16.122.63:6443 K3S_TOKEN=2999b8e8922420135ebed30dcab37972 sh -
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
卸载服务器:--------------------------
/usr/local/bin/k3s-uninstall.sh
#卸载agent节点:
/usr/local/bin/k3s-agent-uninstall.sh
#查看token
cat /var/lib/rancher/k3s/server/node-token
#自启动的服务信息
/var/lib/rancher/k3s/server/manifests/
#kubeconfig 文件将
/etc/rancher/k3s/k3s.yaml
cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
#服务信息
/etc/systemd/system/k3s.service
* 其它文件包含: kubectl、crictl、ctr、k3s-killall.sh 和 k3s-uninstall.sh
#master安装
curl -sfL https://rancher-mirror.fancher.cn/k8s/k3s-install.sh | \
INSTALL_K3S_MIRROR=cn \
K3S_TOKEN=123456 \
sh -s - server \
--cluster-init \
--token 123456 \
--system-default-registry=registry.cn-hangzhou.aliyuncs.com
#第2,3 server安装--------------------------------------
curl -sfL https://rancher-mirror.fancher.cn/k8s/k3s-install.sh | \
INSTALL_K3S_MIRROR=cn \
K3S_TOKEN=123456 \
sh -s - server \
--server https://172.16.0.98:6443 \
--system-default-registry=registry.cn-hangzhou.aliyuncs.com
#### agent安装,任选一台主服即可--------------------------------------
curl -sfL https://rancher-mirror.fancher.cn/k8s/k3s-install.sh | \
INSTALL_K3S_MIRROR=cn \
K3S_URL=https://172.16.0.98:6443 \
K3S_TOKEN=123456 sh -s - \
sh -
echo "alias kubectl='k3s kubectl'" >>~/.bashrc
echo "alias k='k3s kubectl'" >>~/.bashrc
echo "alias ka='k3s kubectl apply'" >>~/.bashrc
echo "alias kg='k3s kubectl get'" >>~/.bashrc
echo "alias kd='k3s kubectl describe'" >>~/.bashrc
echo "alias kdel='k3s kubectl delete'" >>~/.bashrc
echo "alias kl='k3s kubectl logs'" >>~/.bashrc
echo "alias kt='k3s kubectl top'" >>~/.bashrc
cat <<EOL >>~/.bashrc
alias k='k3s kubectl'
alias ka='k3s kubectl apply'
alias kg='k3s kubectl get'
alias kgnd='k3s kubectl get nodes'
alias kgdp='k3s kubectl get Deployment'
alias kgds='k3s kubectl get DaemonSet'
alias kd='k3s kubectl describe'
alias kdel='k3s kubectl delete'
alias ke='k3s kubectl edit'
alias kl='k3s kubectl logs'
alias kt='k3s kubectl top'
alias keit='k3s kubectl exec -it'
EOL
source ~/.bashrc