DEV Community

Cover image for k3sup On MacOS Catalina
John Doyle
John Doyle

Posted on • Originally published at gizmo.codes

k3sup On MacOS Catalina

I'm brand new to Kubernetes and looking at setting up K3s, a light-weight certified Kubernetes distribution, with k3sup. The utility, built by Alex Ellis, was recommended in Rancher Lab's Intro to Kubernetes and Rancher as an easy way to setup Kubernetes - which I am ALL for!

Overview

Ok, to get Kubernetes up and running I'll take you through the following steps:

  1. Install VirtualBox
  2. Download Ubuntu
  3. Setup a Virtual Machine
  4. Configure the Virtual Machine
  5. Run k3sup

Setup - Install VirtualBox

Keep your comfort chew toy nearby as it may be needed. Turns out that you down run K3s locally you your mac!

So we will need to get VirtualBox up and running. I like installing this with Homebrew:

$ brew cask install virtualbox
Enter fullscreen mode Exit fullscreen mode

VirtualBox will allow us to run another operating system on our computer! We can then launch it from the command line or via Spotlight etc - homebrew should have installed it into our Applications folder.

Ubuntu

Thinking a bit ahead, we want to select the OS that we will run, this is where K3S will be installed and our Kubernetes cluster will be running. I'm going to go with the simple Ubuntu. There are several varieties - do you want a desktop or server etc. I choose the server option, as we should only need the terminal!

At this time, Ubuntu Server 20.04.1 LTS is available, so download that - its a little over 2.5 GBs.

Setup A Virtual Machine

Since we have VirtualBox and our operating system ISO image downloaded, lets set up our Virtual Machine. Within VirtualBox you will want to click New in the top right:

I kept it simple with the following settings:

Option Value
Name Demo
Type Linux
Version Ubuntu (64-bit)

I keep all other options to the default, click through till I'm back at the VirtualBox UI with demo appearing on the left.

I want to make one change to this machine before we kick off the install, and that is to make it easier to SSH into it later. So click settings:

And navigate to the Network tab. You'll want to change the Network adapter to be a Bridged Adapter:

Configure the Virtual Machine

You'll be asked to select the ISO image you downloaded for Ubuntu. Once you do, it will take a minute or two as it loads up everything before guiding you through the install. Again, I simply selected all the defaults, with ONE execption.

After prompting for the username/password, you are asked if you want to Install OpenSSH server, and I did choose that. Everything else remains a default option.

Once Ubuntu is fully installed and restarted, we are to login on VirtualBox:

Once logged in, we want to install net-tools:

$ sudo install net-tools -y
Enter fullscreen mode Exit fullscreen mode

Now we can find the IP address of our virtual machine:

$ ifconfig
Enter fullscreen mode Exit fullscreen mode

So I'll note down 192.168.1.165!

SSH

K3sup will SSH into our virtual machine to set everything up. We want it to run as the super user root. Yet, Ubuntu does not allow users to ssh into root using a password by default. So we will:

  1. Create an SSH Key
  2. Copy it to our user on Ubuntu
  3. Give it to root

Lets start with our SSH key:

$ ssh-keygen -b 4096
Enter fullscreen mode Exit fullscreen mode

I saved my key to /Users/john/.ssh/virtualbox.

Now I setup my user as gizmo so I can now copy the newly generated key to the virtual machine with:

$ ssh-copy-id -i ~/.ssh/virtualbox.pub gizmo@192.168.1.165
Enter fullscreen mode Exit fullscreen mode

And you should get output similar to the following:

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/john/.ssh/virtualbox.pub"
The authenticity of host '192.168.1.165 (192.168.1.165)' can't be established.
ECDSA key fingerprint is SHA256:44chMilIP9TccmwKCWFelj/JizrUQGCYE/vv4tXURQU.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
gizmo@192.168.1.165's password:

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh 'gizmo@192.168.1.165'"
and check to make sure that only the key(s) you wanted were added.
Enter fullscreen mode Exit fullscreen mode

And we will test this by logging into the machine:

$ ssh -i ~/.ssh/virtualbox gizmo@192.168.1.165
Enter fullscreen mode Exit fullscreen mode

You should get in without getting prompted for any credentials.

Now we want to move this key over to the root user so that k3sup can work:

$ gizmo@demo:~$ sudo su
[sudo] password for gizmo:
$ root@demo:/home/gizmo# cp .ssh/authorized_keys ~/.ssh/
Enter fullscreen mode Exit fullscreen mode

If we exit out back to our mac terminal, we can verify this again by connecting as root:

$ ssh -i ~/.ssh/virtualbox root@192.168.1.165
Enter fullscreen mode Exit fullscreen mode

Exit out of the ubuntu machine.

Run k3sup

The simplicity of this tool is wonderful! We can install it on our mac with:

curl -sLS https://get.k3sup.dev | sh
Enter fullscreen mode Exit fullscreen mode

And we can get our Kubernetes cluster up and running in under a minute:

k3sup install --ip=192.168.1.165 --ssh-key="~/.ssh/virtualbox" --user=root --k3s-version=v1.18.3+k3s1
Enter fullscreen mode Exit fullscreen mode

The script will SSH into our Ubuntu server and configure our Kubernetes cluster.

It should end with something similar to the following:

# Test your cluster with:
export KUBECONFIG=/Users/john/../k3sup-On-MacOs-Catalina/kubeconfig
kubectl get node -o wide
Enter fullscreen mode Exit fullscreen mode

Lets try these commands out:

$  kubectl get node -o wide
NAME   STATUS   ROLES    AGE   VERSION        INTERNAL-IP     EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION     CONTAINER-RUNTIME
demo   Ready    master   54s   v1.18.3+k3s1   192.168.1.165   <none>        Ubuntu 20.04.1 LTS   5.4.0-42-generic   containerd://1.3.3-k3s2
Enter fullscreen mode Exit fullscreen mode

Great! We have stuff up and running - now to continue on with the Kubernetes tutorials!

Oldest comments (0)