4.2 KiB
obj | website | repo |
---|---|---|
application | https://k3s.io | https://github.com/k3s-io/k3s |
k3s
K3s is a certified Kubernetes distribution developed by Rancher (now part of SUSE). It is designed to be lightweight, simple to install, and optimized for resource-constrained environments such as edge computing, IoT devices, and development setups.
Installation
K3s provides an installation script that is a convenient way to install it as a service on systemd or openrc based systems. This script is available at https://get.k3s.io. To install K3s using this method, just run:
curl -sfL https://get.k3s.io | sh -
After running this installation:
- The K3s service will be configured to automatically restart after node reboots or if the process crashes or is killed
- Additional utilities will be installed, including
kubectl
,crictl
,ctr
,k3s-killall.sh
, andk3s-uninstall.sh
- A kubeconfig file will be written to
/etc/rancher/k3s/k3s.yaml
and thekubectl
installed by K3s will automatically use it
A single-node server installation is a fully-functional Kubernetes cluster, including all the datastore, control-plane, kubelet, and container runtime components necessary to host workload pods. It is not necessary to add additional server or agents nodes, but you may want to do so to add additional capacity or redundancy to your cluster.
To install additional agent nodes and add them to the cluster, run the installation script with the K3S_URL
and K3S_TOKEN
environment variables. Here is an example showing how to join an agent:
curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -
Setting the K3S_URL
parameter causes the installer to configure K3s as an agent, instead of a server. The K3s agent will register with the K3s server listening at the supplied URL. The value to use for K3S_TOKEN
is stored at /var/lib/rancher/k3s/server/node-token
on your server node.
HA (Embedded etcd)
To get started, first launch a server node with the cluster-init
flag to enable clustering and a token that will be used as a shared secret to join additional servers to the cluster.
curl -sfL https://get.k3s.io | K3S_TOKEN=SECRET sh -s - server \
--cluster-init \
--tls-san=<FIXED_IP> # Optional, needed if using a fixed registration address
After launching the first server, join the second and third servers to the cluster using the shared secret:
curl -sfL https://get.k3s.io | K3S_TOKEN=SECRET sh -s - server \
--server https://<ip or hostname of server1>:6443 \
--tls-san=<FIXED_IP> # Optional, needed if using a fixed registration address
Check to see that the second and third servers are now part of the cluster:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
server1 Ready control-plane,etcd,master 28m vX.Y.Z
server2 Ready control-plane,etcd,master 13m vX.Y.Z
server3 Ready control-plane,etcd,master 10m vX.Y.Z
Now you have a highly available control plane. Any successfully clustered servers can be used in the --server
argument to join additional server and agent nodes. Joining additional agent nodes to the cluster follows the same procedure as servers:
curl -sfL https://get.k3s.io | K3S_TOKEN=SECRET sh -s - agent --server https://<ip or hostname of server>:6443
There are a few config flags that must be the same in all server nodes:
- Network related flags:
--cluster-dns
,--cluster-domain
,--cluster-cidr
,--service-cidr
- Flags controlling the deployment of certain components:
--disable-helm-controller
,--disable-kube-proxy
,--disable-network-policy
and any component passed to--disable
- Feature related flags:
--secrets-encryption
Existing single-node clusters
If you have an existing cluster using the default embedded SQLite database, you can convert it to etcd by simply restarting your K3s server with the --cluster-init
flag. Once you've done that, you'll be able to add additional instances as described above.
If an etcd datastore is found on disk either because that node has either initialized or joined a cluster already, the datastore arguments (--cluster-init
, --server
, --datastore-endpoint
, etc) are ignored.