Introduction to MicroK8s

MicroK8s is the smallest, fastest, fully-conformant Kubernetes that tracks upstream releases and makes clustering trivial. MicroK8s is great for offline development, prototyping, and testing. Use it on a VM as a small, cheap, reliable k8s for CI/CD. It’s also the best production grade Kubernetes for appliances. Develop IoT apps for k8s and deploy them to MicroK8s on your Linux boxes.

We’re hiring!: Fancy working with MicroK8s as a full-time job? Check out the role here!

What you’ll need

  • An Ubuntu 20.04 LTS, 18.04 LTS or 16.04 LTS environment to run the commands (or another operating system which supports snapd - see the snapd documentation)
  • At least 20G of disk space and 4G of memory are recommended
  • An internet connection

Note: If you don’t meet these requirements, there are additional ways of installing MicroK8s, including additional OS support and an offline deploy. See the alternative install page for details.

  1. Install MicroK8s

    MicroK8s will install a minimal, lightweight Kubernetes you can run and use on practically any machine. It can be installed with a snap:

    sudo snap install microk8s --classic --channel=1.21
    

    More about setting the channel

  2. Join the group

    MicroK8s creates a group to enable seamless usage of commands which require admin privilege. To add your current user to the group and gain access to the .kube caching directory, run the following two commands:

    sudo usermod -a -G microk8s $USER
    sudo chown -f -R $USER ~/.kube

    You will also need to re-enter the session for the group update to take place:

    su - $USER

  3. Check the status

    MicroK8s has a built-in command to display its status. During installation you can use the --wait-ready flag to wait for the Kubernetes services to initialise:

    microk8s status --wait-ready

  4. Access Kubernetes

    MicroK8s bundles its own version of kubectl for accessing Kubernetes. Use it to run commands to monitor and control your Kubernetes. For example, to view your node:

    microk8s kubectl get nodes

    …or to see the running services:

    microk8s kubectl get services

    MicroK8s uses a namespaced kubectl command to prevent conflicts with any existing installs of kubectl. If you don’t have an existing install, it is easier to add an alias (append to ~/.bash_aliases) like this:

    alias kubectl='microk8s kubectl'

  5. Deploy an app

    Of course, Kubernetes is meant for deploying apps and services. You can use the kubectl command to do that as with any Kuberenetes. Try installing a demo app:

    microk8s kubectl create deployment nginx --image=nginx

    It may take a minute or two to install, but you can check the status:

    microk8s kubectl get pods

  6. Use add-ons

    MicroK8s uses the minimum of components for a pure, lightweight Kubernetes. However, plenty of extra features are available with a few keystrokes using “add-ons” - pre-packaged components that will provide extra capabilities for your Kubernetes, from simple DNS management to machine learning with Kubeflow!

    To start it is recommended to add DNS management to facilitate communication between services. For applications which need storage, the ‘storage’ add-on provides directory space on the host. These are easy to set up:

    microk8s enable dns storage

    See the full list of addons

  7. Starting and Stopping MicroK8s

    MicroK8s will continue running until you decide to stop it. You can stop and start MicroK8s with these simple commands:

    microk8s stop

    … will stop MicroK8s and its services. You can start again any time by running:

    microk8s start

    Note that if you leave MicroK8s running, it will automatically restart after a reboot. If you don’t want this to happen, simply remember to run microk8s stop before you power down.

Next steps

Navigation

