{"id":769,"date":"2020-08-06T15:27:00","date_gmt":"2020-08-06T15:27:00","guid":{"rendered":"https:\/\/www.geekmungus.co.uk\/?p=769"},"modified":"2022-11-05T10:53:18","modified_gmt":"2022-11-05T10:53:18","slug":"microk8s-kubernetes-raspberry-pi-ubuntu-linux-basic-setup-guide-part-3-further-tasks","status":"publish","type":"post","link":"https:\/\/geekmungus.co.uk\/?p=769","title":{"rendered":"MicroK8s (Kubernetes) &#8211; Raspberry Pi Ubuntu Linux Basic Setup Guide &#8211; Part 3 (Further Tasks)"},"content":{"rendered":"\n<p>Well Part 2 was very long, so lets have a shorter one and cover how you can adjust your application on the fly and add the other worker nodes to the cluster.<\/p>\n\n\n\n<p><strong>Updating an Application or Service on the Fly<\/strong><\/p>\n\n\n\n<p>Kubernetes is a system whereby you declare what you want the \u201cworld\u201d to look like, if you make a change to the file you can then say I want the \u201cworld\u201d to look like this now, and Kubernetes will adjust the \u201cworld\u201d to look like that.<\/p>\n\n\n\n<p>Let\u2019s change the service file so we\u2019re adverting the port on 8080 rather than 8000, change the service.yaml file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: v1\n\nkind: Service\n\nmetadata:\n\n  name: hello-python-service\n\nspec:\n\n  selector:\n\n    app: hello-python\n\n  ports:\n\n  - port: 8080\n\n    targetPort: 5000\n\n  type: LoadBalancer<\/code><\/pre>\n\n\n\n<p>Then apply the changes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microk8s kubectl apply -f service.yaml<\/code><\/pre>\n\n\n\n<p>And run a:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microk8s kubectl get services<\/code><\/pre>\n\n\n\n<p>And as you can see, its now on port 8080.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@k8s-master:\/home\/ubuntu\/application\/hello-python\/app# kubectl get services\n\nNAME                         TYPE           CLUSTER-IP       EXTERNAL-IP    PORT(S)          AGE\n\nhello-python-service         LoadBalancer   10.152.183.34    192.168.1.20   8080:30740\/TCP   37h\n\nkubernetes                   ClusterIP      10.152.183.1     &lt;none>         443\/TCP          38h<\/code><\/pre>\n\n\n\n<p>Now go to http:\/\/192.168.1.20:8080, and you\u2019ll find that is now where the site is accessible from.<\/p>\n\n\n\n<p><strong>Adding a Worker Nodes to the Cluster<\/strong><\/p>\n\n\n\n<p>So currently we only have a single node within the cluster (the master node). We want to add some more nodes to act as worker nodes, we\u2019ll call these k8s-worker-01 and k8s-worker-02. Once you have them built and on the network, we can then continue with adding them into the Microk8s cluster.<\/p>\n\n\n\n<p>First we need to install microk8s on each of the two new worker nodes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>snap install microk8s --classic<\/code><\/pre>\n\n\n\n<p>Once installed on all the nodes,you now need to run this command on our master node (k8s-master).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microk8s.add-node<\/code><\/pre>\n\n\n\n<p>You&#8217;ll see a token on the screen, make a note of this, you&#8217;ll need it for the next worker nodes, so lets logon to each worker node and run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microk8s.join &lt;master_ip>:&lt;port>\/&lt;token><\/code><\/pre>\n\n\n\n<p>You may also need to enable your firewall rules and exceptions on the Master and all the Worker nodes to allow communication to work properly.<\/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>Now let\u2019s take a look at our new 3 node cluster with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microk8s kubectl get nodes\n\nroot@k8s-master:\/home\/ubuntu\/application\/hello-python\/app# microk8s kubectl get nodes\n\nNAME            STATUS     ROLES    AGE   VERSION\n\nk8s-master      Ready      &lt;none>   38h   v1.18.6-1+b4f4cb0b7fe3c1\n\nk8s-worker-01   NotReady   &lt;none>   66s   v1.18.6-1+b4f4cb0b7fe3c1\n\nk8s-worker-02   NotReady   &lt;none>   7s    v1.18.6-1+b4f4cb0b7fe3c1<\/code><\/pre>\n\n\n\n<p>After a few minutes, all being well you should see:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@k8s-master:\/home\/ubuntu\/application\/hello-python\/app# microk8s kubectl get nodes\n\nNAME            STATUS   ROLES    AGE   VERSION\n\nk8s-master      Ready    &lt;none>   38h   v1.18.6-1+b4f4cb0b7fe3c1\n\nk8s-worker-01   Ready    &lt;none>   11m   v1.18.6-1+b4f4cb0b7fe3c1\n\nk8s-worker-02   Ready    &lt;none>   10m   v1.18.6-1+b4f4cb0b7fe3c1<\/code><\/pre>\n\n\n\n<p>Our 3 node cluster is now ready for action. Now when we deploy applications we will find the pods spreading out across all the available nodes.<\/p>\n\n\n\n<p>For now go and redeploy the application from Part 2, and see what happens when you run the below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>microk8s kubectl get pods -o wide<\/code><\/pre>\n\n\n\n<p>What do you notice about the column reporting the host node for the pod?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well Part 2 was very long, so lets have a shorter one and cover how you can adjust your application on the fly and add the other worker nodes to the cluster. Updating an Application or Service on the Fly Kubernetes is a system whereby you declare what you want the \u201cworld\u201d to look like, &#8230; <a title=\"MicroK8s (Kubernetes) &#8211; Raspberry Pi Ubuntu Linux Basic Setup Guide &#8211; Part 3 (Further Tasks)\" class=\"read-more\" href=\"https:\/\/geekmungus.co.uk\/?p=769\" aria-label=\"Read more about MicroK8s (Kubernetes) &#8211; Raspberry Pi Ubuntu Linux Basic Setup Guide &#8211; Part 3 (Further Tasks)\">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-769","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\/769","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=769"}],"version-history":[{"count":1,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/769\/revisions"}],"predecessor-version":[{"id":1378,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/769\/revisions\/1378"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/"}],"wp:attachment":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}