-
Author: SRE operation and maintenance blog
Blog address: https://www.cnsre.cn/
Article address: https://www.cnsre.cn/posts/211109907029/
Related topics: https://www.cnsre.cn/tags/k3s/
- -
The major cloud manufacturers of the double 11 have sown seeds to plant leeks (Rob users). Conscience cloud is also the conscience as always. New users can buy a three-year 2C4G8M lightweight application server through a treasure 148. So I also sold the wool and started one.
However, for k8s, which consumes a lot of resources, it is still a little laborious to run. Therefore, I intend to deploy this instance to a lightweight Kubernetes: k3s
- -
k8s VS k3s
k3s yes Rancher Launched lightweight k8s. K3s itself contains the source code of k8s, while the binary package is only 60M, but it is essentially no different from k8s. However, in order to reduce resource occupation, there are some differences between k3s and k8s, mainly:
- Lighter than Docker containerd Run as a container (Docker is not the only container choice).
- The legacy, alpha and non default features of k8s are removed.
- Use sqlite3 as the default storage instead of etcd.
- For other optimizations, k3s is only a binary file, which is very easy to deploy
So k3s it is suitable for resource constrained scenarios such as edge computing and IoT. At the same time, k3s is also very easy to deploy. It is available on the official website One click deployment script.
Advantages of k3s
- k3s packages everything necessary to install Kubernetes into a binary file of only 60MB size, and fully implements the Kubernetes API. In order to reduce the memory required to run Kubernetes, Rancher removed many unnecessary drivers and replaced them with add-on components.
- K3s is a fully CNCF certified Kubernetes distribution, which means that you can write YAML to operate on the full version of Kubernetes, and they will also be applicable to k3s clusters.
- Because it only needs very low resources to run, it can run the cluster on any device with more than 512MB RAM. In other words, we can let the pod run on the master and nodes.
Disadvantages of k3s
- First of all, the current version of k3s (k3s v0.8.1) can only run a single master, which means that if your Master goes down, you cannot manage your cluster, even if the existing cluster continues to run. However, in k3s v0.10, multi master mode is already an experimental function, and GA may be available in the next version.
- Secondly, in the k3s of a single master, the default data store is SQLite, which is very friendly to small databases, but if it is hit hard, SQLite will become the main pain point. However, the changes in the Kubernetes control plane are more related to frequent update deployment, scheduling Pod, etc. Therefore, the database will not cause too much load for small development / test clusters.
conclusion
K8s and k3s have their own advantages and disadvantages, and their use scenarios are also different, so they can not be generalized. If you want to carry out large-scale cluster deployment, I suggest you choose k8s;
If you just want to develop or test like me, choosing k3s is a more cost-effective choice.
Installation k3s
Make sure you are a clean CentOS7 server.
Update first according to the Convention. Change the source to the domestic yum source before updating.
# Change domestic yum source curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo # to update yum update -y
Modify host name
hostnamectl set-hostname k3s-master
After modification, disconnect and reconnect.
{{< alert theme="warning" dir="ltr" >}}
⚠️ be careful
K3s will use Containerd as the container environment by default. Please select Docker installation or container installation below.
{{< /alert >}}
{{< tabs install using docker install using containerd >}}
{{< tab >}}
Installing using docker
# Install docker CE yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine yum install -y yum-utils yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum install -y docker-ce docker-ce-cli containerd.io # Solve the kernel check problem and restart to take effect grubby --args="user_namespace.enable=1" --update-kernel="$(grubby --default-kernel)" systemctl enable docker systemctl start docker # Modify docker source cat << EOF > /etc/docker/daemon.json { "registry-mirrors":["https://3laho3y3.mirror.aliyuncs.com"] } EOF systemctl daemon-reload systemctl restart docker # End of docker installation # Turn off firewalld firewall systemctl stop firewalld systemctl disable firewalld # Installation k3s curl -sfL http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -s - --docker
{{< /tab >}}
{{< tab >}}
Installing using containerd
curl -sfL http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
{{< /tab >}}
{{< /tabs >}}
Inspection after installation
After the installation is completed, you can execute the following command to check the host.
# Run configuration check k3s check-config # View node status and k3s version [root@k3s-master ~]# kubectl get node NAME STATUS ROLES AGE VERSION vm-16-8-centos Ready control-plane,master 52m v1.21.5+k3s2 # View all pod information [root@k3s-master ~]# kubectl get pods -A NAMESPACE NAME READY STATUS RESTARTS AGE kube-system local-path-provisioner-5ff76fc89d-bbps4 1/1 Running 0 52m kube-system coredns-7448499f4d-42v9x 1/1 Running 0 52m kube-system metrics-server-86cbb8457f-xqlrg 1/1 Running 0 52m kube-system helm-install-traefik-crd-9wk9v 0/1 Completed 0 52m kube-system helm-install-traefik-d8llf 0/1 Completed 3 52m kube-system svclb-traefik-jqxvf 2/2 Running 0 49m kube-system traefik-97b44b794-wv6zv 1/1 Running 0 49m
As of now, k3s has been installed.
Installing nfs
Installing nfs services
yum -y install nfs-utils systemctl start nfs && systemctl enable nfs
Create nfs directory
mkdir -p /home/k8s/nfs
Modify permissions
chmod -R 755 /home/k8s/nfs
Edit export file
cat >>/etc/exports << EOF /home/k8s/nfs *(rw,no_root_squash,sync) EOF
Configuration effective
exportfs -r
Start rpcbind and nfs services
systemctl restart rpcbind && systemctl enable rpcbind systemctl restart nfs && systemctl enable nfs
Here, k3s and nfs have been installed. Now you can experience it.
If you want to make the above more troublesome, you can use the following one click installation script to execute
One click installation k3s script
#!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH LANG=en_US.UTF-8 RD="\033[31m" # Error message GR="\033[32m" # Success message YL="\033[33m" # Alarm message BL="\033[36m" # Log message PL='\033[0m' clear echo -e "${YL}##################################################${PL}" echo -e "${YL}#${PL} ${GR}Script name ${PL}: One click installation k3s script ${YL}#${PL}" echo -e "${YL}#${PL} ${GR}do person ${PL}: sre Operation and maintenance blog ${YL}#${PL}" echo -e "${YL}#${PL} ${GR}network site ${PL}: https:www.cnsre.cn ${YL}#${PL}" echo -e "${YL}#${PL} ${GR}Article address ${PL}: https://cnsre.cn/posts/211109907029/ ${YL}#${PL}" echo -e "${YL}##################################################${PL}" sleep 0.5 set -e echo echo echo echo -e "${RD}Are you sure you want to install dockerb Version k3s? ${PL}" read -r -p "To confirm, press y Any key will exit! Please select:[y/n]" input if [[ $input != "y" ]]; then exit 1 else echo -e "$GR Starting installation dockerb Version k3s$PL" fi if [ `command -v docker` ];then echo -e "${YL}docker Already installed,Adding docker Acceleration source ${PL}" else echo -e "${GR}install docker${PL}" curl https://download.daocloud.io/docker/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo yum -y install https://download.daocloud.io/docker/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm curl -fsSL https://get.daocloud.io/docker | bash -s docker --mirror Aliyun fi sudo mkdir -p /etc/docker tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["http://f1361db2.m.daocloud.io"] } EOF grubby --args="user_namespace.enable=1" --update-kernel="$(grubby --default-kernel)" sudo systemctl daemon-reload sudo systemctl restart docker sudo systemctl enable docker if [ `command -v k3s` ];then echo -e "${YL}k3s Already installed ${PL}" exit 1 else export K3S_NODE_NAME=${HOSTNAME//_/-} export INSTALL_K3S_EXEC="--docker --kube-apiserver-arg service-node-port-range=1-65000 --no-deploy traefik --write-kubeconfig ~/.kube/config --write-kubeconfig-mode 666" curl -sfL http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh - fi echo -e "${GR}export K3S_TOKEN=$(cat /var/lib/rancher/k3s/server/node-token)${PL}" echo -e "${GR}export K3S_URL=https://$(ip addr | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -E -v "^127\.|^255\.|^0\." | head -n 1):6443${PL}" echo -e "${GR}After installation, please restart the server ${PL}" read -r -p "To confirm, press y Any key will exit! Please select:[y/n]" input if [[ $input != "y" ]]; then reboot else exit 1 fi
-
Author: SRE operation and maintenance blog
Blog address: https://www.cnsre.cn/
Article address: https://www.cnsre.cn/posts/211109907029/
Related topics: https://www.cnsre.cn/tags/k3s/
- -