Get started

What you’ll need

  • An Ubuntu 22.04 LTS, 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). If you don’t have a Linux machine, you can use Multipass (see Installing MicroK8s with Multipass).
  • MicroK8s runs in as little as 540MB of memory, but to accommodate workloads, we recommend a system with at least 20G of disk space and 4G of memory.
  • 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.31
    

    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 three commands:

    sudo usermod -a -G microk8s $USER
    mkdir -p ~/.kube
    chmod 0700 ~/.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 Kubernetes. 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 ‘hostpath-storage’ add-on provides directory space on the host. These are easy to set up:

    microk8s enable dns
    microk8s enable hostpath-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

1 Like

this doesnt work
you missed microk8s start
you might want to test your docs before posting, these are really bad

The $HOME/.kube directory is empty, maybe it would be convenient to add this command to the instructions:

sudo microk8s kubectl config view --raw > $HOME/.kube/config

1 Like

Getting started step 2 does not always work

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

I experienced this several times, the ~/.kube directory did not exist at this point. I suggest to create the directory in case it does not exist before the chown:

sudo usermod -a -G microk8s $USER
sudo mkdir -p ~/.kube
sudo chown -f -R $USER ~/.kube
1 Like

thanks, added a step to create the dir if it doesn’t exist

There’s a typo in this part, it should be “Kubernetes”.

Edit: fixed it in the post :slight_smile:

Hi all, I have a rather stupid question for Microk8s deployment. I followed all the installation guides, including this one, on deployment. They all asked me to install Microk8s on my VPS under the root account with the command:

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

which went fine for me, and then

microk8s status --wait-ready

but it just hangs there doing nothing. when i checked with another SSH instance to the same VPS

microk8s status

it tells me Microk8s is not running.

when i entered

microk8s kubectl get nodes

It said the node weren’t ready.

I repeated the same commands on another VPS from a different cloud provider. Same outcome. What am I doing wrong? I am just a bit flummoxed that I got stuck in this very basic first step.

Running microk8s inspect told me

Inspecting system
Inspecting Certificates
Inspecting services
  Service snap.microk8s.daemon-cluster-agent is running
  Service snap.microk8s.daemon-containerd is running
  Service snap.microk8s.daemon-kubelite is running
  Service snap.microk8s.daemon-k8s-dqlite is running
  Service snap.microk8s.daemon-apiserver-kicker is running
  Copy service arguments to the final report tarball
Inspecting AppArmor configuration
Gathering system information
  Copy processes list to the final report tarball
  Copy disk usage information to the final report tarball
  Copy memory usage information to the final report tarball
  Copy server uptime to the final report tarball
  Copy openSSL information to the final report tarball
  Copy snap list to the final report tarball
  Copy VM name (or none) to the final report tarball
  Copy current linux distribution to the final report tarball
  Copy asnycio usage and limits to the final report tarball
  Copy inotify max_user_instances and max_user_watches to the final report tarball
  Copy network configuration to the final report tarball
Inspecting kubernetes cluster
  Inspect kubernetes cluster
Inspecting dqlite
  Inspect dqlite
cp: cannot stat '/var/snap/microk8s/6782/var/kubernetes/backend/localnode.yaml': No such file or directory

Am I supposed to do something about dqlite before starting Microk8s? And if so, what would those steps be since none of the guides mention this step?

Thanks all.

Those shouldn’t use sudo as the ~/.kube is meant to be created in $USER’s home and owned by $USER. It should also take care of restricting access to that dir that contains the security sensitive kube config file. Something like:

mkdir -p ~/.kube
chmod 0700 ~/.kube

yes it seems this got messed up in sequence due to someone else’s reported issue earlier in the thread.

Would be great to include this instruction into this “original” tutorial, so folks wouldn’t need to guess.

Another guess instead of this could be:
sudo cp /root/.kube/config $HOME/.kube/config
Is that also ok?

Also, in some tutorials, the command is:
microk8s kubectl config view --raw > ~/.kube/config,
in some it is:
microk8s config > ~/.kube/config.

There does not seem to be any differences in output, but it would be nice if you maintainers state if one or the other is to be preferred for some reason.

Tthink the thing that is confusing people is you do not need to use the kubeconfig file if you are using the built-in version of kubectl. It is only if you want to use an existing one. that’s why originally there was no mkdir command (because if you had kubectl installed already it would exist). I’m very reluctant to give people commands that could destroy any configuration they already have

Hi @evilnick , since I can’t edit this page, here’s my suggested improvement:

1 Like

Hi,

@evilnick Hi! :wave: A few comments for this page (great doc by the way). Right above What you’ll need, can we get a summary of its objective? Like “At the end of this tutorial you will have a working one-node Kubernetes cluster” or “The purpose of this tutorial is to…”. Maybe there are other things to mention too. I’m not sure.

There is a recommendation to enable the dns add-on. My install had it enabled by default:

sudo snap install microk8s --classic --channel=1.31
2024-10-20T01:51:30Z INFO Waiting for automatic snapd restart...
microk8s (1.31/stable) v1.31.1 from Canonical✓ installed
microk8s status --wait-ready
microk8s is running
high-availability: no
  datastore master nodes: 127.0.0.1:19001
  datastore standby nodes: none
addons:
  enabled:
    dns                  # (core) CoreDNS

Hope this helps! :pie:
Peter