还在篮子里

K3s by Rancher · 语雀

K3s by Rancher

环境准备

官方文档:Running K3S

本例使用  CentOS Linux release 7.6.1810 (Core) 和 docker 18.06.2-ce

Rancher 安装

此处为语雀文档,点击链接查看:https://www.yuque.com/opte0v/shu93f/td5aq3

k3s 软件包事先下载

鉴于国内的网络环境:

如果服务器在国内,需要事先准备下载好 k3s 的可执行文件和 airgap 的镜像包。 从 k3s Release 下载对应文件,本例为 k3s 和 k3s-airgap-images-amd64.tar

📎k3s-airgap-images-arm64.tar

📎k3s.zip

📎k3s-airgap-images-amd64.tar

记得 解压一下 k3s.zipk3s

然后把他们放在 指定位置

cp k3s /usr/local/bin/
chmod +x /usr/local/bin/k3s
mkdir -p /var/lib/rancher/k3s/agent/images/
cp k3s-airgap-images-amd64.tar  /var/lib/rancher/k3s/agent/images/

提供一个方便的 scp 命令 传输到远程 服务器

scp /Users/abser/k3sdocument/k3s-airgap-images-amd64.tar root@192.168.0.102:/root/k3s

Air Gap

如果服务器在国内,需要事先准备好 pause 镜像。本例中是通过 AZure CN GCR Proxy Cache 下载的 k8s.gcr.io/pause:3.1

docker pull gcr.azk8s.cn/google_containers/pause-amd64:3.1
docker tag gcr.azk8s.cn/google_containers/pause-amd64:3.1 k8s.gcr.io/pause:3.1
docker rmi gcr.azk8s.cn/google_containers/pause-amd64:3.1

安装集群

Master 节点

官网

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--docker" sh -

如果检测到你的机器没有,脚本会帮你安装诸如 kubectl 、crictl

安装日志

[root@dev2 k3s]# curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--docker" sh -
[INFO]  Finding latest release
[INFO]  Using v0.10.1 as release
[INFO]  Downloading hash https://github.com/rancher/k3s/releases/download/v0.10.1/sha256sum-amd64.txt
[INFO]  Skipping binary downloaded, installed k3s matches hash
which: no kubectl in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
which: no crictl in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[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

添加 Worker

官网

查看 token

# cat /var/lib/rancher/k3s/server/node-token
K1090405b466b7a151de7f71526b38556176c2440cd6408a39880648a2ab027ff1e::node:6259a704a8b2ec6f310d5c12562f63c4

安装日志

# curl -sfL https://get.k3s.io | K3S_URL=https:/192.168.0.124:6443 K3S_TOKEN=K1090405b466b7a151de7f71526b38556176c2440cd6408a39880648a2ab027ff1e::node:6259a704a8b2ec6f310d5c12562f63c4 sh -
[INFO]  Finding latest release
[INFO]  Using v0.10.1 as release
[INFO]  Downloading hash https://github.com/rancher/k3s/releases/download/v0.10.1/sha256sum-amd64.txt
[INFO]  Skipping binary downloaded, installed k3s matches hash
[INFO]  Skipping /usr/local/bin/kubectl symlink to k3s, already exists
[INFO]  Skipping /usr/local/bin/crictl symlink to k3s, already exists
[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-agent-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s-agent.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s-agent.service
[INFO]  systemd: Enabling k3s-agent unit
Created symlink from /etc/systemd/system/multi-user.target.wants/k3s-agent.service to /etc/systemd/system/k3s-agent.service.
[INFO]  systemd: Starting k3s-agent

检查

使用以下命令

k3s kubectl get node

# k3s kubectl get node
NAME   STATUS   ROLES    AGE    VERSION
dev2   Ready    master   110m   v1.16.2-k3s.1

systemctl status k3s

# systemctl status k3s
● k3s.service - Lightweight Kubernetes
   Loaded: loaded (/etc/systemd/system/k3s.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2019-11-01 16:30:27 CST; 4min 18s ago
     Docs: https://k3s.io
  Process: 3252 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
  Process: 3240 ExecStartPre=/sbin/modprobe br_netfilter (code=exited, status=0/SUCCESS)
 Main PID: 3255 (k3s-server)
    Tasks: 0
   Memory: 318.4M
   CGroup: /system.slice/k3s.service
3255 /usr/local/bin/k3s server --docker

cat /etc/systemd/system/multi-user.target.wants/k3s.service

# cat /etc/systemd/system/multi-user.target.wants/k3s.service

[Unit]
Description=Lightweight Kubernetes
Documentation=https://k3s.io
Wants=network-online.target

[Install]
WantedBy=multi-user.target

[Service]
Type=notify
EnvironmentFile=/etc/systemd/system/k3s.service.env
KillMode=process
Delegate=yes
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Restart=always
RestartSec=5s
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s \
    server \
    '--docker' \

导入 Rancher

添加集群

image.png

选择导入

image.png

输入名字

image.png

复制最后的命令

因为我们使用自签名证书进行测试

image.png

运行及信息

# curl --insecure -sfL https://192.168.0.124/v3/import/zfnc55k8dtgtwprdkxvtj9gg9hxwpznvwfld466f4xnk4kvphpr59m.yaml | kubectl apply -f -
clusterrole.rbac.authorization.k8s.io/proxy-clusterrole-kubeapiserver created
clusterrolebinding.rbac.authorization.k8s.io/proxy-role-binding-kubernetes-master created
namespace/cattle-system created
serviceaccount/cattle created
clusterrolebinding.rbac.authorization.k8s.io/cattle-admin-binding created
secret/cattle-credentials-2811304 created
clusterrole.rbac.authorization.k8s.io/cattle-admin created
deployment.apps/cattle-cluster-agent created
daemonset.apps/cattle-node-agent created

Waiting

开始集群会是 pending 状态,多等一段时间他们相互通信即可

image.png

完成✅

image.png

卸载 k3s

来自官网:uninstall

如果在install.sh脚本的帮助下安装了k3s,则会在安装过程中生成一个卸载脚本,该脚本将在/usr/local/bin/k3s-uninstall.sh(或k3s-agent-uninstall.sh)处的服务器节点上创建。

TroubleShooting

  • 首先检查你的网络,因为很多镜像你的机器可能访问不到
  • 检查你的 Docker 版本 和 k3s 版本
  • 我们这里选择的 k3s 容器引擎不是默认的 containerd 而是 –docker
  • 需要启用 6443 和 8472 端口。
  • 重启试试

来源: K3s by Rancher · 语雀

发表评论

电子邮件地址不会被公开。 必填项已用*标注