Skip to content

Commit 42fc880

Browse files
authored
Setup development container for new architecture (kubernetes#7563)
* Fix path and add yarn * Add `docker compose` plugin Also, fix path. * Setup docker group * Setup default behavior that exec `make run` * Cleanup backup file * Rename script for running development container
1 parent 5c95903 commit 42fc880

File tree

6 files changed

+46
-62
lines changed

6 files changed

+46
-62
lines changed

docs/developer/getting-started.md

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -138,57 +138,37 @@ git push -f origin my-feature
138138
## Easy way to build your development environment with Docker
139139

140140
At first, change directory to kubernetes dashboard repository of your fork.
141+
This development container has all of dependencies to develop dashboard.
141142

142-
### Allow accessing dashboard from outside the container
143+
### Miscellaneous
143144

144-
Development container builds Kubernetes Dashboard and runs it with self-certificates by default,
145-
but Kubernetes Dashboard is not exposed to outside the container with insecure certificates by default.
145+
* Development container builds Kubernetes Dashboard and runs it with self-certificates by default.
146+
* This container create `user` with `UID` and `GID` same as local user, switch user to `user` with `gosu` and run commands. So created or updated files like results of `make fix` would have same ownership as your host. You can commit them immediately from your host.
147+
* Built Kubernetes Dashboard will run by `docker compose`, so other few containers will be created in your docker.
146148

147-
To allow accessing dashboard from outside the development container,
148-
pass value for `--insecure-bind-address` option to dashboard as follows:
149-
150-
* Set `K8S_DASHBOARD_BIND_ADDRESS` environment variable as `"0.0.0.0"` before using `aio/develop/run-npm-on-container.sh`.
151-
* Run like `npm run [command] --bind_address="0.0.0.0"`, when you run dashboard from inside the container.
152-
153-
### Change port number for dashboard
154-
155-
As default, development container uses `8080` port to expose dashboard. If you need to change the port number, set `K8S_DASHBOARD_PORT` environment variable before using `aio/develop/run-npm-on-container.sh`. The variable would be passed to `--port` option for docker and `npm run start` command inside container, then container exports the port and dashboard starts at the port.
156-
157-
### To run dashboard using Docker at ease
158-
159-
1. Run `aio/develop/run-npm-on-container.sh`.
160-
161-
That's all. It will build dashboard container from your local repository, will create also kubernetes cluster container for your dashboard using [`kind`](https://github.com/kubernetes-sigs/kind), and will run dashboard.
162-
Then you can see dashboard `http://localhost:8080` with your browser. Since dashboard uses self-certificates, so you need ignore warning or error about it in your browser.
163-
164-
### To run with your another Kubernetes cluster
149+
### To run with your Kubernetes cluster
165150

166151
1. Copy kubeconfig from your cluster, and confirm the URL for API server in it, and modify it if necessary.
167152
2. Set filepath for kubeconfig into `K8S_DASHBOARD_KUBECONFIG` environment variable.
168153
3. If you deployed `dashboard-metrics-scraper` in your cluster, set its endpoint to `K8S_DASHBOARD_SIDECAR_HOST` environment variable.
169154
4. Change directory into your dashboard source directory.
170-
5. Run `aio/develop/run-npm-on-container.sh`.
171-
172-
These manipulations will build container, and run dashboard as default.
173-
174-
### To run npm commands as you want
155+
5. Run `hack/develop/run-dev-container.sh`.
175156

176-
Also, you can run npm commands described in package.json as you want
157+
These manipulations will build container and run dashboard with `make run` as default.
177158

178-
e.g.
179-
1. To test dashboard, run `aio/develop/run-npm-on-container.sh run test`.
180-
2. To check your code changes, run `aio/develop/run-npm-on-container.sh run check`.
159+
To accessing Kubernetes Dashboard, open https://localhost:4443 from your browser.
181160

182-
This container create `user` with `UID` and `GID` same as local user, switch user to `user` with `gosu` and run commands. So created or updated files like results of `npm run fix` or `npm run check` would have same ownership as your host. You can commit them immediately from your host.
183-
184-
### To run container without creating cluster and running dashboard
161+
### Just to run development container without building and running dashboard
185162

186163
1. Set `K8S_DASHBOARD_CMD` environment variable as `bash`.
187-
2. Run `aio/develop/run-npm-on-container.sh`.
164+
2. Run `hack/develop/run-dev-container.sh`.
188165
3. Run commands as you like in the container.
189166

190167
This runs container with `bash` command.
191168

169+
To run dashboard, execute `make run`. This will build dashboard for production and run three containers for the dashboard.
170+
Then, access https://localhost:4443 from your browser.
171+
192172
### To access console inside of running development container
193173

194174
1. Run `docker exec -it k8s-dashboard-dev gosu user bash`.

hack/develop/Dockerfile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - \
4141
&& rm -rf /var/lib/apt/lists/* \
4242
&& apt-get clean
4343

44+
# Install yarn
45+
RUN npm install -g yarn
46+
4447
ENV GIT_EDITOR=nano
4548

4649
# Install firefox from Mozilla binaries
@@ -66,14 +69,19 @@ ENV NG_CLI_ANALYTICS=false
6669

6770
# Download a statically linked docker client,
6871
# so the container is able to build images on the host.
69-
RUN curl -sSL https://download.docker.com/linux/static/stable/x86_64/docker-20.10.17.tgz > /tmp/docker.tgz && \
72+
RUN curl -sSL https://download.docker.com/linux/static/stable/x86_64/docker-20.10.22.tgz > /tmp/docker.tgz && \
7073
cd /tmp/ && \
7174
tar xzvf docker.tgz && \
7275
rm docker.tgz && \
7376
mv /tmp/docker/docker /usr/bin/docker && \
7477
rm -rf /tmp/docker/ && \
7578
chmod +x /usr/bin/docker
7679

80+
# Install docker compose plugin
81+
RUN mkdir -p /usr/local/lib/docker/cli-plugins
82+
RUN curl -SL https://github.com/docker/compose/releases/download/v2.14.0/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
83+
RUN chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
84+
7785
# Install kubectl
7886
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
7987
RUN chmod +x ./kubectl
@@ -82,7 +90,7 @@ RUN mv ./kubectl /usr/local/bin/kubectl
8290
# Install golangci for ckecking or fixing go format.
8391
# `npm ci` installs golangci, but this installation is needed
8492
# for running `npm run check` singlely, like
85-
# `aio/develop/run-npm-on-container.sh run check`.
93+
# `hack/develop/run-dev-container.sh run check`.
8694
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0
8795

8896
# Enable go mod.
@@ -114,4 +122,4 @@ WORKDIR /go/src/github.com/kubernetes/dashboard
114122
EXPOSE 8080 8443 9090 2345
115123

116124
# Run gosu command in container.
117-
CMD ./aio/develop/gosu-command.sh
125+
CMD ./hack/develop/gosu-command.sh

hack/develop/gosu-command.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ fi
2323
useradd -u ${LOCAL_UID} -g ${LOCAL_GID} -d /home/user user
2424
chown -R ${LOCAL_UID}:${LOCAL_GID} /home/user
2525

26+
# Create docker group and add user to docker group, if group its ID provided
27+
if [ -v DOCKER_GID ]; then
28+
groupadd -g ${DOCKER_GID} docker
29+
usermod -aG docker user
30+
fi
31+
2632
# Add user as sudoer without password
2733
echo "user ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/user
2834

@@ -38,5 +44,5 @@ if [[ -n "${K8S_DASHBOARD_CMD}" ]] ; then
3844
${GOSU} ${K8S_DASHBOARD_CMD}
3945
else
4046
# Run npm command
41-
${GOSU} aio/develop/npm-command.sh
47+
${GOSU} hack/develop/npm-command.sh
4248
fi

hack/develop/npm-command.sh

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,9 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
# Install dependencies
17-
echo "Install dependencies"
18-
npm ci
19-
2016
# Run npm command if K8S_DASHBOARD_NPM_CMD is set,
2117
# otherwise start dashboard.
22-
if [[ -n "${K8S_DASHBOARD_NPM_CMD}" ]] ; then
23-
# Run npm command
24-
echo "Run npm '${K8S_DASHBOARD_NPM_CMD}'"
25-
npm ${K8S_DASHBOARD_NPM_CMD} \
26-
--bind_address=${K8S_DASHBOARD_BIND_ADDRESS} \
27-
--sidecar_host=${K8S_DASHBOARD_SIDECAR_HOST} \
28-
--port=${K8S_DASHBOARD_PORT}
29-
else
18+
if [[ -v "${K8S_DASHBOARD_NPM_CMD}" ]] ; then
3019
if [[ "${K8S_OWN_CLUSTER}" != true ]] ; then
3120
# Stop cluster.
3221
echo "Stop cluster"
@@ -43,24 +32,22 @@ else
4332
sed -e "s/127.0.0.1:[0-9]\+/${KIND_ADDR}:6443/g" /tmp/kind.kubeconfig > ~/.kube/config
4433
# Deploy recommended.yaml to deploy dashboard-metrics-scraper sidecar
4534
echo "Deploy dashboard-metrics-scraper into kind cluster"
46-
kubectl apply -f aio/deploy/recommended.yaml
35+
kubectl apply -f hack/deploy/recommended.yaml
4736
# Kill and run `kubectl proxy`
4837
KUBECTL_PID=$(ps -A|grep 'kubectl'|tr -s ' '|cut -d ' ' -f 2)
4938
echo "Kill kubectl ${KUBECTL_PID}"
5039
kill ${KUBECTL_PID}
5140
nohup kubectl proxy --address 127.0.0.1 --port 8000 >/tmp/kubeproxy.log 2>&1 &
52-
export K8S_DASHBOARD_SIDECAR_HOST="http://localhost:8000/api/v1/namespaces/kubernetes-dashboard/services/dashboard-metrics-scraper:/proxy/"
41+
export SIDECAR_HOST="http://localhost:8000/api/v1/namespaces/kubernetes-dashboard/services/dashboard-metrics-scraper:/proxy/"
5342
# Inform how to get token for logging in to dashboard
5443
echo "HOW TO GET TOKEN FOR LOGGING INTO DASHBOARD"
5544
echo "1. Run terminal for dashboard container."
5645
echo " docker exec -it k8s-dashboard-dev gosu user bash"
5746
echo "2. Run following to get token for logging into dashboard."
5847
echo " kubectl -n kubernetes-dashboard create token kubernetes-dashboard"
5948
fi
60-
# Start dashboard.
61-
echo "Start dashboard in production mode"
62-
npm run start:prod \
63-
--bind_address=${K8S_DASHBOARD_BIND_ADDRESS} \
64-
--sidecar_host=${K8S_DASHBOARD_SIDECAR_HOST} \
65-
--port=${K8S_DASHBOARD_PORT}
6649
fi
50+
51+
# Start dashboard.
52+
echo "Start dashboard in production mode"
53+
make run

hack/develop/run-npm-on-container.sh renamed to hack/develop/run-dev-container.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2525
# User and group ID to execute commands.
2626
LOCAL_UID=$(id -u)
2727
LOCAL_GID=$(id -g)
28+
DOCKER_GID=$(getent group docker|cut -d ":" -f 3)
2829

2930
# K8S_DASHBOARD_NPM_CMD will be passed into container and will be used
3031
# by run-npm-command.sh on container. Then the shell sciprt will run `npm`
@@ -95,11 +96,13 @@ docker run \
9596
-e K8S_DASHBOARD_CMD="${K8S_DASHBOARD_CMD}" \
9697
-e K8S_OWN_CLUSTER=${K8S_OWN_CLUSTER} \
9798
-e K8S_DASHBOARD_BIND_ADDRESS=${K8S_DASHBOARD_BIND_ADDRESS} \
98-
-e K8S_DASHBOARD_SIDECAR_HOST=${K8S_DASHBOARD_SIDECAR_HOST} \
9999
-e K8S_DASHBOARD_PORT=${K8S_DASHBOARD_PORT} \
100100
-e K8S_DASHBOARD_DEBUG=${K8S_DASHBOARD_DEBUG} \
101+
-e KUBECONFIG=${K8S_DASHBOARD_KUBECONFIG} \
102+
-e SIDECAR_HOST=${K8S_DASHBOARD_SIDECAR_HOST} \
101103
-e LOCAL_UID="${LOCAL_UID}" \
102104
-e LOCAL_GID="${LOCAL_GID}" \
105+
-e DOCKER_GID="${DOCKER_GID}" \
103106
-p ${K8S_DASHBOARD_PORT}:${K8S_DASHBOARD_PORT} \
104107
-p ${K8S_DASHBOARD_DEBUG_PORT}:${K8S_DASHBOARD_DEBUG_PORT} \
105108
${DOCKER_RUN_OPTS} \

modules/web/i18n/ja/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ Kubernetes Dashboard の和訳を実施するにあたって、下記の配慮
112112
* **[和訳ファイル](./messages.ja.xlf)`<target>` タグの中身を和訳/修正します。
113113
原文は `<source>` タグで、これにあたる和訳/修正を実施します。
114114
その際、翻訳済みである印として、`<target>` タグ内に `state="new"` の属性があれば、この属性を削除します。**
115-
* `npm run start:prod` を実行して Kubernetes Dashboard をビルド、実行して、和訳/修正した結果をブラウザから確認します。
116-
+ Dashboard の開発環境コンテナを利用して`kind` を利用した Kubernetes クラスタの構築、Dashboard のビルドと起動を一括で行うには、下記を実行します。
115+
* `make run` を実行して Kubernetes Dashboard をビルド、実行して、和訳/修正した結果をブラウザから確認します。
116+
+ Dashboard の開発環境コンテナを利用して Dashboard をビルドし、ご自身の Kubernetes クラスタに接続する Dashboard を起動するには、下記を実行します。
117117
> :warning: **`K8S_DASHBOARD_BIND_ADDRESS=0.0.0.0`を付けることで、Dashboard はコンテナ外部からのアクセスを許可しています。信頼できるネットワーク上にある環境で実行してください。**
118118
119-
`K8S_DASHBOARD_BIND_ADDRESS=0.0.0.0 aio/develop/run-npm-on-container.sh`
119+
`K8S_DASHBOARD_KUBECONFIG=<path to kubeconfig file> K8S_DASHBOARD_BIND_ADDRESS=0.0.0.0 hack/develop/run-dev-container.sh`
120120
* Pull Request を `kubernetes/dashboard` リポジトリに提出します。
121121
* 新たに翻訳すべき原文の追加や修正が発生しているかは、[`kubernetes/dashboard` リポジトリの`language/ja` ラベルが付いた Pull Request](https://github.com/kubernetes/dashboard/pulls?utf8=%E2%9C%93&q=is%3Apr+label%3Alanguage%2Fja) を監視することで行います。
122122

0 commit comments

Comments
 (0)