{"id":761,"date":"2020-08-06T15:09:00","date_gmt":"2020-08-06T15:09:00","guid":{"rendered":"https:\/\/www.geekmungus.co.uk\/?p=761"},"modified":"2022-11-05T10:53:18","modified_gmt":"2022-11-05T10:53:18","slug":"microk8s-kubernetes-raspberry-pi-ubuntu-linux-basic-setup-guide-part-1-getting-started","status":"publish","type":"post","link":"https:\/\/geekmungus.co.uk\/?p=761","title":{"rendered":"MicroK8s (Kubernetes) &#8211; Raspberry Pi Ubuntu Linux Basic Setup Guide &#8211; Part 1 (Getting Started)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Kuberntes is a platform for the managing of containerised workloads and services, that is akin to a declarative infrastructure as code type platform. It allows developers to deploy containerised applications quickly and easily and in such a way that infrastructure system administrators can manage the infrastructure for the applications to be as adaptable and flexible as the applications require.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To avoid repeating what is already there read the<a href=\"https:\/\/kubernetes.io\/docs\/concepts\/overview\/what-is-kubernetes\/\" target=\"_blank\" rel=\"noreferrer noopener\"> <\/a><a href=\"https:\/\/kubernetes.io\/docs\/concepts\/overview\/what-is-kubernetes\/\" target=\"_blank\" rel=\"noreferrer noopener\">What is Kubernetes?<\/a> article on the Kubernetes website for more information.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, MicroK8s is a small easy to deploy version of Kubernetes and in this guide we&#8217;ll be installing it onto Raspberry Pi computers. You can install onto a single Raspberry Pi, but for this example we&#8217;ll be installing on 3 x Raspberry Pi 4&#8217;s with 2GB RAM each, 4GB is recommended but not essential.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Install Ubuntu 20.04 onto Raspberry Pi<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Firstly download the Ubuntu 20.04 Raspberry Pi image x64 version. Flash the image to the memory card, you\u2019ll need at least 16GB memory card, ideally 32GB, a tool like Rufus is ideal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Set Hostname<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once the device has booted, determine its IP address, normally the easiest way is to find this from your DHCP server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SSH to the device username: ubuntu, password: ubuntu, you&#8217;ll be prompted to change the password and then be disconnected. Reconnect via SSH using the new password you just set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Edit the hostname file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi \/etc\/hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Set the hostname as per one the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>k8s-master<\/li><li>k8s-worker-01<\/li><li>k8s-worker-02<\/li><li>k8s-worker-03<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Edit the hosts file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi \/etc\/hosts<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace the &#8220;127.0.0.1 localhost&#8221; line with the new hostname so: &#8220;172.0.0.1 k8s-master localhost&#8221; for example.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reboot the server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Set Timezone and NTP<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dpkg-reconfigure tzdata\n\nsudo timedatectl\n\ntimedatectl show-timesync<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.linuxuprising.com\/2019\/07\/how-to-set-timezone-and-enable-network.html\">https:\/\/www.linuxuprising.com\/2019\/07\/how-to-set-timezone-and-enable-network.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Perform Updates<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt update\n\napt upgrade\n\nreboot<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Preparation for Microk8s<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We need to configure the memory settings for Kubernetes to operate correctly, node this needs to be done to all the nodes that are going to run MicroK8s.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi \/boot\/firmware\/cmdline.txt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then at the end of the line add:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cgroup_enable=memory cgroup_memory=1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Reboot and repeat for each of your nodes if you&#8217;re setting up a cluster for MicroK8s.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Install MicroK8s<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the following on all nodes to install Microk8s:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>snap install microk8s --classic<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Once installed on all the nodes, run on the node you want to be master:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microk8s.add-node<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll see a token on the screen, make a note of this, you&#8217;ll need it for the next worker nodes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microk8s.join &lt;master_ip&gt;:&lt;port&gt;\/&lt;token&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You may also need to enable your firewall to allow communication:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow in on cni0 &amp;&amp; sudo ufw allow out on cni0\n\nsudo ufw default allow routed<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Enable Kubernetes Add-Ons<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We want to enable a load of add-ons, you can see which are enabled with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microk8s status<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Lets turn some things on, the main ones to explain are &#8220;storage&#8221; that gives you persistent volumes, &#8220;metallb&#8221; that provides a load balancer for accessing your pods services e.g. HTTPS, and the &#8220;registry&#8221; for the storage and management of images.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microk8s enable dns \n\nmicrok8s enable storage \n\nmicrok8s enable metallb (You\u2019ll be prompted for a range of IP addresses here, pick one on the same subnet as the Kubenetes nodes)\n\nmicrok8s enable ingress \n\nmicrok8s enable dashboard\n\nmicrok8s enable registry<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You may need to wait a while for all the pods to be created. You can check on progress with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microk8s kubectl get pods --all-namespaces -o wide<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When all are done then you are ready to continue to the next part.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/unsplash.com\/@guibolduc\" data-type=\"URL\" data-id=\"https:\/\/unsplash.com\/@guibolduc\" target=\"_blank\" rel=\"noreferrer noopener\">Image Attribution<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kuberntes is a platform for the managing of containerised workloads and services, that is akin to a declarative infrastructure as code type platform. It allows developers to deploy containerised applications quickly and easily and in such a way that infrastructure system administrators can manage the infrastructure for the applications to be as adaptable and flexible &#8230; <a title=\"MicroK8s (Kubernetes) &#8211; Raspberry Pi Ubuntu Linux Basic Setup Guide &#8211; Part 1 (Getting Started)\" class=\"read-more\" href=\"https:\/\/geekmungus.co.uk\/?p=761\" aria-label=\"Read more about MicroK8s (Kubernetes) &#8211; Raspberry Pi Ubuntu Linux Basic Setup Guide &#8211; Part 1 (Getting Started)\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":763,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,11],"tags":[],"class_list":["post-761","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kubernetes","category-linux"],"_links":{"self":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=761"}],"version-history":[{"count":1,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/761\/revisions"}],"predecessor-version":[{"id":1380,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/761\/revisions\/1380"}],"wp:attachment":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}