This document describes how to setup your development environment.
Make sure the following software is installed and added to the $PATH
variable:
- Curl 7+ (installation)
- Git 2.13.2+ (installation)
- Docker 23.0.1+ (installation)
- Golang 1.20+ (installation)
- We use
go mod
for go dependency management
- We use
- Node.js 18.14.0+ (installation)
- Yarn 2+ (installation)
Clone the repository and install the dependencies:
make --directory modules/common/tools install
yarn
To make Dashboard work you need to have cluster running. If you would like to use local cluster we recommend kubeadm, minikube or kubeadm-dind-cluster. The most convenient way is to make it work is to create a proxy. Run the following command:
kubectl proxy
kubectl will handle authentication with Kubernetes and create an API proxy with the address localhost:8080
. Therefore, no changes in the configuration are required.
Quick updated version:
npm start
Another way to connect to real cluster while developing dashboard is to specify options for npm
like following:
npm run start:https --kubeconfig=<path to your kubeconfig>
Please see here which options you can specify to run dashboard with npm
.
Open a browser and access the UI under localhost:8080
.
In the background, npm start
makes a concurrently call to start the golang
backend server and the angular
development server.
Once the angular server starts, it takes some time to pre-compile all assets before serving them. By default, the angular development server watches for file changes and will update accordingly.
As stated in the Angular documentation, i18n does not work in the development mode. Follow Building Dashboard for Production section to test this feature.
Due to the deployment complexities of i18n and the need to minimize rebuild time, the development server only supports localizing a single locale at a time. Setting the "localize" option to true will cause an error when using ng serve if more than one locale is defined. Setting the option to a specific locale, such as "localize": ["fr"], can work if you want to develop against a specific locale (such as fr).
To build dashboard for production, you still need to install bc
.
The Dashboard project can be built for production by using the following task:
make build
The code is compiled, compressed, i18n support is enabled and debug support removed. The dashboard binary can be found in the dist
folder.
To build and immediately serve Dashboard from the dist
folder, use the following task:
make prod
Open a browser and access the UI under localhost:9090
. The following processes should be running (respective ports are given in parentheses):
Dashboard backend (9090) ---> Kubernetes API server (8080)
To build the Docker image on darwin OS you will need to set environment variable for go to build as linux:
export GOOS=linux
In order to package everything into a ready-to-run Docker image, use the following task:
make docker-build-head
You might notice that the Docker image is very small and requires only a few MB. Only Dashboard assets are added to a scratch image. This is possible, because the dashboard
binary has no external dependencies. Awesome!
Unit tests should be executed after every source code change. The following task makes this a breeze. The full test suite includes unit tests and integration tests.
make test
You can also run individual tests on their own (such as the backend or frontend tests) by doing the following:
make test-backend
make test-frontend
The code style check suite includes format checks can be executed with:
make check
The code formatting can be executed with:
make fix
These check and formatting involves in go, ts, scss, html, license and i18n files.
Before committing any changes, please run make fix
. This will keep you from accidentally committing non tested and unformatted code.
Since the hooks for commit has been set with husky
into <dashboard_home>/.git/hooks/pre-commit
already if you installed dashboard according to above, so it will run make fix
and keep your code as formatted.
Then you can commit your changes and push them to your fork:
git commit
git push -f origin my-feature
At first, change directory to kubernetes dashboard repository of your fork. This development container has all of dependencies to develop dashboard.
- Development container builds Kubernetes Dashboard and runs it with self-certificates by default.
- This container create
user
withUID
andGID
same as local user, switch user touser
withgosu
and run commands. So created or updated files like results ofmake fix
would have same ownership as your host. You can commit them immediately from your host. - Built Kubernetes Dashboard will run by
docker compose
, so other few containers will be created in your docker. - A Docker network called
kubernetes-dashboard
will be created by our script and all these containers will be assigned to it.
- Run
hack/develop/run-dev-container.sh
.
That's all. It will build dashboard container from your local repository, will create also kubernetes cluster container for your dashboard using kind
, and will run dashboard.
Then you can see dashboard http://localhost:4443 with your browser. Since dashboard uses self-certificates, so you need ignore warning or error about it in your browser.
- Copy kubeconfig from your cluster, and confirm the URL for API server in it, and modify it if necessary.
- Set filepath for kubeconfig into
KD_DEV_KUBECONFIG
environment variable. - If you deployed
dashboard-metrics-scraper
in your cluster, set its endpoint toKD_DEV_SIDECAR_HOST
environment variable. - Change directory into your dashboard source directory.
- Run
hack/develop/run-dev-container.sh
.
These manipulations will build container and run dashboard with make run
as default.
To accessing Kubernetes Dashboard, open https://localhost:4443 from your browser.
- Set
KD_DEV_CMD
environment variable asbash
. - Run
hack/develop/run-dev-container.sh
. - Run commands as you like in the container.
This runs container and execute bash
command interactively. Then, develop Kubernetes Dashboard!
- To run dashboard, execute
make run
. This will build dashboard for production and run three containers for the dashboard. Then, access https://localhost:4443 from your browser. - To run dashboard with Angular Live Development Server, execute
KUBECONFIG=/home/user/.kube/config make serve
. Then, access http://localhost:8080 from your browser.
- Run
docker exec -it k8s-dashboard-dev gosu user bash
.
Copyright 2019 The Kubernetes Dashboard Authors