K8S lightweight version of K3S installation tutorial

@eyasliu 2019-08-21 07:54:44 published in eyasliu / blog server

K3S official website: https://k3s.io/

K8S and K3S what to do with it, the official website of the original words

k3s designed to be fully compatible Kubernetes releases, k8s major changes are as follows:

  1. Old, Alpha version of the non-default features have been removed.
  2. Removed most cloud providers and internal memory card can be replaced with a plug.
  3. New SQLite3 as the default storage mechanism, etcd3 still valid, but is no longer the default.
  4. Packaged in simple starter can handle a large number of LTS and complexity options.
  5. Minimize to no operating system dependent, and only a core mount cgroup.

It is entirely possible to K3S instead of K8S, but also takes up resources will be smaller, there will be no loss of functionality, but also easier.
K3S is K8S lightweight version, but not castrated version, K8S functions it has, is also compatible with a variety of plug-ins and applications K8S.

Into the official website, you can see that there can be a key installation command

-sfL curl https://get.k3s.io | sh -

If the server is in a foreign country, it should not be a network problem, use a command that can be installed successfully. If the server in mainland China, will encounter a series of network problems, server installation process domestic K3S in this record

Ready to work

Install the specified version of docker

Here we must note down, k8S for docker version is required, not too high, the time of this writing, the latest version K8S is v1.14.6the latest version K3S is v0.8.1, at this time the latest version K3S is also compatible with the latest version of K8S, which docker time K8S version of the maximum support to 18.06the current latest version is the docker 19.03, so be careful when installing the docker's version number.

For example with ubuntu

# Step 1: install GPG certificate 
$ curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo APT the Add-Key - 

# the Step 2: writing software source information 
$ sudo add- Repository-APT "the deb [Arch = AMD64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $ (lsb_release -cs) the stable" 

# the Step. 3: update source 
$ -Y update the sudo APT-GET 

# Step 4: Check the current version can be installed docker 
# centos use List docker-ce --showduplicates yum 
$ APT-ce-Cache Policy docker 
docker-ce: 
  installed: 18.06.3 3-0 ~ ~ ~ ce Ubuntu 
  Candidate: 5: ~ ~ 3-0-Ubuntu 19.03.1 Bionic 
  Version Table: 
     . 5: 19.03.1 Ubuntu-Bionic ~ ~ 500 3-0 
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu Bionic / AMD64 the stable Packages 
     . 5: 19.03.0 Ubuntu ~ 3-0 ~ 500-Bionic
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
     5:18.09.8~3-0~ubuntu-bionic 500
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
     5:18.09.7~3-0~ubuntu-bionic 500
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
     5:18.09.6~3-0~ubuntu-bionic 500
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
     5:18.09.5~3-0~ubuntu-bionic 500
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
     5:18.09.4~3-0~ubuntu-bionic 500
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
     5:18.09.3~3-0~ubuntu-bionic 500
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
     5:18.09.2~3-0~ubuntu-bionic 500
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
     5:18.09.1~3-0~ubuntu-bionic 500
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
     5:18.09.0~3-0~ubuntu-bionic 500
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
 *** 18.06.3~ce~3-0~ubuntu 500
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
        100 /var/lib/dpkg/status
     18.06.2~ce~3-0~ubuntu 500
        Bionic https://mirrors.aliyun.com/docker-ce/linux/ubuntu 500 / the stable AMD64 the Packages 
     18.06.1 Ubuntu ~ ~ CE ~ 500 3-0 
        500 https://mirrors.aliyun.com/docker-ce/ Linux / Ubuntu Bionic / the stable AMD64 the Packages 
     18.06.0 Ubuntu ~ ~ CE ~ 500 3-0 
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu Bionic / the stable AMD64 the Packages 
     18.03.1. 3 ~ ~ CE Ubuntu 500 ~ -0 
        500 https://mirrors.aliyun.com/docker-ce/linux/ubuntu Bionic / the stable AMD64 the Packages 

# the Step. 5: install the specified version 
# centos use sudo yum install docker-ce-18.06.3.ce -3.el7 
$ APT the install the sudo docker -Y-CE = CE ~ ~ 3-0 ~ 18.06.3 Ubuntu 

# Step 6: 验证安装
$ the sudo docker Version 

