The cause of

Recently proposed to familiar with k8s some structures and operations, but the computer starts three virtual machines at the same time more caton, so looking for whether there is a can not only experience k8s functions at the same time can reduce resource consumption way, that there was a minikube, including k8s website and tubing, the great god of all stripes in use, but the domestic network environment, Minikube is not so easy to use. Later, I heard that a company called Rancher produced a software called K3S, which is said to be a release of Kubernetes, designed for the Internet of Things and edge computing. It has a simple and lightweight design, so I started to build and test it (due to network problems, there will be some pitfalls later).

Architecture diagram

Environment to prepare

K3s architecture is divided into K3S Server and K3S Agent. Here, only one machine is intended to act as the server and agent at the same time, so it is ok to start a VIRTUAL machine on your own computer. This article takes centos7.x as an example.

The official website and some reference links

https://docs.rancher.cn/docs/k3s/quick-start/_index/
https://www.infoq.cn/article/jizyup2sl30kkfqjfblw
https://rancher.com/docs/k3s/latest/en/installation/private-registry/
Copy the code

The INSTALLATION of K3S starts

Please refer to the Quick Start manual on the official website to see that the installation script is provided and there are options suitable for domestic users:

curl -sfL http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
Copy the code

After running this installation:

  • The K3s service will be configured to restart automatically after the node restarts or if the process crashes or is killed
  • Other utilities will be installed, including kubectl, crictl, CTR, k3s-killall.sh and k3s-uninstall.sh
  • Kubeconfig file written to the/etc/rancher/k3s/k3s yaml, by kubectl k3s installation will automatically use the file

K3s is known for being lightweight, so by default containerd is built into the k8S container runtime. Cri is short for Container Runtime Interface (CRI), so any container that meets the CRI standard can be run using this tool.

Register the Agent with the server

If the script is executed successfully, you can see that the K3S server is already running. In this case, we need to pass a token value in advance for future use:

cat /var/lib/rancher/k3s/server/node-token
Copy the code

The output is a long string, so I’ll put it here. Run the following command to register the agent

curl -sfL http://rancher-mirror.cnrancher.com/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -
Copy the code

Replace myServer with the IP address of your server and myNodeToken with the string above. You can run the following command to view your node.

kubectl get nodes
Copy the code

Configure Containerd to pull the domestic mirror address of the mirror

As mentioned earlier, k3S uses the built-in Containerd as the underlying runtime by default, and by default, like Docker, it downloads the image from the Docker Hub. The registry-mirrors address can be set in Docker. If the pull image does not have a repository address (project name + image name :tag), the image will be pulled from the default repository. If the mirror acceleration address is configured, the system accesses the mirror acceleration repository first. If no data is returned, the system accesses the default mirror repository.

Currently, Containerd does not directly configure the image acceleration function. However, Containerd can modify the endpoint corresponding to docker. IO.

In the configuration file “/ etc/rancher/k3s/registries yaml” add the following content (if not please directly created) :

mirrors:
  "docker.io":
    endpoint:
      - "https://hub-mirror.c.163.com"
Copy the code

I have configured a 163 address, you can optionally configure domestic acceleration mirror site, you can add more, will poll. Then restart the K3S service (to be on the safe side):

systemctl restart k3s
systemctl restart k3s-agent
Copy the code

Check whether the configuration takes effect:

crictl info
Copy the code

If you see the mirror where you configure the address that it is ok.

Try to pull the mirror

You can use the following command to try to pull the docker Hub image:

crictl pull nginx
Copy the code

View local mirrors:

crictl image ls
Copy the code

The last

One last look at kubectl get node is ready. I will write the traditional way of Docker + K8S when I have time later.