Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Kubernetes API via Kubernetes Dashboard Host

So the idea is Kubernetes dashboard accesses Kubernetes API to give us beautiful visualizations of different 'kinds' running in the Kubernetes cluster and the method by which we access the Kubernetes dashboard is by the proxy mechanism of the Kubernetes API which can then be exposed to a public host for public access.

My question would be is there any possibility that we can access Kubernetes API proxy mechanism for some other service inside a Kubernetes cluster via that publically exposed address of Kubernetes Dashboard?

like image 712
Arpit Goyal Avatar asked Oct 09 '18 15:10

Arpit Goyal


People also ask

How do I access API in Kubernetes?

When accessing the Kubernetes API for the first time, use the Kubernetes command-line tool, kubectl . To access a cluster, you need to know the location of the cluster and have credentials to access it.

What type of account does the dashboard application use to query the Kubernetes API?

The recommended way to authenticate to the API server is with a service account credential. By default, a Pod is associated with a service account, and a credential (token) for that service account is placed into the filesystem tree of each container in that Pod, at /var/run/secrets/kubernetes.io/serviceaccount/token .

What can you do with Kubernetes dashboard?

Dashboard is a web-based Kubernetes user interface. You can use Dashboard to deploy containerized applications to a Kubernetes cluster, troubleshoot your containerized application, and manage the cluster resources.

How to access Kubernetes dashboard from outside the cluster?

You can reach by hitting the nodePort for the dashboard on the master Now you should be able to access the dashboard at port 10443. You need to run kubectl proxy locally for accessing the dashboard outside the kubernetes cluster. This is because of the authentication mechanism.

How do I access the Kubernetes API?

When accessing the Kubernetes API for the first time, use the Kubernetes command-line tool, kubectl. To access a cluster, you need to know the location of the cluster and have credentials to access it.

How to access Kubernetes-dashboard with HTTPS<IP>8001?

Kubernetes dashboard opened successfully. create a new service to expose port 8001 to kubernetes-dashboard's 8443. now, you can access your kubernetes-dashboard with https://<ip>:8001 . Change type: ClusterIP to type: NodePort and save file. Dashboard has been exposed on port 31707 (HTTPS).

What is the welcome view in Kubernetes dashboard?

Welcome view. When you access Dashboard on an empty cluster, you’ll see the welcome page. This page contains a link to this document as well as a button to deploy your first application. In addition, you can view which system applications are running by default in the kube-system namespace of your cluster, for example the Dashboard itself.


Video Answer


2 Answers

Sure you can. So after you set up your proxy with kubectl proxy, you can access the services with this format:

http://localhost:8001/api/v1/namespaces/kube-system/services/<service-name>:<port-name>/proxy/

For example for http-svc and port name http:

http://localhost:8001/api/v1/namespaces/default/services/http-svc:http/proxy/

Note: it's not necessarily for public access, but rather a proxy for you to connect from your public machine (say your laptop) to a private Kubernetes cluster.

like image 109
Rico Avatar answered Oct 18 '22 02:10

Rico


You can do it by changing your service to NodePort:

$ kubectl -n kube-system edit service kubernetes-dashboard

You should see yaml representation of the service. Change type: ClusterIP to type: NodePort and save file.

Note: This way of accessing Dashboard is only possible if you choose to install your user certificates in the browser. Certificates used by kubeconfig file to contact API Server can be used.

Please check the following articles and URLs for better understanding:

Stackoverflow thread

Accessing Dashboard 1.7.X and above

Deploying a publicly accessible Kubernetes Dashboard

How to access kubernetes dashboard from outside cluster

Hope it will help you!

like image 29
Vit Avatar answered Oct 18 '22 01:10

Vit