# the Step. 7: docker the current user is added to the user group, after which the user may not execute commands dokcer then you need to sudo, need to re-login to take effect
$ sudo usermod -aG docker $USER

Download the executable file

First download the binary file k3s of local, note the version number of url

https://github.com/rancher/k3s/releases/download/v0.8.1/k3s

Once downloaded to find ways to upload to the server, provided by way of example here scp

scp -P 23 ./k3s [email protected]:/home/user/

Then connect to the server, the files into k3s /usr/local/binand add executable permissions

sudo mv ./k3s /usr/local/bin/
sudo chmod +x /usr/local/bin/k3s

So that when installed will not go back k3s download files k3s

Download the base image

The installation will download some time in k8s.gcr.iothe mirror, was a wall, installed in advance, pay attention to mirror the version number is not the latest version of the current time

docker pull mirrorgooglecontainers/pause:3.1
docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1

Start the installation K3S

installation

-sfL curl https://get.k3s.io | sh -

Because in the preparation of a good majority of downloads of the download, so this process should be soon, Bahrain verify

$ sudo kubectl get nodes
NAME             STATUS   ROLES    AGE     VERSION
vm-0-16-ubuntu   Ready    master   3h26m   v1.14.6-k3s.1

Change setting

Make the following changes

  • The engine is switched from the default container Containerd to Docker,
  • Modify the configuration file permissions can be made to perform kubectl command does not require root privileges
sudo vim /etc/systemd/system/multi-user.target.wants/k3s.service

Need to modify the value ExecStart will change it to:

/usr/local/bin/k3s server --docker --no-deploy traefik --write-kubeconfig-mode 664

Restart Service

systemctl-daemon reload sudo 
sudo systemctl restart k3s 

# node and then see whether the normal start 
sudo k3s kubectl get node

This completes the deployment of K3S

K8S cluster

Since K3S is K8S lightweight version, that clustering is there.

All machines installed K3S

According to the article above process, all the machines are installed in over K3S, all machines are temporarily treated as a master node, install all alone again, be sure to use the following command to find its own node After installing

sudo k3s kubectl get node

Configure master node

Now all machines are ready, arbitrarily chosen as a master node. If all of your machines are on the same network segment, for example, we are in the same local area network, the master node does not need to make any changes can be directly used, skip this step. If each machine is a cross-segment, cross-cloud providers (such as a machine that Ali cloud, a cloud machine is Tencent, there is an Amazon cloud), but the need to ensure that all machines have a public IP, then the master node K3S modify the configuration, the K3S the public IP address binding

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

ExecStart modify the field value, wherein the attention ip 12.34.56.78modify your public network master node ip

/usr/local/bin/k3s server --docker --no-deploy traefik --write-kubeconfig-mode 664 --kube-apiserver-arg="advertise-address=12.34.56.78" --kube-apiserver-arg="external-hostname=12.34.56.78"

Then restart the service

sudo systemctl daemon-reload
sudo systemctl restart k3s 

Configuring slave node

Currently master node configured, now configure the slave node. In fact, there are bottom K3S official website say how to join, process is as follows

Execute the following command in the maser node, pay attention to your own ip into

$ echo /usr/local/bin/k3s agent --server https://12.34.56.78:6443 --token `sudo cat /var/lib/rancher/k3s/server/node-token`
sudo k3s agent --server https://12.34.56.78:6443 --token K1022c3b20bd00e2b705ca34551b5e346dcce703dsr132dddfc3f8323b0adb1fb9::node:adb40646cf6fdc1239e3d769b9dbbb9a

Copy the contents of the above good command output to all of the slave node configuration editor

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

The profile ExecStartmodify the value of the above content output, save and reboot modified K3S

sudo systemctl daemon-reload
sudo systemctl restart k3s 

Verify, to the maser node, execute the command to view the currently available nodes, you can see other nodes to join

$ kubectl get node
NAME                      STATUS   ROLES    AGE   VERSION
iz2ze4grlnalbfkizskkadf   Ready    master   25h   v1.14.6-k3s.1
vm-0-16-ubuntu            Ready    worker   18h   v1.14.6-k3s.1
Original articles published 0 · won praise 0 · Views 534

Guess you like

Origin blog.csdn.net/qingdao666666/article/details/104712338