How to add a K8s cluster on the local network to Juju 2.6?

I would like to add a Kubernetes cluster to Juju that’s on my local network. The cluster was spun up with microk8s, but not with my local copy of microk8s. I tried both with and without specifying a region, like this:

juju add-k8s microk8s --storage=operator-storage <kubeconfig
juju add-k8s microk8s --storage=operator-storage --region=localhost <kubeconfig

The first one gave me an error about needing to specify a region, and the second one gave me an error about microk8s already existing as a built-in cloud. I also tried giving it a name of microk8s-cluster (which is the cluster name in kubeconfig), and that didn’t seem to help, as I got an error about localhost being an invalid region.

add-k8s uses the content of a kubeconfig file to extract the cluster endpoint and credential details.
It will by default look in ~/.kube/config, so the commands above are not quite right if you are looking to register a microk8s cluster. What you want to try is something like:

microk8s.config | juju add-k8s mycluster

See that add-k8s also accepts input from stdin so the above pipes the microk8s config to add-k8s to be parsed.

This ended up working:

juju add-k8s cluster-name --storage=microk8s-hostpath --region=microk8s/localhost < kubeconfig
1 Like