Is it possible to run dashboard UI locally via docker run, but using api proxied from remote server?

Hi!

Our company dropped support for Kubernetes UI leaving us just CLI options.

I would love to ask therefore, is it possible somehow to run dashboard UI ( since is like a web app ) in a separate container on localhost, sharing with it api server via kubectl proxy?

Thank you!

[Courtesy of Google DeepMind]

Yes, it is indeed possible to run the Kubernetes Dashboard UI in a Docker container on your local machine while proxying the API server from a remote Kubernetes cluster. Here’s a high-level approach to achieving this:

Step 1: Set Up kubectl Proxy

First, ensure that kubectl is configured correctly to communicate with your remote Kubernetes cluster. Once that’s established, you can start a proxy to the Kubernetes API server using the following command:

shCopy code

kubectl proxy --port=8080

This command makes the Kubernetes API server accessible locally at http://localhost:8080. The proxy server forwards requests to the remote Kubernetes API server, effectively acting as a middleman.

Step 2: Run Kubernetes Dashboard in Docker

To run the Kubernetes Dashboard in a Docker container and connect it to the proxied API server, you can follow these steps:

  1. Pull the Kubernetes Dashboard Docker Image: You’ll need to pull the official Kubernetes Dashboard image from Docker Hub or any other container registry hosting the image.

shCopy code

docker pull kubernetesui/dashboard:v2.0.0  # Use the latest version
  1. Run the Dashboard Container: Start a Docker container from the Dashboard image. You’ll need to configure the container to use the host network to easily access the kubectl proxy. This is done using the --network="host" option in the docker run command.

shCopy code

docker run --rm -it --network="host" kubernetesui/dashboard:v2.0.0

Using the host network mode allows the Dashboard running inside the container to access services running on the host machine, including the kubectl proxy.

Step 3: Access the Dashboard

With the kubectl proxy running and the Dashboard UI running in a Docker container, you can access the Dashboard through your web browser at the following URL:

bashCopy code

http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

Step 4: Authentication

To access the Dashboard, you will need an authentication token. You can use a Service Account token or a kubeconfig file for authentication. If you don’t have a Service Account with the necessary permissions, you might need to create one and assign the appropriate roles.

  1. Create a Service Account (if necessary):

shCopy code

kubectl create serviceaccount dashboard-admin -n kube-system
  1. Bind the Service Account to a Cluster Role:

shCopy code

kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
  1. Get the Token:

shCopy code

kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep dashboard-admin | awk '{print $1}')

Copy the token and use it to log in to the Dashboard UI.

Notes

  • Ensure that your local firewall or security settings allow traffic between your local machine and the remote Kubernetes cluster.
  • Be mindful of security implications, especially when exposing the Kubernetes API server, even if it’s just locally. Ensure proper authentication and authorization mechanisms are in place.
  • Versions and configurations might vary, so adjust commands accordingly.

This setup should help you get the Kubernetes Dashboard running locally while interacting with a remote Kubernetes cluster.

Unfortunately this seems to be AI generated response and I do jot think this approach will work just as is… I think we need to have more parameters for container at least

This question is more than 1 month old, and maybe you already found a way to achieve your goal. However, I’ll post an answer here since I was not able to find any other answer anywhere else, and it may interest other people :slight_smile:

It is possible to run the Kubernetes dashboard locally using Docker compose. Under the hood, this is how the dashboard development mode works. Indeed, running make serve from a clone of GitHub - kubernetes/dashboard: General-purpose web UI for Kubernetes clusters spawns a local kind cluster and starts 5 local Docker containers using Docker compose.

Here is a Docker compose Gist that is largely based on this development environment but uses the official released images from the Docker Hub instead: Run Kubernetes dashboard locally · GitHub.

This Gist requires a valid Kubeconfig file. It will use ~/.kube/config by default, but this can be customized using KUBECONFIG environment variable.

For example, to run the dashboard locally using the latest official images and using the default kubeconfig file, you can use:

curl -s https://gist.githubusercontent.com/yadutaf/dcbf8668a102438e7b1ec3ff520d0cb6/raw/802e339518f0fc1458fb0302624eb7ae3c8e184e/kube-dashboard.docker.compose.yaml \
   | docker compose -f- up \
     --remove-orphans \
     --no-attach gateway \
     --no-attach scraper

If for any reason the dashboard can not connect to the cluster (eg: when using a specific auth plugin that is not available in the official images like gke-gcloud-auth-plugin), you can additionally spawn a local Kube proxy and use a kube config to connect through the proxy:

# Start the proxy, allowing connections from Docker's bridge
kubectl proxy --address 172.17.0.1 --accept-hosts='^localhost$,^127\.0\.0\.1$,^172\.\d+\.\d+\.\d$'

# Create a stub kubeconfig to connect through this proxy
cat > kubeconfig.proxy <<EOF
apiVersion: v1
kind: Config
clusters:
- cluster:
    server: http://172.17.0.1:8001
  name: proxy
contexts:
- context:
    cluster: proxy
    namespace: default
  name: proxy-default
current-context: proxy-default
EOF

# And finally start the dashboard using this config file
curl -s https://gist.githubusercontent.com/yadutaf/dcbf8668a102438e7b1ec3ff520d0cb6/raw/802e339518f0fc1458fb0302624eb7ae3c8e184e/kube-dashboard.docker.compose.yaml \
   | KUBECONFIG=kubeconfig.proxy docker compose -f- up \
     --remove-orphans \
     --no-attach gateway \
     --no-attach scraper

Nota: the scraper does not work in practice, probably because it can not connect to the real metric source. Therefore, no metric will be available in the dashboard.