Why installing kubectl if already using microk8s (video from canaonical)

While studying microk8s I watched the video titled MicroK8s basics (Part 1): MicroK8s installation & simple commands in the celebrateubuntu youtube channel.

I’m puzzled as it installs both microk8s AND kubectl. Why that?

If it wasn’t for the authoritative channel I would have thought at an error, but since it’s from Ubuntu there must be an explanation that I can’t make out…

sudo snap alias microk8s.kubectl

Thanks, @metabsd, I know how to create the alias.

My question is why did the video suggest to also install kubeclt (sudo snap install kubectl) when, in fact, it already had kubectl from the installation of microk8s.

I have not seen the video but the only logical reason I see is to snap install kubectl from another Ubuntu to manage the cluster from outside.

I have now another case to use kubectl from snap install kubectl: It correctly reads ~/.kube/config that kubectl from microk8s does not!!!

*:frowning:

I also use kubectl from snap. I export the microk8s config to ~/.kube/config.

1 Like

Why would you need to setup ~/.kube/config on the same machine using microk8s? My setup is microk8’s for internal cluster actions, and kubectl for external actions

To be able to launch a command from one cluster in another cluster… I think that’s the point of ~/.kube/config, isn’t it?

So my current setup uses the ~/.kube/config. My current setup is such:

workstation -> master
                  -> node
                  -> node
                  -> node

I use the kubectl command to do actions on my master. The workstation has the ~/.kube/config

It sounds like you are trying to do this:

master1 -> master2

Where master1 is a k8’s master, and master2 is a k8s master. Both running microk8’s. Is that correct?

I would think this may cause some issues, but I can’t confirm. Why can’t you use the workstation approach?

workstation -> master1
            -> master2 

I also installed microk8s on my laptop, just to study it. At that point I has kubect as alias to microk8s.kubectl.

Nowhere in the docs I read this is not a recommended setup. From my workstation want to reach any need to must administer.

I can use kubectl from its own snap rather that from microk8s, but I’d like to know why I need to do that. Docs say that microk8s.kubectl should read ~/.kube/config.

Why do you think is should cause “some issues”?

The some issues is more of a gut feeling. I have no idea how microk8’s sets up its config, but it “just works” out of the box for local, Looking at my master node it doesn’t even have a ~/.kube/config file, but I can still do microk8s.kubectl commands.

My method isn’t the “recommended setup”, but it seems to work really well.

Reading the docs I do not see how it would work with the ~/.kube/config. It seems to point at the opposite.

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).

I would setup a master config with all your masters and use kubectl, not microk8s kubectl. That would seem to solve your issue