Adding Wifi on Raspberry Pi Running Kubernetes

Updating the Kubernetes cluster to use wifi

kubernetes plus raspberrypi

Unlike typical home offices I had recently came in to a power issue. With every new piece of equipment I added it eventually needed to be powered. So taking a look at what I had just to try to find something to get rid of.

The answer came down to the small switch I bought for my original cloud project Kubernetes Running on Raspberry Pi. Looking at it the switch was really not needed and I could have saved a few buck on it because my Pis all have a static IP address. This brings up a few things. First to be portable I am going to have to address a mobile way of assigning static IP addresses. Logging in locally to set the networking up is going to be a nightmare. So for the time being this portable cloud is going to be grounded in my office.

This still doesn’t address my current issue, where my desk is and with everything around it, I am out of plugs. That is where we jump back in to my Kubernetes Running on Raspberry Pi project. Looking again at the specs of the Raspberry Pi 4 they have a wifi card built in. And to be perfectly honest I didn’t even look at that. I was more concerned about the memory and processing speed. So for those who followed my original write up sorry for over looking this and you going out to buy the NETGEAR 5-Port Gigabit Ethernet Unmanaged Switch (GS305) - Desktop, Sturdy Metal Fanless Housing.

This get’s us in to our topic wifi enabling your Kubernetes cluster running on Raspberry Pi 4s. For a refresher we are using Ubuntu 19.10 and that means we are using Netplan. For those of you who don’t know Netplan is the networking interface written and supported by Canonical. It’s nice, clean and easy to set up if you are used to writing yaml files.

Back in Installing Ubuntu 19.10 on Raspberry Pi I walked you through setting up the static ip for each of your raspberries. Looked something like this:

network:
    ethernets:
        eth0:
            addresses: [192.168.1.5x/24] # note the x here is supposed to be a 
            gateway4: 192.168.1.1
            nameservers:
              addresses: [8.8.8.8,8.8.4.4]
            dhcp4: no
    version: 2

This is the set up for doing the ethernet and we did this on all of the Raspberries. So let’s fire up our cluster if you don’t have it running and set up some static wifis. We can SSH in to each of these Raspberries but realize we are going to use the sudo netplan try command that will kill off the connection, but if you write perfect yaml the first time a simple reboot is all you need. That being said you might want to break out the monitor and keyboard just incase.

First let’s find out the name of the wifi device on each raspberry:

ip a

And that should give you an output looking something like this:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.x/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 x::x:x:x:x/64 scope link
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether x:x:x:x:x:x brd ff:ff:ff:ff:ff:ff

What we are looking for is the wlan0 that is the name of our wifi card. Let’s open up our Netplan configuration.

sudo nano /etc/netplan/50-cloud-init.yaml

This should look something like the following:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        eth0:
            addresses: [192.168.1.x/24] # note the x here is supposed to be a number I masked it in my example
            gateway4: 192.168.1.1
            nameservers:
              addresses: [8.8.8.8,8.8.4.4]
            dhcp4: no
    version: 2

What we need to add to it is the following:

    wifis:
        wlan0:
            dhcp4: no
            dhcp6: no
            addresses: [192.168.1.5x/24] # note the x here is supposed to be a number I masked it in my example
            gateway4: 192.168.1.1
            nameservers:
              addresses: [8.8.8.8,8.8.4.4]
            access-points:
              "network_ssid":
                password: "xxxxxxxxxxxxxxxxxx"

Now I set the same ip address for both ethernet and wifi, both are static. At the end your configuration should look something like so:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        eth0:
            addresses: [192.168.1.5x/24] # note the x here is supposed to be a number I masked it in my example
            gateway4: 192.168.1.1
            nameservers:
              addresses: [8.8.8.8,8.8.4.4]
            dhcp4: no
    wifis:
        wlan0:
            dhcp4: no
            dhcp6: no
            addresses: [192.168.1.5x/24] # note the x here is supposed to be a number I masked it in my example
            gateway4: 192.168.1.1
            nameservers:
              addresses: [8.8.8.8,8.8.4.4]
            access-points:
              "network_ssid":
                password: "xxxxxxxxxxxxxxxxxx"
    version: 2

Because a sudo netplan try will boot you off of the ssh, I just did reboots on each checked the router and made sure the static ip address was there after I disconnected the ethernet cables.

NOTE: you will have to do this for each of your Raspberries.