{"id":3151,"date":"2024-04-11T12:37:17","date_gmt":"2024-04-11T16:37:17","guid":{"rendered":"https:\/\/dft.wiki\/?p=3151"},"modified":"2026-06-08T10:40:31","modified_gmt":"2026-06-08T14:40:31","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 Canonical&#8217;s <span style=\"text-decoration: underline;\">single-package fully conformant<\/span> lightweight Kubernetes [<a href=\"https:\/\/github.com\/canonical\/microk8s\">Link<\/a>]. It is a 100% compatible Kubernetes orchestrator that can be deployed with a single click on Ubuntu and many other distributions via Snap.<\/p>\n<p>Compared to <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-grade Kubernetes with a low operational overhead (low-ops).<\/p>\n<p><strong>Kubernetes<\/strong> was built by Google to meet Google-scale demands, which is why it is widely known to be complex to deploy and manage. This leads many companies to opt for managed services such as <strong>EKS<\/strong> (AWS), <strong>GKE<\/strong> (GCP), or <strong>AKS<\/strong> (Azure), all of which come with an associated cost.<\/p>\n<p>Most container orchestration use cases are straightforward, and <strong>MicroK8s<\/strong> handles them well.<\/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 MicroK8s daemon.<\/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>For standard Kubernetes commands and use cases, see this reference post [<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. To extend it, optionally specify a namespace and duration.<\/p>\n<pre>sudo microk8s kubectl create token default --namespace=<strong>namespace<\/strong> --duration=<strong>24h<\/strong><\/pre>\n<p>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 the 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 to MicroK8s. It is a standard Kubernetes module and is outside the scope of this post. See the Dashboard walkthrough post [<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 &#8220;unprivileged&#8221; option.<\/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, 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>Start the CT and add the following line to the root user&#8217;s crontab.<\/p>\n<pre>crontab -e<\/pre>\n<pre>@reboot ln -s \/dev\/console \/dev\/kmsg<\/pre>\n<p>Set up 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 install MicroK8s.<\/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, verify everything is 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 its 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 Canonical&#8217;s single-package fully conformant lightweight Kubernetes [Link]. It is a 100% compatible Kubernetes [&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":19,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/3151\/revisions"}],"predecessor-version":[{"id":5625,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/3151\/revisions\/5625"}],"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}]}}