Navigation
Level Path Navlink
0 Install
1 / Getting started
1 install-alternatives Alternative install methods
2 install-alternatives#heading–windows Windows10
2 install-alternatives#heading–macos macOS
2 install-alternatives#heading–arm Raspberry PI/ARM
2 install-alternatives#heading–offline Offline installs
1 lxd LXD
1 install-proxy Behind a proxy
1 setting-snap-channel Channels and versions
1 upgrading Upgrading
0 Add-ons
1 addons Enabling and disabling
2 addons#heading–list Available add-ons
2 addon-ambassador ambassador
2 addon-dashboard dashboard
2 addon-dns dns
2 addon-fluentd fluentd
2 addon-gpu gpu
2 addon-host-access host-access
2 addon-inaccel inaccel
2 addon-ingress ingress
2 addon-kata kata
2 addon-keda keda
2 addon-kubeflow kubeflow
2 addon-linkerd linkerd
2 addon-metallb metallb
2 addon-multus multus
2 addon-openfaas openfaas
2 addon-openebs openebs
2 addon-portainer portainer
2 addon-traefik traefik
0 Additional configuration
1 high-availability High Availability
1 configuring-services Configuring services
1 clustering Multi-node cluster
1 ports#heading–auth Authentication and authorization
1 external-lma Adding an LMA stack
1 multi-user Multi-user setup
1 change-cidr Changing the pod CIDR
1 add-a-windows-worker-node-to-microk8s Adding Windows workers
0 Images and registries
1 registry-images Using local images
1 registry-public Using a public registry
1 registry-built-in Using the built-in registry
1 registry-private Using a private registry
0 Troubleshooting
1 troubleshooting How to diagnose problems
1 troubleshooting#heading–inspect Using microk8s.inspect
1 troubleshooting#heading–common-issues Common issues
1 troubleshooting#heading–report-bug Reporting a bug
0 Reference
1 release-notes Release notes
1 command-reference Command reference
1 services-and-ports Services and ports used
1 working-with-kubectl Working with kubectl
1 get-in-touch Get in touch
1 docs/docs Contributing to docs

Redirects

Mapping table
Path Location
1 Like

Hello - I would recommend updating the docs to indicate that installing operator lifecycle manager requires the rbac add-on. Without the rbac addon the OLM CSV never succeeds.

Hey guys. Who/which forum can I ask the following question.

Would it be appropriate to use mircoK8s for a production standalone server ?

Cheers,
Nate

Hi @intyig20,

Yes, MicroK8s is perfectly fine for a production server.

You can post questions on this forum and tag them with MicroK8s so we get notified.

Thanks

Hi,

I’m new to microk8s and kubernetes, I started to read the doc yesterday and I may have spotted a problem :
In the fifth step (deploy an app), the command : microk8s kubectl create deployment return an error (Error: required flag(s) “image” not set).
I didn’t understand the error at first, but after going through other docs I came to understand that it’s incomplete, we should have something like this : microk8s kubectl create deployment nginx --image=nginx

Maybe the doc could be updated with a compete deployment command with a demo app or something, as it could be difficult to overcome for absolute beginners.

Thanks

I have seen this statement in the blog as well :

What is MicroK8s?

MicroK8s is a powerful, lightweight, reliable production-ready Kubernetes distribution.

And in the home of microk8s.io:

High availability K8s New

Low-ops, minimal production Kubernetes,
for devs, cloud, clusters, workstations, Edge and IoT.

but it’s not in the headline of this category:

Is there a reason that the official docs keeps a low-profile if it’s in fact considered production ready?

Can we put a note on here about the limitations of storage. The add-on only works with a single node. Not clusters, at least not very well once you get into more complex stuff.

please add a completely working example of how to use microk8s in production
now I run this commands in a new server before begin deploy apps
sudo snap install microk8s --classic
microk8s enable dashboard dns registry ingress metrics-server storage
microk8s kubectl create namespace cert-manager
microk8s kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.26.1/deploy/static/mandatory.yaml
microk8s kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.26.1/deploy/static/provider/cloud-generic.yaml
microk8s kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v0.12.0/cert-manager.yaml
microk8s kubectl get pods --namespace cert-manager

Thanks for your use case. We may be doing some work to tidy up ‘default’ add-ons which will be automatically added which will make it easier to manage deploys. Beyond that, MicroK8s remains adaptable to the user’s needs, so there isn’t a set way to create a production deployment, although I take your point that we could add examples.

Hi, I am new to kubernets and Microk8s. I created an VM in ubuntu(18.0) and installed microk8s. I using add-ons called metallb also enabled the metallb add-on. the kubeconfig yaml file is getting created, but the problem the server address is my NAT address, its not allocating the mentioned ip address for the load-balancer. so its not accessible external address. Any help why this is happening. ?.

thank you

when you say

can you add any details - is this Virtual Box, LXD? What is the host OS?

Hi, its the virtual box. and the os is linux. I also face other error. the connection to the server localhost:8080 was refused - did you specify the right host or port?. When I searched on this error its mentioned kubectl file would not have been present . so I tried to run the following command.

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
but admin.conf file is not present. Not sure how to get it

In VirtualBox, did you set the Network to Bridged Networking?

If you are running in Linux, it is probably easier to follow the LXD install instructions - will run faster and use fewer resources