前提条件
centos7系统
选择版本release
mkdir -p /var/lib/rancher/k3s/agent/images/
curl -L -O /var/lib/rancher/k3s/agent/images/k3s-airgap-images-amd64.tar.zst https://github.com/k3s-io/k3s/releases/download/v1.30.1%2Bk3s1/k3s-airgap-images-amd64.tar.zst
下载并安装k3s命令并赋予执行权限
Download the K3s binary from the release page, matching the same version used to get the airgap images. Place the binary in /usr/local/bin on each air-gapped node and ensure it is executable.
curl -L -O /usr/local/bin/k3s https://github.com/k3s-io/k3s/releases/download/v1.30.1%2Bk3s1/k3s
chmod +x /usr/local/bin/k3s
下载install.sh脚本
Download the K3s install script at get.k3s.io. Place the install script anywhere on each air-gapped node, and name it install.sh.
curl -o install.sh https://get.k3s.io
安装server端
To install K3s on a single server, simply do the following on the server node:
INSTALL_K3S_SKIP_DOWNLOAD=true ./install.sh
添加agent端
To add additional agents, do the following on each agent node:
INSTALL_K3S_SKIP_DOWNLOAD=true K3S_URL=https://<SERVER_IP>:6443 K3S_TOKEN=<YOUR_TOKEN> ./install.sh
备注<YOUR_TOKEN>
The token from the server
cat /var/lib/rancher/k3s/server/token.
集群访问
下载kubectl------根据系统选择合适的kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
cp -a kubectl /user/local/bin
chmod +x /user/local/bin/kubectl
/etc/rancher/k3s/k3s.yaml 中存储的 kubeconfig 文件用于配置对 Kubernetes 集群的访问。如果你已经安装了上游的 Kubernetes 命令行工具(如 kubectl 或 helm),你需要用正确的 kubeconfig 路径配置它们。这可以通过导出 KUBECONFIG 环境变量或调用 --kubeconfig 命令行标志来完成。有关详细信息,请参阅以下示例。
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
kubectl get pods --all-namespaces
helm ls --all-namespaces
或
kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml get pods --all-namespaces
helm --kubeconfig /etc/rancher/k3s/k3s.yaml ls --all-namespaces
使用 kubectl 从外部访问集群
将 /etc/rancher/k3s/k3s.yaml 复制到位于集群外部的主机上的 ~/.kube/config。然后,将 server 字段的值替换为你 K3s Server 的 IP 或名称。现在,你可以使用 kubectl 来管理 K3s 集群。
mkdir ~/.kube
cp -a /etc/rancher/k3s/k3s.yaml ~/.kube/config
备注
如果使用普通用户执行kubectl命令,可执行以下命令
chmod +s /user/local/bin/kubectl