In short, you can copy the file from microk8s
instance that kubectl
is using (kubeconfig
) to the Windows machine in order to connect to your microk8s
instance.
As you already have full connectivity between the Windows machine and the Ubuntu that microk8s
is configured on, you will need to:
- Install
kubectl
on Windows machine
- Copy and modify the
kubeconfig
file on your Windows machine
- Test the connection
Install kubectl
You can refer to the official documentation on that matter by following this link:
Copy and modify the kubeconfig
file on your Windows machine
IMPORTANT!
After a bit of research, I've found easier way for this step.
You will need to run microk8s.config
command on your microk8s
host. It will give you the necessary config to connect to your instance and you won't need to edit any fields. You will just need to use it with kubectl
on Windows machine.
I've left below part to give one of the options on how to check where the config file is located
This will depend on the tools you are using but the main idea behind it is to login into your Ubuntu machine, check where the kubeconfig
is located, copy it to the Windows machine and edit it to point to the IP address of your microk8s
instance (not 127.0.0.1
).
If you can SSH
to the VM
you can run following command to check where the config file is located (I would consider this more of a workaround solution):
microk8s kubectl get pods -v=6
I0506 09:10:14.285917 104183 loader.go:379] Config loaded from file: /var/snap/microk8s/2143/credentials/client.config
I0506 09:10:14.294968 104183 round_trippers.go:445] GET https://127.0.0.1:16443/api/v1/namespaces/default/pods?limit=500 200 OK in 5 milliseconds
No resources found in default namespace.
As you can see in this example, the file is in (it could be different in your setup):
/var/snap/microk8s/2143/credentials/client.config
You'll need to copy this file to your Windows machine either via scp
or other means.
After it's copied, you'll need to edit this file to change the field responsible for specifying where the kubectl
should connect to:
- before:
server: https://127.0.0.1:16443
- after:
server: https://ubuntuk8s:16443
Test the connection
One of the ways to check if you can connect from your Windows machine to microk8s
instance is following:
PS C:\Users\XYZ\Desktop> kubectl --kubeconfig=client.config get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
ubuntu Ready <none> 101m v1.20.6-34+e4abae43f6acde 192.168.0.116 <none> Ubuntu 20.04.2 LTS 5.4.0-65-generic containerd://1.3.7
Where:
--kubeconfig=client.config
is specifying the file that you've downloaded
Additional resources: