Setting up local Kubernetes on a virtual machine
Here is how I set up local Kubernetes on a DigitalOcean virtual machine(VM) using minikube.
minikube is a local Kubernetes, that allows to create and work on Kubernetes cluster locally. Requirements for setting up minikube.
- 2 CPUs or more
- 2GB of free memory
- 20GB of free disk space
- A virtual machine manger, e.g. Docker
Make sure your instance meets the above hardware requirements. In my case, my DigitalOcean droplet(VM) was running on 1 CPU, 1GB of RAM, 25 GB disk space. Since that was not enough, I had to resize it to 2 CPUs and 2GB of RAM.
Then installed Docker as follows:
1. Setup package repository and Install Docker
Setup the repository
Connect to your digital ocean instance using ssh and then:
Update package index and install packages to enable https access to a package repository
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
Add Docker'ss GPG key
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add the stable package repository.
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
Install Docker Engine
$ sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Verify Docker's installation using the following command. It will download a test image and run it in a container. When the container runs, it prints an informational message and exits.
$ sudo docker run hello-world
One last thing, add your user to the “docker” group so that you can use docker as a non-root user
sudo usermod -aG docker <your-user>
Now that we have all the requirements for minikube in place, we can go ahead and install minikube.
2. minikube
My VM is on Linux Ubuntu and has amd64 / x86_64 architecture. You can find out your VM's info using the command
uname -a
Install minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb
Start a cluster
minikube start
Get minikube dashboard
minikube dashboard allows to have a visual representation of the resources that exist on the local cluster. To obtain the dashboard's URL use the command:
minikube dashboard --url
Now, the returned URL is a local address (127.0.0.1) which refers to the Digital Ocean VM. In order to have access from our local machine we can create an SSH tunnel.
Example
minikube dashboard URL
127.0.0.1:33411/api/v1/namespaces/kubernete..
Create an SSH tunnel ssh -N -L 8888:127.0.0.1:33411 -i KEYFILE username@IPAddressOfTheVM
NOTE: If successful, the above command will create an SSH tunnel but will not display any output on the server console.
This will create a secure tunnel by forwarding the destination port: (127.0.0.1:33411) on the remote server to a source port (8888) on the local host/machine.
Then, open the dashboard URL in a browser to view the components of the kubernetes cluster. It should look something like this:
If you made it this far, Bravo!!! Would love to read your feedback below.
References: