2

I have a Windows 10 machine running a Hyper-V virtual machine with Ubuntu guest. On Ubuntu, there is a Microk8s installation for my single node Kubernetes cluster.

I can't figure out how to set up my kubectl on the Win10 to allow deploying on the microk8s cluster in the vm.

Atm, from outside, I can ssh into the vm and I can reach the dashboard-proxy for microk8s (in this case locally https://ubuntuk8s:10443 ).

How to configure kubectl on my windows to deploy to microk8s inside the vm?

1 Answers1

1

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:

Dawid Kruk
  • 8,982
  • 2
  • 22
  • 45
  • Thanks Dawid! This helped alot! The only thing that is not working is changing the IP to machine name. That gives me the following error: "error loading config file "C:\Users\joern/.kube/config": v1.Config.Contexts: []v1.NamedContext: Clusters: []v1.NamedCluster: v1.NamedCluster.Name: Cluster: v1.Cluster.Server: CertificateAuthorityData: decode base64: illegal base64 data at input byte 107, error found in #10 byte of ...|VUF\u003e","server":|..., bigger context ...|QVBOaDNsaEd5eWhJTUEwR0NTcUdTSWIzRFFFQkN3VUF\u003e","server":"https://ubuntuk8s:16443"},"name":"micro|..." – babbyldockr May 07 '21 at 09:33
  • Actually, the basic access is working with the output of the microc8s.config command copied to my kubectl config file. Also there is an IP adress that I cannot change to machine name without breaking the thing – babbyldockr May 07 '21 at 09:39