I have been experimenting with various resources that are available for learning & practicing with Kubernetes and there are quite a few good resources out there. With that said, I hit somewhat of a roadblock the other day when I realized that I (at least for now) was unable to get the latest Kubernetes V1.19 on my own machine via Docker-Desktop or my local install of Minikube. After letting my mind wander a bit, I thought: why not try installing Kubernetes on an Ubuntu Server via an install from OSBoxes.org. After scouring the internet for tutorials on configuring Kubernetes on Ubuntu Server, I came across a very handy tool named MicroK8s via a message in my console when I logged into my new instance of Ubuntu Server this morning. This made my day to put it mildly!
Installing Ubuntu Server on MacOS via VirtualBox
To install Ubuntu Server 20.04 Focal Fossa on Virtual Box, go to the downloads page and download the image provided by OSBoxes.org. For instructions on how to configure the image with VirtualBox, visit this link for instructions.
To verify that your new image has been properly configured with VirtualBox, simply open up VirtualBox in your applications folder, start the VM and login to Ubuntu Server with the default credentials that are provided with the installation. Success!!
NOTE: the default username for a OSBox image is
osboxes and the default password to log into your downloaded images is
SSH into Ubuntu Server
The next step is to set up port forwarding in order to be able to SSH into Ubuntu Server with either Bash or ZSH on your local machine.
To SSH into Ubuntu Server from your host/local machine, you first have to prepare the image so that you can set up port forwarding by confirming that the OpenSSH Server service is installed and enabled. From within the Ubuntu Server interface run these commands:
# Get the IP of your VM ip addr show # Ping Google to test that you can connect to the internet ping www.google.com # Check if ssh status is enabled/installed service sshd status # If ssh in not installed run sudo apt install openssh-server # Start the service sudo systemctl start sshd # Check the status once more service sshd status # Locate your VM via the VirtualBox interface and go to Settings => Network => Adapter 1 (..where the default NAT adapter is located) => Port-forwarding (located @ the bottom of the popup window) => Create Rule (ie., the green arrow on the right) # Give your new rule a name like SSH Port # Leave the default Protocol set to TCP # Assign a Host Port (I went with port 7777) # Leave the Guest Port default of 22 # Open up your terminal on your local machine, SSH into Ubuntu Server: ssh -p 7777 email@example.com # Enter the default credentials: user: osboxes password: osboxes.org
Create New User with Sudo Privileges
To create a new user with sudo privileges run the commands below while logged in as the default root user
sudo adduser <your-new-username> sudo adduser <your-new-username> sudo
Add the new user to the sudo Group (for more information, see here:
# Switch to root su # Add user to sudo Group usermod -aG sudo <your-new-username> # Check that the user has sudo privileges whoami
Optional: Change the Hostname
To change the hostname run:
sudo vim /etc/hostname # replace default hostname w/ your chosen name sudo reboot ssh -p 7777 <your-new-username>@127.0.0.1
Install Kubernetes v1.19 with MicroK8s
To install, stop & start Kubernetes v1.19 with MicroK8s run:
sudo snap install microk8s --channel=1.19/candidate --classic microk8s start microk8s stop
That's it! It's that simple. You now have a single node Kubernetes cluster running on your new VirtualBox Ubuntu Server image! Pretty cool stuff!!
For more information on setting up, working with, and configuring your new cluster visit the Introduction to Microk8s and follow the steps provided by MicroK8s.
Being that I spend a lot of time working in my terminal, I have become a big fan of using aliases to make my life easier. So naturally, one of my first priorities was to set up Kubectl aliases on my newly installed MicroK8s via a few steps:
Note from the MicroK8s docs:
MicroK8s uses a namespaced kubectl command to prevent conflicts with any existing installs of kubectl.
sudo vim ~/.bash_aliases alias kb="microk8s kubectl" alias kbgs="microk8s kubectl get secrets" alias kbe="microk8s kubectl edit" alias kbgp="microk8s kubectl get pods" alias kbdp="microk8s kubectl describe pod" alias kbdn="microk8s kubectl describe node" alias kbep="microk8s kubectl edit pod" alias kbc="microk8s kubectl create -f" alias kbgn="microk8s kubectl get nodes" alias kbgn="microk8s kubectl get namespaces" alias kbgpan="microk8s kubectl get pods --all-namespaces" alias cl=clear alias kbcn="microk8s kubectl create namespace" alias kba="microk8s kubectl apply -f" alias kbc="microk8s kubectl create -f" alias kbd="microk8s kubectl delete" alias kbed="microk8s kubectl edit deployment" alias kbsd="microk8s kubectl scale deployment" alias kbcdy="microk8s kubectl create deployment" alias dry="--dry-run=client -o yaml" export fo="--grace-period=0 --force" export do="--dry-run=client -o yaml" export fl="--from-literal=" alias rn="--restart=Never" alias dry="--restart=Never -o yaml --dry-run=client" alias sc="microk8s kubectl config set-context --current --namespace=" alias rj="--restart=OnFailure" export cj="--restart=OnFailure --schedule=" alias kbrh="microk8s kubectl rollout history" alias kbru="microk8s kubectl rollout undo" alias r="--record" alias kbrsd="microk8s kubectl rollout status deployment" alias kbsi="microk8s kubectl set image deployment" alias kbdd="microk8s kubectl describe deployment" alias kbln="microk8s kubectl label nodes" alias kbgnsl="microk8s kubectl get nodes --show-labels" alias kbgpsl="microk8s kubectl get pods --show-labels" alias kbcc="microk8s kubectl config current-context" alias kbsc="microk8s kubectl config set-context --current" alias kbcj="microk8s kubectl create job" alias kbccj="microk8s kubectl create cj cj1 -o yaml --dry-run=client --schedule="*/1 * * * *" --image=throw-dice > cj1.yaml" alias kbed="microk8s kubectl expose deploy" alias kbexp="microk8s kubectl expose pod" alias kbr="microk8s kubectl run" alias rn="--restart=Never" alias kbgm="microk8s kubectl top pod" alias h=history
Some Addons to Consider
To get started, I installed these addons at the outset:
# add DNS management microk8s enable dns storage # get metrics like top... microk8s enable metrics-server # add an NGINX Ingress Controller microk8s enable ingress
I hope that anyone who reads this enjoys this post. I, for one, am super stoked to be able to test out the latest Kubernetes commands on my local laptop without having to spin up a paid cluster for testing/practice purposes!!
*PSA NOTE: I am only using this (as currently configured) for development/testing/practice purposes, not for production!! *