{"id":3151,"date":"2024-04-11T12:37:17","date_gmt":"2024-04-11T16:37:17","guid":{"rendered":"https:\/\/dft.wiki\/?p=3151"},"modified":"2024-09-08T09:58:46","modified_gmt":"2024-09-08T13:58:46","slug":"microk8s-the-out-of-the-box-kubernetes-of-ubuntu","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=3151","title":{"rendered":"MicroK8S, the Out-of-the-box Kubernetes of Ubuntu"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4097\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/MicroK8s.png\" alt=\"\" width=\"527\" height=\"168\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/MicroK8s.png 527w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/MicroK8s-300x96.png 300w\" sizes=\"auto, (max-width: 527px) 100vw, 527px\" \/><\/p>\n<p><strong>MicroK8s<\/strong> is the Canonical <span style=\"text-decoration: underline;\">single-package fully conformant<\/span> lightweight Kubernetes [<a href=\"https:\/\/github.com\/canonical\/microk8s\">Link<\/a>]. It means, it is a 100% compatible Kubernetes orchestrator that can be deployed with a &#8220;single-click&#8221; on Ubuntu and many other distributions via Snap.<\/p>\n<p>When compared with <strong>MiniKube<\/strong> [<a href=\"https:\/\/dft.wiki\/?p=3087\">Link<\/a>] and <strong>K3s<\/strong> [<a href=\"https:\/\/dft.wiki\/?p=3105\">Link<\/a>], <strong>MicroK8s<\/strong> is a minimal production Kubernetes that offers with the minimal effort for operating (low-ops).<\/p>\n<p><strong>Kubernetes<\/strong> is a beast created by Google to meet Google needs of scalability, that is why it is a common knowledge that Kubernetes is Hard to deploy and manage. This makes many companies opt for managed services such as <strong>EKS<\/strong> (from AWS), <strong>GKE<\/strong> (from GCP), or <strong>AKS<\/strong> (from Azure). And that comes with an associated price tag.<\/p>\n<p>Most of the use cases for orchestrating clusters of containers are very simple and <strong>MicroK8s<\/strong> suits these requirements by far.<\/p>\n<hr \/>\n<p><strong>INSTALLATION<\/strong><\/p>\n<pre>sudo snap install microk8s --classic\r\nmicrok8s.inspect<\/pre>\n<p><strong>That is it!<\/strong> Even <code>kubectl<\/code> is included in the package.<\/p>\n<p>To use MicroK8s without <code>sudo<\/code>,add your username to the <code>microk8s<\/code> group.<\/p>\n<pre>sudo usermod -a -G microk8s userName<\/pre>\n<p>Stopping and starting the\u00a0 MicroK8s Deamon.<\/p>\n<pre>microk8s.stop\r\nmicrok8s.start<\/pre>\n<hr \/>\n<p><strong>BASIC COMMANDS<\/strong><\/p>\n<pre>sudo microk8s kubectl get nodes\r\nsudo microk8s kubectl get services<\/pre>\n<p>To avoid repetition, here is another post that show cases standard Kubernetes commands and use cases [<a href=\"https:\/\/dft.wiki\/?p=1372\">Link<\/a>].<\/p>\n<hr \/>\n<p><strong>EXTENDED FEATURES<\/strong><\/p>\n<p>Enabling popular Addons.<\/p>\n<pre>sudo microk8s enable dashboard\r\nsudo microk8s enable registry\r\nsudo microk8s enable ingress\r\nsudo microk8s enable dns\r\nsudo microk8s enable gpu\r\nsudo microk8s enable ha-cluster\r\nsudo microk8s enable cert-manager\r\nsudo microk8s enable prometheus\r\nsudo microk8s enable community\r\nsudo microk8s enable istio<\/pre>\n<hr \/>\n<p><strong>ACCESSING THE DASHBOARD<\/strong><\/p>\n<pre>sudo microk8s enable dashboard\r\nsudo microk8s kubectl create token default<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4109\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-16-31.png\" alt=\"\" width=\"638\" height=\"216\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-16-31.png 638w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-16-31-300x102.png 300w\" sizes=\"auto, (max-width: 638px) 100vw, 638px\" \/><\/p>\n<p>By default, the token expires in 1 hour. If necessary, give it more time or add the namespace:<\/p>\n<pre>sudo microk8s kubectl create token default --namespace=<strong>namespace<\/strong> --duration=<strong>24h<\/strong><\/pre>\n<p>Now, expose the dashboard.<\/p>\n<pre>sudo microk8s kubectl port-forward -n kube-system service\/kubernetes-dashboard 10443:443<\/pre>\n<p>Navigate to <a href=\"https:\/\/127.0.0.1:10443\/\">https:\/\/127.0.0.1:10443<\/a> and paste generated token:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4110\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-19-59.png\" alt=\"\" width=\"1143\" height=\"836\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-19-59.png 1143w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-19-59-300x219.png 300w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-19-59-1024x749.png 1024w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-19-59-768x562.png 768w\" sizes=\"auto, (max-width: 1143px) 100vw, 1143px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4111\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-20-12.png\" alt=\"\" width=\"1143\" height=\"836\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-20-12.png 1143w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-20-12-300x219.png 300w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-20-12-1024x749.png 1024w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-04-12-12-20-12-768x562.png 768w\" sizes=\"auto, (max-width: 1143px) 100vw, 1143px\" \/><\/p>\n<p><strong> Note:<\/strong> this dashboard is not specific from MicroK8s. Instead, it is a Kubernetes module and is not in the scope of this post to walk-through the Dashboard. Check our the Dashboard Walk-through post at [<a href=\"https:\/\/dft.wiki\/?p=4114\">Link<\/a>].<\/p>\n<hr \/>\n<p><strong>RUNNING MICROK8S IN PROXMOX LXC<\/strong><\/p>\n<p>Create a new CT and uncheck the option for &#8220;unprivileged&#8221;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4417\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-09-07-12-40-40.png\" alt=\"\" width=\"722\" height=\"281\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-09-07-12-40-40.png 722w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2024\/04\/Screenshot-from-2024-09-07-12-40-40-300x117.png 300w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><\/p>\n<p>Before starting the CT for the first time, on open a shell on the host and edit the CT configuration file.<\/p>\n<pre>nano \/etc\/pve\/nodes\/proxmox\/lxc\/100.conf<\/pre>\n<pre>lxc.apparmor.profile: unconfined\r\nlxc.cap.drop:\r\nlxc.mount.auto: proc:rw sys:rw\r\nlxc.mount.entry: \/dev\/fuse dev\/fuse none bind,create=file 0 0\r\nlxc.mount.entry: \/sys\/kernel\/security sys\/kernel\/security none bind,create=file 0 0<\/pre>\n<p>Then, start the CT and add the following line to the crontab of the root user.<\/p>\n<pre>crontab -e<\/pre>\n<pre>@reboot ln -s \/dev\/console \/dev\/kmsg<\/pre>\n<p>Setup the environment.<\/p>\n<pre>ln -s \/dev\/console \/dev\/kmsg\r\napt update &amp;&amp; apt upgrade -y\r\napt install snapd squashfuse fuse -y\r\nreboot<\/pre>\n<p>Now, the installation can happen.<\/p>\n<pre>snap install microk8s --classic\r\napparmor_parser --add \/var\/lib\/snapd\/apparmor\/profiles\/snap.microk8s.*\r\nmicrok8s.inspect\r\nreboot<\/pre>\n<p>After rebooting, check if it is still working as expected.<\/p>\n<pre>microk8s.inspect\r\nmicrok8s kubectl get nodes\r\nmicrok8s kubectl get services\r\n<\/pre>\n<hr \/>\n<p><strong>BONUS<\/strong><\/p>\n<p>Auto-start <strong>Microk8s<\/strong> and it&#8217;s the dashboard on startup.<\/p>\n<pre>nano \/etc\/systemd\/system\/kubectl.service<\/pre>\n<pre>[Unit]\r\nDescription=Port forward for Kubernetes Dashboard\r\nAfter=network.target\r\n\r\n[Service]\r\nExecStart=\/root\/microk8s.sh\r\nRestart=always\r\nUser=root\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\n<pre>nano \/root\/microk8s.sh\r\nchmod +x \/root\/microk8s.sh<\/pre>\n<pre>#!\/bin\/bash\r\napparmor_parser --add \/var\/lib\/snapd\/apparmor\/profiles\/snap.microk8s.*\r\nmicrok8s.start\r\nsleep 30\r\n\/snap\/bin\/microk8s kubectl port-forward -n kube-system service\/kubernetes-dashboard 10443:443 --address 0.0.0.0<\/pre>\n<pre>systemctl daemon-reload\r\nsystemctl enable kubectl --now<\/pre>\n<hr \/>\n<p><strong>OTHER POSTS<\/strong><\/p>\n<p><strong>Minikube<\/strong> on Ubuntu 22.04 [<a href=\"https:\/\/dft.wiki\/?p=3087\">Link<\/a>].<\/p>\n<p><strong>K3s<\/strong> on Ubuntu 22.04 [<a href=\"https:\/\/dft.wiki\/?p=3105\">Link<\/a>].<\/p>\n<p><strong>K8s<\/strong> Persistent Volumes [<a href=\"https:\/\/dft.wiki\/?p=1435\">Link<\/a>].<\/p>\n<p><strong>K8s<\/strong> Cheat Sheet [<a href=\"https:\/\/dft.wiki\/?p=1372\">Link<\/a>].<\/p>\n<p><strong>K8s<\/strong> Dashboard [<a href=\"https:\/\/dft.wiki\/?p=4114\">Link<\/a>].<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MicroK8s is the Canonical single-package fully conformant lightweight Kubernetes [Link]. It means, it is a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-3151","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/3151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3151"}],"version-history":[{"count":18,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/3151\/revisions"}],"predecessor-version":[{"id":4421,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/3151\/revisions\/4421"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}