Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring kubectl against remote clusters

I followed the Kubernetes docs for setting up a single node cluster as a Docker container. I now have Kubernetes running on a remote Linux VM (say, mykube01.example.com).

I then downloaded and installed kubectl locally on my Mac laptop. I can run kubectl version and it verifies I have installed the correct version.

I then went to configure kubectl by following this doc and created the following ~/.kube/config file:

 apiVersion: v1
 clusters:
 - cluster:
      api-version: v1
      server: http://mykube01.example.com:8080
      name: testkube

When I run kubectl cluster-info I get:

Kubernetes master is running at http://mykuber01.example.com:8080

But when I run kubetctl get nodes I get:

The connection to the server mykube01.example.com:8080 was refused - did you specify the right host or port?

Any ideas where I'm going awry? I want to get to the point where I can keep going with that first Kubernetes doc and deploy nginx to the 1-node cluster via:

kubectl -s http://mykube01.example.com:8080 run-container nginx --image=nginx --port=80

But I can't do that until I get kubectl configured properly and correctly connecting to my remote "cluster".

like image 503
smeeb Avatar asked Sep 25 '15 20:09

smeeb


People also ask

How do you point a kubectl to a remote cluster?

Be sure to set KUBERNETES_PUBLIC_ADDRESS to the public IP of your controller. Set the credentials for kubectl. Set the context for the cluster. Use the new kubectl context to check which pods are currently running on the cluster.

How do I access Kubernetes remotely?

For the locally installed kubectl instance to remote access your Kubernetes cluster's API server running at https://cluster-ip-address:8443 , you need to setup a public we URL for the API server, so that you could access and manage the cluster from anywhere in the internet.

How does kubectl connect to cluster?

When kubectl accesses the cluster it uses a stored root certificate and client certificates to access the server. (These are installed in the ~/. kube directory). Since cluster certificates are typically self-signed, it may take special configuration to get your http client to use root certificate.


1 Answers

When you created the connection to your master, a file should be created:

/etc/kubernetes/kubelet.conf

By default, your personal config is empty or missing. So, I copied the above mentioned kubelet.conf file as my ~/.kube/config file. Worked perfectly.

like image 86
Colin Fox Avatar answered Sep 28 '22 20:09

Colin Fox