Command reference

MicroK8s adds the ‘microk8s’ command with a number of commands:

Addon helper commands

Some commands are specific to particular addons (e.g. microk8s cilium) and may not do anything useful if the respective addon is not currently enabled. For more information on these commands, see the Addon documentation.

  • microk8s cilium
  • microk8s helm
  • microk8s istioctl
  • microk8s linkerd

microk8s add-node

Usage: microk8s add-node

Options:

  • -l, -token-ttl TTL. Specify how long the token is valid in seconds, before it expires. Value of “-1” indicates that the token is usable only once (i.e. after joining a node, the token becomes invalid)

  • -t, --token TOKEN. Specify the bootstrap token to add, must be 32 characters long. Auto generates when empty.

Description:
Running this command will generate a connection string and output a list of suggested microk8s join commands to add an additional MicroK8s node to the current cluster.

Examples:

microk8s add-node

…will result in output similar to:

Join node with: microk8s join 192.168.0.2:25000/eLCTbltkDzxOnSKAkmVMbOPYgSrAieEl

If the node you are adding is not reachable through the default interface you can
use one of the following:
 microk8s join 192.168.0.2:25000/eLCTbltkDzxOnSKAkmVMbOPYgSrAieEl
 microk8s join 192.168.250.1:25000/eLCTbltkDzxOnSKAkmVMbOPYgSrAieEl
 microk8s join 10.57.200.1:25000/eLCTbltkDzxOnSKAkmVMbOPYgSrAieEl
 microk8s join 10.128.63.1:25000/eLCTbltkDzxOnSKAkmVMbOPYgSrAieEl
 microk8s join 172.17.0.1:25000/eLCTbltkDzxOnSKAkmVMbOPYgSrAieEl
 microk8s join 10.1.37.68:25000/eLCTbltkDzxOnSKAkmVMbOPYgSrAieEl
 microk8s join 192.168.122.1:25000/eLCTbltkDzxOnSKAkmVMbOPYgSrAieEl

microk8s config

Usage: microk8s config [-l]

Options:

  • -l, --use-loopback : Report the cluster address using the loopback
    address (127.0.0.1) rather than the default interface address.

Description:
Retrieves and outputs the current config information from MicroK8s (similar to that returned by kubectl).

Examples:

microk8s config

…will result in output similar to:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCRENDQWV5Z0F3SUJBZ0lKQVBQMGhoaFduTTR0T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SU9zZnR6SFF6SVA4NWRhOEsKWGptbVY2UzNLQnZtZlpKMU1WZzFuUFBGYnpBdVhoaXI0RmFvZ3AzL2lwNkVFdWtYNUYydnQvVDdSaC9XODFDNQphUFhpTDdSMTUxQm9aU3U2Y2ZUdGx2Y092cW9DSDFvaXlvWlJIV2dSeElPVTU2dXVuRXlUdVNoMjJnbGVSSlAyCk8xWk9rNEVBS3VNMEsra05SeEVvcXNmeFliYlZicENvbGVJRXlLUVhhNzJJU0RrdlVWRmhRMkxGZTJ1bmtvRDgKY2JZbVAxVU1tZ009Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
    server: https://192.168.0.2:16443
  name: microk8s-cluster
contexts:
- context:
    cluster: microk8s-cluster
    user: admin
  name: microk8s
current-context: microk8s
kind: Config
preferences: {}
users:
- name: admin
  user:
    username: admin
    password: S05BcnhqaWpCNzlRaWtDZEIzNHEzVU5qKzZCaERUbWxjQ2d6VTFmcjkrQT0K

microk8s dbctl

Usage: microk8s dbctl [-h] [--debug] {restore,backup}

Options:

-h, --help show this help message and exit
–debug print debug output

Sub-commands:
{restore,backup} backup and restore operations

Description:
Available on 1.19+ releases, this command allows for backing up and restoring the dqlite based MicroK8s datastore.

Examples:

  • To take a backup:

microk8s dbctl backup [-o backup-file]

The -o backup-file is optional. If not provided a backup file name using the current date and time will be produced.

  • To restore dqlite from backup:

microk8s dbctl restore <backup-file.tar.gz>

microk8s ctr

Usage: microk8s ctr [command]

Options:

  • any ctr command: see below

Description:
This command provides access to the containerd CLI command ctr. It is provided as a convenience, for more information on using ctr, please see the relevant manpage with man ctr or run the built-in help with microk8s ctr.

Examples:

microk8s ctr version

…will result in output similar to:

Client:
  Version:  v1.2.5
  Revision: bb71b10fd8f58240ca47fbb579b9d1028eea7c84

microk8s disable

Usage: microk8s disable addon [addon ...]

Options:

  • addon : The name of the addon to disable.

Description:
MicroK8s addons can be enabled or disabled at any time. This command accepts the name of an addon and then proceeds to make the necessary changes to remove it from the current node. Note that some services and applications may not continue to work properly if addons are removed.

Examples:

microk8s disable dns

…will usually result in output detailing what has been done. In this case,
the ouput will be similar to:

Disabling DNS
Reconfiguring kubelet
Removing DNS manifest
serviceaccount "coredns" deleted
configmap "coredns" deleted
deployment.apps "coredns" deleted
service "kube-dns" deleted
clusterrole.rbac.authorization.k8s.io "coredns" deleted
clusterrolebinding.rbac.authorization.k8s.io "coredns" deleted

microk8s enable

Usage: microk8s enable addon [addon ... ]

Options:

  • addon : The name of the addon to enable.

Description:
MicroK8s addons can be enabled or disabled at any time. This command accepts the name of an addon and then proceeds to make the necessary changes to MicroK8s to enable it. For more details, see the documentation for the specific addon in question in the addons documentation.

For a list of the current available addons, and whether or not they are enabled, run microk8s status.

Examples:

microk8s enable storage

…will result in output similar to:

Enabling default storage class
deployment.apps/hostpath-provisioner created
storageclass.storage.k8s.io/microk8s-hostpath created
serviceaccount/microk8s-hostpath created
clusterrole.rbac.authorization.k8s.io/microk8s-hostpath created
clusterrolebinding.rbac.authorization.k8s.io/microk8s-hostpath created
Storage will be available soon

microk8s inspect

Usage: microk8s inspect

Options:

Description:
This command creates a detailed profile of the current state of the running MicroK8s. This is primarily useful for troubleshooting and reporting bugs.

Examples:

microk8s inspect

…will result in output similar to:

Inspecting services
  Service snap.microk8s daemon-cluster-agent is running
  Service snap.microk8s daemon-flanneld is running
  Service snap.microk8s daemon-containerd is running
  Service snap.microk8s daemon-apiserver is running
  Service snap.microk8s daemon-apiserver-kicker is running
  Service snap.microk8s daemon-proxy is running
  Service snap.microk8s daemon-kubelet is running
  Service snap.microk8s daemon-scheduler is running
  Service snap.microk8s daemon-controller-manager is running
  Service snap.microk8s daemon-etcd 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 snap list to the final report tarball
  Copy VM name (or none) 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 current linux distribution to the final report tarball
  Copy openSSL information to the final report tarball
  Copy network configuration to the final report tarball
Inspecting kubernetes cluster
  Inspect kubernetes cluster

Building the report tarball
  Report tarball is at /var/snap/microk8s/982/inspection-report-20191017_180222.tar.gz

microk8s join

Usage: microk8s join <master>:<port>/<token>

Options:

Description:
Used to join the local MicroK8s node in to a remote cluster. An ‘invitation’ in
the form of a token is required, which is issued by running the
microk8s add-node command on the master MicroK8s node.

Running microk8s add-node will output a number of different commands which can
be used from the node wishing to join, taking into account different
network addressing. The microk8s join command will need the address and port
number of the master node, as well as the token, in order for this command to
be successful.

Examples:

microk8s join 10.128.63.163:25000/JGoShFJfHtbieSOsMhmkgsOHrwtxDKRH

microk8s kubectl

Usage: microk8s kubectl [command]

Options:

  • any kubectl command : See description.

Description:
This command runs the standard Kubernetes kubectl which ships with MicroK8s.

Examples:

microk8s kubectl get all

…will result in output similar to:

NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.152.183.1   <none>        443/TCP   108m

microk8s leave

Usage: microk8s leave

Options:

Description:
When run on a node which has previously joined a cluster with microk8s join,
this command will remove the current node from the cluster and return it to
single node operation.

Examples:

microk8s leave

microk8s refresh-certs (version 1.19+)

Usage: microk8s refresh-certs [</ca-path>] [-u] [-c]

Options:

  • -c : check the expiration time of the current certificate.
  • -u : Undo the last operation.

Description:
A self-signed CA is created by MicroK8s at install time. Starting from the 1.19 release, it is possible to refresh that CA with an auto-generated one or to configure Kubernetes to use a user-provided one.
Call microk8s refresh-certs with no arguments to auto-generate a new CA or provide a </ca-path> with the CA’s ca.crt and ca.key files.

