Although we’ve learned how to install Kubernetes locally using Minikube in a previous post, we want to try new and easier ways to do it. The purpose of this post is to install Kubernetes as easy as possible but this time using RKE. These are some possible scenarios:
- Run k8s applications in your laptop.
- Develop new services and run them locally.
Before you begin
In this tutorial, we’ll learn how to install Kubernetes on local machine/server using Rancher Kubernetes Engine aka RKE. The examples on this post have been tested in Ubuntu but a Linux/Mac OS machine with Docker and Kubernetes client kubectl is good enough to follow this tutorial.
You can install the Kubernetes client kubectl following the official docs here.
The installation of RKE is pretty easy, you just need to download the binary to start using it:
wget -O rke https://github.com/rancher/rke/releases/download/v0.3.1/rke_linux-amd64 chmod +x rke sudo mv rke /usr/local/bin # Checking Rancher RKE version rke --version > rke version v0.3.1
See Rancher Kubernetes Engine installation page for more info.
Before installing k8s and running rke up make sure that the docker daemon already started and that you have a ssh user that can easily ssh to your machine using its public key (without password prompting).
Command to check Docker is up:
service docker status service docker start
Run the following command with the user that you want to use in RKE/Kubernetes installation.
From now on we can suppose that my_user is your current user. Make sure that sshd service is already up and running:
service sshd status service sshd start
Also check that the user can SSH to your machine using its public SSH key. To do so make sure that the public key is in your authorized_keys file with 600 permission.
cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys
And finally, check again:
If you succeed running previous step you can proceed installing k8s.
In order to install Kubernetes using Rancher RKE we need a cluster.yml. RKE provides a command line form to create the previous file:
# Creating a cluster.yml file rke config --name cluster.yml
We can use the default answers (just press intro) to the vast majority of the questions except for the following 5 questions:
[+] SSH Address of host (1) [none]: localhost [+] SSH User of host (localhost) [ubuntu]: my_user [+] Is host () a Control Plane host (y/n)? [y]: y [+] Is host () a Worker host (y/n)? [n]: y [+] Is host () an etcd host (y/n)? [n]: y
After answering all the questions make sure that you have a cluster.yml file.
Run the following RKE command to start the installation:
Check k8s installation
Once the Kubernetes cluster is running, make sure that you can see the k8s nodes:
kubectl --kubeconfig kube_config_cluster.yml get nodes
You can skip the need of passing kube_config_cluster.yml as a kubeconfig param by copying this file to your local/default .kube/config file as follows:
cp kube_config_cluster.yml ~/.kube/config kubectl get nodes > NAME STATUS ROLES AGE VERSION > localhost Ready controlplane,etcd,worker 10m v1.15.5
Because we are installing kubernetes locally, the full k8s cluster will be in a single machine: The control plane, etcd and worker components will in the same machine. Obviously this setup is not recommended for production purposes.
See Rancher Kubernetes Engine Overview page for more info and other Rancher RKE tutorials.