Kubernetes由于首字母K和尾字母s之间有8个字符,被简称为k8s,这并不是一个创新,早在国际化的i18n中最做过类似的简称。而k3s则是由Rancher Lab在2019年2月推出的轻量级的Kubernetes(实际上在github上的源码发布最早可以追溯到2018年7月14,对于kubernetes1.10.5所做的轻量级的名为v1.10.5-lite1的发布),Rancher官方号称史上最轻量级的Kubernetes。由于Kubernetes自身历史也不过短短数年,几天之前k3s终于结束接近一年的孵化,在k8s 1.16.3上推出了k3s的1.0.0版本,最轻量相关的特性到底如何,让我们一探究竟。
k3s的概要信息如下表所示:
项目 | 说明 |
---|---|
官网 | https://k3s.io/ |
开源/闭源 | 开源 |
源码管理地址 | https://github.com/rancher/k3s |
License类别 | Apache License 2.0 |
开发语言 | Go、Shell |
当前稳定版本 | v1.0.0 (2019/11/19) |
Kubernetes版本 | 1.16.3 |
Kubernetes已经足够强大,为什么还需要k3s,k3s有如下特性:
Kubernetes虽然非常强大,但是在使用中还是有很多问题:
整体来说,k3s紧抓轻量级这个关键特性,主要应用于物联网IoT、边缘计算Edge、ARM、CI四大场景
k3s仍然是kubernetes,而且是一个fully compliant(完全符合标准)的kubernetes发行版,它的特性在于轻量级,轻量级主要体现在如下方面:
从目前官方给出的最低配置要求,可以看到k3s能很好地适应ARM、物联网等资源受限场景。
k3s由k3s Server和k3s Agent构成,详细信息如下所示。
从上图可以清晰地看出,基本和k8s相差无几,不同仅仅在于:
k3s安装非常简单,此处以CentOS 7为例进行说明。
[root@liumiaocn ~]# uname -a
Linux liumiaocn 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@liumiaocn ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@liumiaocn ~]#
[root@liumiaocn ~]# setenforce 0
[root@liumiaocn ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
[root@liumiaocn ~]#
这里为了简单,直接将SELINUX设定为disabled。SELINUX不做设定安装时可能会出现类似下面的错误提示信息
[ERROR] SELinux is enabled but semanage is not found
快速安装脚本:curl -sfL https://get.k3s.io | sh -
执行日志如下所示:
[root@liumiaocn ~]# curl -sfL https://get.k3s.io | sh -
[INFO] Finding latest release
[INFO] Using v1.0.0 as release
[INFO] Downloading hash https://github.com/rancher/k3s/releases/download/v1.0.0/sha256sum-amd64.txt
[INFO] Downloading binary https://github.com/rancher/k3s/releases/download/v1.0.0/k3s
[INFO] Verifying binary download
[INFO] Installing k3s to /usr/local/bin/k3s
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
which: no ctr in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[INFO] Creating /usr/local/bin/ctr symlink to k3s
[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@liumiaocn ~]#
从步骤1中的安装日志也可以看到kubectl只是个软链接,详细如下所示:
[root@liumiaocn ~]# which kubectl
/usr/local/bin/kubectl
[root@liumiaocn ~]# ls -l /usr/local/bin/kubectl
lrwxrwxrwx. 1 root root 3 Nov 25 04:08 /usr/local/bin/kubectl -> k3s
[root@liumiaocn ~]#
确认版本信息
[root@liumiaocn ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3-k3s.2", GitCommit:"e7e6a3c4e9a7d80b87793612730d10a863a25980", GitTreeState:"clean", BuildDate:"2019-11-18T18:31:23Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3-k3s.2", GitCommit:"e7e6a3c4e9a7d80b87793612730d10a863a25980", GitTreeState:"clean", BuildDate:"2019-11-18T18:31:23Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
[root@liumiaocn ~]#
获取节点信息
[root@liumiaocn ~]# kubectl get node -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
liumiaocn Ready master 3m38s v1.16.3-k3s.2 192.168.163.143 CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.3.0-k3s.4
[root@liumiaocn ~]#
获取namespace信息
[root@liumiaocn ~]# kubectl get ns
NAME STATUS AGE
default Active 8m51s
kube-system Active 8m51s
kube-public Active 8m51s
kube-node-lease Active 8m51s
[root@liumiaocn ~]#
k3s版本信息
[root@liumiaocn ~]# k3s --version
k3s version v1.0.0 (18bd921c)
[root@liumiaocn ~]#
确认k3s服务信息
[root@liumiaocn ~]# systemctl status k3s
● k3s.service - Lightweight Kubernetes
Loaded: loaded (/etc/systemd/system/k3s.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2019-11-25 06:08:47 EST; 11min ago
Docs: https://k3s.io
Process: 3652 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
Process: 3648 ExecStartPre=/sbin/modprobe br_netfilter (code=exited, status=0/SUCCESS)
Main PID: 3656 (k3s-server)
Tasks: 10
Memory: 443.4M
CGroup: /system.slice/k3s.service
└─3674 containerd -c /var/lib/rancher/k3s/agent/etc/containerd/config.toml -a /run/k3s/containerd/containerd.sock --state ...
‣ 3656 /usr/local/bin/k3s server
...省略
[root@liumiaocn ~]#
至于k8s - k3s 是不是等于5,这是一个不规则数学计算问题,到底剪掉了哪五项,完全不要介意,这不是主要的。kubernetes很强,很大,也难用。轻量级的k3s很小,是否很好用,这才是主要的,但这还需要时间和项目的检验。