Skip to content

Instantly share code, notes, and snippets.

@lucaguada
Last active April 4, 2024 07:19
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save lucaguada/e4c3725542c1cafa1fb3ea8a56c7e2d0 to your computer and use it in GitHub Desktop.
Save lucaguada/e4c3725542c1cafa1fb3ea8a56c7e2d0 to your computer and use it in GitHub Desktop.
Steps to fully install Ubuntu Server and MiniKube on Raspberry Pi 4 (wip)

How to install Ubuntu Server and Minikube on Raspberry Pi 4 4GB+ (recommended)

Disclaimer: this step-by-step GIST has been created with no guarantees, I may have missed some steps because of distraction or chiptune improvised on-chair-dancing, so be patient and let me know if I must add or fix something.

This is the way for living long and prospering!

Download Raspberry Pi Imager

Download and install Raspberry Imager: https://www.raspberrypi.org/software/

Then put your SD in your laptop or desktop, choose and write the image Ubuntu Server 20.10 64Bit (or 32Bit if you prefer). Boot your Raspberry Pi 4 with the new system, log in with ubuntu/ubuntu and set a new password (the OS will ask to do so).

Set your Wifi Connection

Edit the following file: sudo nano /etc/netplan/50-cloud-init.yaml in order to have your configuration like this:

## already there
network:
    ethernets:
        eth0:
            dhcp4: true
            optional: true
    version: 2
## what you need to add:
    wifis:
        wlan0:
            dhcp4: true
            optional: true
            access-points:
                "SSID_name":
                    password: "WiFi_password"

then you can type: sudo netplan generate && sudo netplan apply or just reboot.

I didn't face any issue, but if you meet some problems try to read the source. Source > https://itsfoss.com/connect-wifi-terminal-ubuntu/

Unleash update and upgrade

Just sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y.

Set your keyboard layout (Optional)

Install console-common with the following command: sudo apt install console-common. After that configure the keyboard with: sudo dpkg-reconfigure keyboard-configuration.

Source > https://askubuntu.com/questions/434849/change-keyboard-layout-english-uk-on-command-line-to-english-us

Install net-tools (Recommended)

Well... just sudo apt install net-tools, you can then check your nice IP's.

Edit hostname and add a custom user (Optional)

If you're snobbish about default usernames and hostnames, or you have a favourite way to name your laptop/desktop hosts/users like me (i.e. all my devices and usernames are named against Transformers characters), you need to do a couple of things.

Edit hostname

Just sudo nano /etc/hostname and then reboot. Nothing else (in /etc/hosts I didn't find any reference to the old hostname).

Add New User

Just sudo adduser your_cool_username && sudo adduser your_cool_username sudo and then you will have a new user to log-in with.

If you also want to remove the user ubuntu, you need to log-out and then log-in with your new user. Then just sudo userdel -r ubuntu, it will delete user settings and home folder. By the way, don't worry about the error for mail spool, it's ok.

Enable CGROUP CPUSET and MEMORY

To make Minikube work, you need to enable some Linux kernel features named Control Groups. I didn't get why but in Ubuntu the cmdline.txt is placed in a different folder from RaspOS/Raspian. Anyway as always just sudo nano /boot/firmware/cmdline.txt and add the following settings at the end of the line, not in a new line, but at the end of the first line:

cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1

Install Docker

Fortunately, there's a funny shell-script to make the things trivial for us. For starters curl -fsSL https://get.docker.com -o get-docker.sh then just sudo sh get-docker.sh.

Once done I strongly suggest to add your user or ubuntu user to the docker group: sudo usermod -aG docker your_cool_user.

Source > https://phoenixnap.com/kb/docker-on-raspberry-pi

Install Arkade

arkade is a nice CLI tool for installing Kubernetes apps and other related stuff. Just curl -sSL https://dl.get-arkade.dev | sudo sh and then you're done.

Install Kubectl

Well, you can now just type arkade get kubectl and follow the instructions provided by arkade.

Install, Start and Test Minikube

Now the not-that-trivial part. At this moment minikube is not fully ready for the ARM architecture, some features are missing, but with some caveats, you can run it and start to play with it. Just keep in mind minikube for ARM is not production-ready, yet.

Install Minikube

For starters just curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-arm64 (remove the 64 if you need the 32bit version). After that just sudo install minikube-linux-arm64 /usr/local/bin/minikube (again remove the 64 if you downloaded the 32bit version.

Start Minikube

To start minikube we need to run it with the none driver since the docker driver is not ready yet. What's the difference? The docker driver specifies to minikube to use its own embedded Docker daemon service, with none driver instead of you just tell to minikube to use your hosted Docker daemon service, this is why you needed to install docker before anything else (as you've read above).

For starters: sudo minikube start --vm-driver=none and then you have to wait sometime to get your Kubernetes bootstrapped. When done you should get a message like this:

When using the none driver, the kubectl config and credentials generated will be root-owned and will appear in the root home directory.
You will need to move the files to the appropriate location and then set the correct permissions.  An example of this is below:
 sudo mv /root/.kube $HOME/.kube # this will write over any previous configuration
 sudo chown -R $USER $HOME/.kube
 sudo chgrp -R $USER $HOME/.kube
 
 sudo mv /root/.minikube $HOME/.minikube # this will write over any previous configuration
 sudo chown -R $USER $HOME/.minikube
 sudo chgrp -R $USER $HOME/.minikube

Well before doing anything explained above, you have to stop minikube: sudo minikube stop. Then move from root the hidden folders .kube and .minikube to yours, then change owner and group like explained in the message.

If everything is fine and before to run minikube again, it's better to delete the old node instance (since it's all configured with root settings) with just: minikube delete (yep, no sudo this time). Then you should be able to run minikube start --vm-driver=none w/o sudo.

Side note: for some reason when you reboot your Raspberry, it's not possible to start minikube again, you forced to delete the node with minikube delete and then minikube start --vm-driver=none. Maybe I missed something when I can get why such thing happens I will update the GIST.

Test Minikube

The official guide suggests testing the service by using echoserver however an ARM64 build for it is not still ready, hence it's better to create a deployment with a whoami service.

# kubectl create deployment whoami --image=containous/whoami

it's also possible to write it as follow:

# minikube kubectl -- create deployment whoami --image=containous/whoami

but there's no difference, so it's up to you what you prefer.

After a while you can then expose the service:

# kubectl expose deployment whoami --type=LoadBalancer --port=80
service/whoami exposed

To check the exposed port you can just:

# minikube service whoami
|-----------|--------|-------------|---------------------------|
| NAMESPACE |  NAME  | TARGET PORT |            URL            |
|-----------|--------|-------------|---------------------------|
| default   | whoami |          80 | http://192.168.1.54:32456 |
|-----------|--------|-------------|---------------------------|

Eventually:

# curl -X GET http://192.168.1.54:32456
Hostname: whoami-734d555321-7fxw5
IP: 127.0.0.1
IP: 172.17.0.3
RemoteAddr: 172.17.0.1:2346
GET / HTTP/1.1
Host: 192.168.1.54:32456
User-Agent: curl/7.68.0
Accept: */*

Source > https://www.grottedubarbu.fr/raspberry-4-minikube-ubuntu-arm64/

@codelinx
Copy link

codelinx commented Feb 22, 2023

On the latest install of Kubernetes v1.26.1 i had to do some additional steps:


Some issues i ran into were:
Error on minikube start:

  • "HOST_JUJU_LOCK_PERMISSION" -> possible fixed with sudo sysctl fs.protected_regular=0
  • "unable to disable preinstalled bridge CNI(s): failed to disable all bridge cni configs in "/etc/cni/net.d" -> possible fix installing kubectl, kubelet, kuebadm via "Debian-based distributions"
  • After start check the status of your cluster you may have to run "minikube update-context" if you see output like:
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Misconfigured *<--------------

@cristisulighetean
Copy link

Hi, arkade just updated their link and now the current one does not work. This is the new one posted in their documentation.

curl -sLS https://get.arkade.dev | sudo sh

Thanks for the Minikube guide!

@lucaguada
Copy link
Author

@cristisulighetean thank you for your contribution! 👍

@codelinx sorry for the late reply, I will try to update the guide one day 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment