- Rancher is an amazing GUI for managing and installing Kubernetes clusters. It addresses the operational and security challenges of managing multiple Kubernetes clusters across any infrastructure, while providing DevOps teams with integrated tools for running containerized workloads.
- K3s is designed to be a single binary of less than 40MB that completely implements the Kubernetes API. In order to achieve this, they removed a lot of extra drivers that didn’t need to be part of the core and are easily replaced with add-ons.
It is much easier than what I thought before for installing both and integrate them. One command for Rancher and one command for K3S, then modify k3s service file to change container engine from containered to docker. After that, another command to import K3S into Rancher. That’s it.
Install Docker environment
Install Rancher Server
Import an existing cluster
Copy the third script for next step to import cluster into Rancher.
Install K3S cluster
root@K3S-1:~# vim /etc/systemd/system/multi-user.target.wants/k3s.service root@K3S-1:~# systemctl daemon-reload root@K3S-1:~# service k3s restart root@K3S-1:~# k3s kubectl get node NAME STATUS ROLES AGE VERSION k3s-1 Ready master 58s v1.18.6+k3s1 root@K3S-1:~#
Import the K3S cluster to Rancher
On the current Rancher Server, the cluster status is displayed as Pending , like this:
root@K3S-1:~# curl --insecure -sfL https://188.8.131.52/v3/import/6tx4vblm9464jc4wnvj5kx87qsxxkqxcrmn575msq55j6j2bvdzcvk.yaml | kubectl apply -f - error: no objects passed to apply root@K3S-1:~# curl --insecure -sfL https://184.108.40.206/v3/import/6tx4vblm9464jc4wnvj5kx87qsxxkqxcrmn575msq55j6j2bvdzcvk.yaml --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: proxy-clusterrole-kubeapiserver rules: - apiGroups: [""] resources: - nodes/metrics - nodes/proxy - nodes/stats - nodes/log - nodes/spec ...(Omitted)... - name: k8s-ssl hostPath: path: /etc/kubernetes type: DirectoryOrCreate - name: var-run hostPath: path: /var/run type: DirectoryOrCreate - name: run hostPath: path: /run type: DirectoryOrCreate - name: cattle-credentials secret: secretName: cattle-credentials-26fff6d defaultMode: 320 - hostPath: path: /etc/docker/certs.d type: DirectoryOrCreate name: docker-certs updateStrategy: type: RollingUpdate rollingUpdate: maxUnavailable: 25% root@K3S-1:~# curl --insecure -sfL https://220.127.116.11/v3/import/6tx4vblm9464jc4wnvj5kx87qsxxkqxcrmn575msq55j6j2bvdzcvk.yaml | kubectl apply -f - clusterrole.rbac.authorization.k8s.io/proxy-clusterrole-kubeapiserver created clusterrolebinding.rbac.authorization.k8s.io/proxy-role-binding-kubernetes-master created namespace/cattle-system created serviceaccount/cattle created clusterrolebinding.rbac.authorization.k8s.io/cattle-admin-binding created secret/cattle-credentials-26fff6d created clusterrole.rbac.authorization.k8s.io/cattle-admin created deployment.apps/cattle-cluster-agent created daemonset.apps/cattle-node-agent created root@K3S-1:~#
This status shows that Rancher has received the registration request from K3S and is completing the registration of the K3S cluster. Wait a couple of seconds to complete the import of the K3S cluster, and status will become Active:
At this point, we have successfully completed the connection between Rancher 2.x and K3S, and can operate the K3S cluster just like the K8S cluster.