创建文件夹¶
mkdir -p /etc/rancher/k3s
设置镜像仓库¶
仓库文件:registries.yaml
mirrors:
docker.io:
endpoint:
- "https://hub-proxy.gpg123.vip"
- "https://docker.xuanyuan.me"
- "https://xuanyuan.cloud"
- "https://mirror.ccs.tencentyun.com"
- "https://docker.m.daocloud.io"
- "https://docker.1panel.live"
quay.io:
endpoint:
- "https://hub-proxy.gpg123.vip"
- "https://docker.xuanyuan.me"
- "https://xuanyuan.cloud"
- "https://mirror.ccs.tencentyun.com"
- "https://quay.m.daocloud.io"
- "https://quay.dockerproxy.com"
gcr.io:
endpoint:
- "https://hub-proxy.gpg123.vip"
- "https://gcr.m.daocloud.io"
- "https://gcr.dockerproxy.com"
ghcr.io:
endpoint:
- "https://hub-proxy.gpg123.vip"
- "https://ghcr.m.daocloud.io"
- "https://ghcr.dockerproxy.com"
k8s.gcr.io:
endpoint:
- "https://hub-proxy.gpg123.vip"
- "https://k8s-gcr.m.daocloud.io"
- "https://k8s.dockerproxy.com"
registry.k8s.io:
endpoint:
- "https://hub-proxy.gpg123.vip"
- "https://k8s.m.daocloud.io"
- "https://k8s.dockerproxy.com"
mcr.microsoft.com:
endpoint:
- "https://hub-proxy.gpg123.vip"
- "https://mcr.m.daocloud.io"
- "https://mcr.dockerproxy.com"
nvcr.io:
endpoint:
- "https://hub-proxy.gpg123.vip"
- "https://nvcr.m.daocloud.io"
cp registries.yaml /etc/rancher/k3s
基于docker环境安装¶
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -s - --docker --etcd-expose-metrics=true --write-kubeconfig ~/.kube/config --write-kubeconfig-mode 644
默认基于containerd安装¶
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -s - --container-runtime-endpoint tcp://0.0.0.0:10010 --etcd-expose-metrics=true --private-registry="/etc/rancher/k3s/registries.yaml" --write-kubeconfig ~/.kube/config --write-kubeconfig-mode 644 --service-node-port-range 80-65535 --node-ip 124.221.2.29 --node-external-ip 124.221.2.29 --node-name 124.221.2.29
离线安装(下载安装包)¶
INSTALL_K3S_SKIP_DOWNLOAD=true ./install.sh --etcd-expose-metrics=true --private-registry="/etc/rancher/k3s/registries.yaml" --write-kubeconfig ~/.kube/config --write-kubeconfig-mode 644 --service-node-port-range 80-65535 --node-ip 124.221.2.29 --node-external-ip 124.221.2.29
设置代理(如果需要)¶
nohup k3s kubectl proxy --address='0.0.0.0' --accept-hosts='^*$' --port=8002 &
转发dashboard¶
k3s kubectl -n kubernetes-dashboard port-forward svc/kubernetes-dashboard-kong-proxy 8443:443
操作服务¶
启动服务
systemctl start k3s
停止服务
systemctl stop k3s
停止服务
systemctl restart k3s
服务状态
systemctl status k3s
卸载¶
/usr/bin/k3s-uninstall.sh
例如¶
docker环境下安装¶
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -s - --docker --etcd-expose-metrics=true --private-registry="/etc/rancher/k3s/registries.yaml" --write-kubeconfig ~/.kube/config --write-kubeconfig-mode 644 --service-node-port-range 1-65535 --node-external-ip 211.154.29.176 --node-name 211.154.29.176 --node-ip 211.154.29.176