How to access minikube (installed on a remote VM) from my local machine?

10/23/2020

I have a CentOS 7 VM, which has minikube running with --vm-driver=none. On the VM itself, I can run kubectl commands to interact with the minikube cluster.

As I am new to k8s, I am not sure how to generate all the necessary values to put in the ~/.kube/config file. My end goal is to interact with minikube cluster like my other AWS EKS clusters by using kubectl on my local machine.

-- Grimlock
kubeconfig
kubectl
kubernetes
minikube

1 Answer

10/23/2020

To understand what you need in your local machine's ~/.kube/config file, checkout the ~/.kube/config file on the remote VM itself.

You'll find that you need to add these 3 items in your local machine's ~/.kube/config file:

  1. A cluster under clusters
  2. A context under contexts
  3. A user under users

To add these 3 items, first you need to copy these 3 files from remote VM to your local machine:

  1. ca.crt (usually found at ~/.minikube/profiles/minikube/ca.crt)
  2. client.crt (usually found at ~/.minikube/profiles/minikube/client.crt)
  3. client.key (usually found at ~/.minikube/profiles/minikube/client.key)

Now, you need to base64 encode these 3 files. For example, if you're on macOS, you can use this command:

base64 -i <input_file> -o <output_file>

Now you're ready to update your local machine's ~/.kube/config file.

  1. Add this cluster under clusters:
- cluster:
    certificate-authority-data: <base64 of ca.crt file>
    server: <same ip as remote VM's kubeconfig file, since you've used vm-driver=none>
  name: minikube
  1. Add this context under contexts (same values as remote VM)
- context:
    cluster: minikube
    user: minikube
  name: minikube
  1. Add this user under users
- name: minikube
  user:
    client-certificate-data: <base64 of client.crt file>
    client-key-data: <base64 of client.key file>
-- Grimlock
Source: StackOverflow