On its own:

sudo microk8s refresh-certs

…will generate and use a new CA.

To use previously generated cert files, specify a path where the two files ca.crt and ca.key can be found:

sudo microk8s refresh-certs ./ca-path/

To undo the last operation you can use the -u flag:

sudo microk8s refresh-certs -u

To check the expiration time of the installed CA:

sudo microk8s refresh-certs -c

Notes:

  • The CA should not be updated in a cluster without running workloads. Auxiliary certificates and credentials make use of the CA, so updating the CA in a live cluster will have unpredictable effects.
  • In a multi-node setup, nodes will need to leave and rejoin the cluster in order for new certificates to properly propagate.

microk8s remove-node

Usage: microk8s remove-node address

Options:

  • address : The address of the node to be removed

Description:
Removes a specified node from the current cluster. The node should be identified by hostname/IP address by which it is known to the cluster. To retrieve this information you can run:

microk8s kubectl get nodes

This command only works on the master node of the cluster. To remove the local node from a remote cluster, see microk8s leave.

Examples:

microk8s remove-node 10.128.63.163

microk8s reset

Usage: microk8s reset [--destroy-storage]

Options:

  • --destroy-storage : Also deletes any files which may have been created by the storage addon.

Description:
This command is used to return the MicroK8s node to the default initial state. This process may take some time and will remove any resources, authentication, running services, pods and optionally, storage. All addons will be disabled and the configuration will be reinitialised.

This commands makes it easy to revert your MicroK8s to an ‘install fresh’ state wihout having to reinstall anything.

Examples:

microk8s reset

…will result in output similar to:

Calling clean_cluster
Cleaning resources in namespace default
No resources found
endpoints "kubernetes" deleted
secret "default-token-5lqdh" deleted
serviceaccount "default" deleted
service "kubernetes" deleted
...

microk8s start

Usage: microk8s start

Options:

Description:
Will start MicroK8s, if the MicorK8s node has previously been halted with microk8s stop.

Examples:

microk8s start

…will result in output similar to:

Started.
Enabling pod scheduling
node/ubuntu1804 already uncordoned

microk8s status

Usage: microk8s status

Options:

Description:
This command outputs some useful status information, including the current state of the MicroK8s node, and a list of all the available extensions, indicating which ones are enabled/disabled.

Examples:

microk8s status

…will result in output similar to:

microk8s is running

addons:
  enabled:
    cilium:          # SDN, fast with full network policy
    dashboard:       # Enable the Kubernetes dashboard
    dns:             # CoreDNS
  disabled:
    fluentd:         # Elasticsearch-Fluentd-Kibana logging and monitoring
    gpu:             # Automatic enablement of Nvidia CUDA
    helm:            # Leverage Helm charts to manage your Kubernetes apps
    ingress:         # Ingress controller for external access.
    istio:           # Core Istio service mesh services
    jaeger:          # Kubernetes Jaeger operator with its simple config
    juju:            # Model-driven operator engine
    knative:         # Add Knative serverless middleware to your cluster
    kubeflow:        # Enable Kubeflow for easy ML deployments
    linkerd:         # Deploy the linkerd service mesh
    metallb:         # Loadbalancer for your Kubernetes cluster
    metrics-server:  # K8s Metrics Server for API access to service metrics
    prometheus:      # Prometheus operator for monitoring and logging
    rbac:            # Enable Role-Based Access Control for authorisation
    registry:        # Private image registry exposed on localhost:32000
    storage:         # Storage class; allocates storage from host directory

microk8s stop

Usage: microk8s stop

Options:

Description:
Halts the current MicroK8s node.

Examples:

microk8s stop

…will result in output describing the shutdown process.

how do i restart i worker node by the master node?

This is not possible, but is a valid ask. Could you open a feature request issue over at https://github.com/ubuntu/microk8s/issues describing your needs and what CLI/UX would you like have.

Thank you.

thank you,

i am new using microk8s and new using this discuss forum… when i have some question, how do i have to proceed? do i need to come here and post something or could i go straight to issues in github?

Either would work. For questions prefer the forum. If it is a bug to report where you need to attach files github issues are more suitable.

The command microk8s dbctl will be great if it has option to upload to or download from an s3 bucket.
Thoughts?

Integrating with common backup repositories is a nice idea. Do you think such integration belongs to this command or should it be part of the user specific backup script?

Perhaps in many case users may have their own backup strategy. I do not have the numbers though.
I just thought of the user experience of providing option to backup the data file to an s3 storage as part of the command.
Just my 2 cents. :blush: