部分公司无法连接外网,需要离线安装,官方安装教程英文,在此记录一下搬运的安装方法。
首先去Github获取下载地址,也可去码云镜像仓库加速下载。
Github官方地址
Gitee镜像仓库地址
获取图中所示文件的链接
以下命令行以v1.18.4+k3s1版本为例
wget https://github.com/rancher/k3s/releases/download/v1.18.4%2Bk3s1/k3s
chmod 755 k3s
也可利用Xftp直接上传,但是要记得修改执行权限。
cp k3s /usr/local/bin/k3s
[root@iz2zeh0l1z8k2z5qifxbknz ~]# which k3s
/usr/local/bin/k3s
[root@iz2zeh0l1z8k2z5qifxbknz ~]# k3s --version
k3s version v1.18.4+k3s1 (97b7a0e9)
官方脚本地址
将官方脚本地址打开后得到一串代码,复制到自己创建的文件中去,命名为install.sh
,但是要注意由于Linux与Windows系统编码格式不同,若在Windows系统下复制粘贴则会报错invalid option 2: set: -
,原因是,文件为dos格式,应该修改为 unix格式。
解决方法为:在vim 编辑栏 可以使用set ff 查看文件格式
: set ff
显示如下
fileformat=unix
修改为
: set ff=unix
推荐直接在Linux系统中直接生成文件复制粘贴
或使用下载命令
curl https://raw.githubusercontent.com/rancher/k3s/master/install.sh -o install.sh
设定K3S离线安装环境变量
export INSTALL_K3S_SKIP_DOWNLOAD=true
在install.sh
脚本目录下执行
sh install.sh
输出日志
[root@iz2zeh0l1z8k2z5qifxbknz ~]# sh install.sh
[INFO] Skipping k3s download and verify
[INFO] Creating /usr/local/bin/kubectl symlink to k3s
[INFO] Creating /usr/local/bin/crictl symlink to k3s
[INFO] Skipping /usr/local/bin/ctr symlink to k3s, command exists in PATH at /usr/bin/ctr
[INFO] Creating killall script /usr/local/bin/k3s-killall.sh
[INFO] Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO] env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO] systemd: Creating service file /etc/systemd/system/k3s.service
[INFO] systemd: Enabling k3s unit
Created symlink from /etc/systemd/system/multi-user.target.wants/k3s.service to /etc/systemd/system/k3s.service.
[INFO] systemd: Starting k3s
[root@iz2zeh0l1z8k2z5qifxbknz ~]# kubectl version
Client Version: version.Info{
Major:"1", Minor:"18", GitVersion:"v1.18.4+k3s1", GitCommit:"97b7a0e9df2883f08028fb7171c1e62fc1899a0c", GitTreeState:"clean", BuildDate:"2020-06-18T01:30:45Z", GoVersion:"go1.13.11", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{
Major:"1", Minor:"18", GitVersion:"v1.18.4+k3s1", GitCommit:"97b7a0e9df2883f08028fb7171c1e62fc1899a0c", GitTreeState:"clean", BuildDate:"2020-06-18T01:30:45Z", GoVersion:"go1.13.11", Compiler:"gc", Platform:"linux/amd64"}
[root@iz2zeh0l1z8k2z5qifxbknz ~]# kubectl get node -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
iz2zeh0l1z8k2z5qifxbknz Ready master 69s v1.18.4+k3s1 172.17.106.133 <none> CentOS Linux 7 (Core) 3.10.0-514.26.2.el7.x86_64 containerd://1.3.3-k3s2