Working with kubectl

MicroK8s comes with its own packaged version of the kubectl command for operating Kubernetes. By default, this is accessed through MicroK8s, to avoid interfering with any version which may already be on the host machine (including its configuration). It is run in a terminal like this:

  1. microk8s kubectl

If you are using or want to use a different kubectl command, see the relevant sections below for your OS

Linux

If you’d prefer to use your host’s kubectl command, running the following command will output the kubeconfig file from MicroK8s.

  1. microk8s config

If you have not already configured kubectl on the host, you can just open a terminal and generate the required config :

  1. cd $HOME
  2. mkdir .kube
  3. cd .kube
  4. microk8s config > config

If you have already configured other Kubernetes clusters, you should merge the output from the microk8s config with the existing config (copy the output, omitting the first two lines, and paste it onto the end of the existing config using a text editor).

Windows

MicroK8s comes with its own kubectl command, which can be accessed like this:

  1. microk8s kubectl

There are some advantages to running the Windows native version of kubectl, notably when working with files(which otherwise need to be copied to/from the VM). To install the Windows version of kubectl, see the official documentation. Running the following command will output the kubeconfig file from MicroK8s:

  1. microk8s config

If you have not already configured kubectl on the host for other clusters, you can open a ‘cmd’ Command Prompt and run the following:

  1. cd %USERPROFILE%
  2. mkdir .kube
  3. cd .kube
  4. microk8s config > config

If you have already configured other Kubernetes clusters, you should merge the output from the microk8s config with the existing config (copy the output, omitting the first two lines, and paste it onto the end of the existing config using a text editor).

macOS

MicroK8s comes with its own kubectl command, which can be accessed like this:

  1. microk8s kubectl

There are some advantages to running the native version of kubectl for macOS, notably when working with files (which otherwise need to be copied to/from the VM). To install the macOS version of kubectl, see the official documentation. Running the following command will output the kubeconfig file from MicroK8s:

  1. microk8s config

If you have not already configured kubectl on the host, you can just open a terminal and generate the required config :

  1. cd $HOME
  2. mkdir .kube
  3. cd .kube
  4. microk8s config > config

If you have already configured other Kubernetes clusters, you should merge the output from the microk8s config with the existing config (copy the output, omitting the first two lines, and paste it onto the end of the existing config using a text editor).

Last updated 1 year, 2 months ago. Help improve this document in the forum.