Search code examples
kubernetesvagrantvirtualboxkubectlvagrantfile

Access Kubernetes Cluster in Virtual Machines


I've setup a kubernetes cluster using vagrant and virtual vbox. So far everything seems to wo work fine.

Next step was to deploy the dashboard application using the guide from https://github.com/kubernetes/dashboard (and the linked "Create An Authentication Token (RBAC)" section).

Now I run into an issue. Since I setup all nodes as virtual machines I need to deploy my application to a VM. But how can I access these services from my host machine via browser?

Running kubectl proxy & inside the VM does not do the trick to access from my host.

My whole setup is available on Github: https://github.com/sebastian9486/v-kube-cluster

Output from my dashboard.sh (the IP addresses are from my vagrantboxes)

[INFO] Start deployment of application: dashboard
[INFO] Start deployment
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/dashboard-metrics-scraper created
Connection to 127.0.0.1 closed.
serviceaccount/admin-user created
Connection to 127.0.0.1 closed.
[DONE] Created service account
clusterrolebinding.rbac.authorization.k8s.io/admin-user created
Connection to 127.0.0.1 closed.
[DONE] Created service account
[INFO] ***   BEARER TOKEN   *********************************************

eyJhbGciOiJSUzI1NiIsImtpZCI6IlBZZ2wzUWtHeTdKbC0xVEptQXBMQTI0MXpmdzdkMEo0dDNEYVdSenV0NmcifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLTVkYnhrIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJhOWZiYmNiYS1kZDI2LTQ4MzAtYWRkOC0xOTg5MWJhZTg0NTAiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6YWRtaW4tdXNlciJ9.TBH-NHpG8KMqzucQ70OoCijcAIi3qo0pM2LURa01hFG-7WQfvhYNGQo5q36hBenZdOPwZrIQ5WewfUJTEQ52UpnPKUhZVy7jwhIZEn7qaIQkHJYynNXzqnCAP7aS__paTG5AVQNDUWSpwEVBR0GNp0pBZq1rq_6SdA3ePuqKqCXnhWzGEgkN-Vy1hOORL87ecbTy2TNWADDPy90_rSPc4NdpF6NDFbpU1yW9upmR1AL7qNpUWsCYGWRLavY2jcCaG4s6uSsYcTlJByCKePBrALQa1LyIcwHlvZjaEDCBQLvhXfLI6pm6rF2ln_AhV0WXGG1zdzCYI9Xw1HSsyKhdaQConnection to 127.0.0.1 closed.

[INFO] ******************************************************************
[DONE] ------------------------------------------------------------------
[DONE] Deployed application: dashboard
[DONE] ------------------------------------------------------------------
Connection to 127.0.0.1 closed.
[DONE] Started kube proxy on v-kube-master machine
[INFO] http://192.168.50.10:8001/ui
[INFO] http://192.168.50.10:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

Accessing URLs in the host-machines browser results in:

When I ssh into the master-node I get these results:

vagrant@v-k8s-master:~$ curl http://192.168.50.10:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
curl: (7) Failed to connect to 192.168.50.10 port 8001: Connection refused

vagrant@v-k8s-master:~$ curl http://127.0.0.1:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
curl: (7) Failed to connect to 127.0.0.1 port 8001: Connection refused

vagrant@v-k8s-master:~$ curl http://127.0.0.1:8080/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused

vagrant@v-k8s-master:~$ curl http://192.168.50.10:8080/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
curl: (7) Failed to connect to 192.168.50.10 port 8080: Connection refused

Anyone got an idea?


Solution

  • Try exposing proxy with this way:

    kubectl proxy --address='0.0.0.0' --port=8001 --accept-hosts='.*'
    

    Then from your host machine acceded to http://192.168.50.10:8001/api/v1/...