Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit caa0cc4

Browse files
committed
Add optionnal volume binding for Minikube
1 parent 0825ec4 commit caa0cc4

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

containers/kubernetes-helm/.devcontainer/Dockerfile

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,20 @@ RUN curl -s https://raw.githubusercontent.com/helm/helm/master/scripts/get | bas
3636
# Copy localhost's ~/.kube/config file into the container and swap out localhost
3737
# for host.docker.internal whenever a new shell starts to keep them in sync.
3838
RUN echo '\n\
39-
mkdir -p $HOME/.kube\n\
40-
cp -r $HOME/.kube-localhost/* $HOME/.kube\n\
41-
sed -i -e "s/localhost/host.docker.internal/g" $HOME/.kube/config' \
42-
>> $HOME/.bashrc
43-
44-
# Copy localhost's minikube certificate file into the container and swap out localhost
45-
RUN echo '\n\
46-
mkdir -p $HOME/.minikube\n\
47-
if [[ -f "$HOME/.minikube-localhost/ca.crt" ]]; then\n\
48-
cp -r $HOME/.minikube-localhost/ca.crt $HOME/.minikube\n\
49-
sed -i -r "s|(\s*certificate-authority:\s).*|\\1$HOME\/.minikube\/ca.crt|g" $HOME/.kube/config\n\
50-
fi\n\
51-
if [[ -f "$HOME/.minikube-localhost/client.crt" ]]; then\n\
52-
cp -r $HOME/.minikube-localhost/client.crt $HOME/.minikube\n\
53-
sed -i -r "s|(\s*client-certificate:\s).*|\\1$HOME\/.minikube\/client.crt|g" $HOME/.kube/config\n\
54-
fi\n\
55-
if [[ -f "$HOME/.minikube-localhost/client.key" ]]; then\n\
56-
cp -r $HOME/.minikube-localhost/client.key $HOME/.minikube\n\
57-
sed -i -r "s|(\s*client-key:\s).*|\\1$HOME\/.minikube\/client.key|g" $HOME/.kube/config\n\
39+
if [ "$SYNC_LOCALHOST_KUBECONFIG" == "true" ]; then\n\
40+
mkdir -p $HOME/.kube\n\
41+
cp -r $HOME/.kube-localhost/* $HOME/.kube\n\
42+
sed -i -e "s/localhost/host.docker.internal/g" $HOME/.kube/config\n\
43+
\n\
44+
if [ -d "$HOME/.minikube-localhost" ]; then\n\
45+
mkdir -p $HOME/.minikube\n\
46+
cp -r $HOME/.minikube-localhost/ca.crt $HOME/.minikube\n\
47+
sed -i -r "s|(\s*certificate-authority:\s).*|\\1$HOME\/.minikube\/ca.crt|g" $HOME/.kube/config\n\
48+
cp -r $HOME/.minikube-localhost/client.crt $HOME/.minikube\n\
49+
sed -i -r "s|(\s*client-certificate:\s).*|\\1$HOME\/.minikube\/client.crt|g" $HOME/.kube/config\n\
50+
cp -r $HOME/.minikube-localhost/client.key $HOME/.minikube\n\
51+
sed -i -r "s|(\s*client-key:\s).*|\\1$HOME\/.minikube\/client.key|g" $HOME/.kube/config\n\
52+
fi\n\
5853
fi' \
5954
>> $HOME/.bashrc
6055

containers/kubernetes-helm/.devcontainer/devcontainer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
"ms-kubernetes-tools.vscode-kubernetes-tools"
77
],
88
"runArgs": [
9+
"-e", "SYNC_LOCALHOST_KUBECONFIG=true",
910
"--mount", "type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock",
1011
"--mount", "type=bind,source=${env:HOME}${env:USERPROFILE}/.kube,target=/root/.kube-localhost",
11-
"-v", "${env:HOME}${env:USERPROFILE}/.minikube:/root/.minikube-localhost"
12+
13+
// Uncomment the next line to also sync certs in your .minikube folder
14+
// "--mount", "type=bind,source=${env:HOME}${env:USERPROFILE}/.minikube,target=/root/.minikube-localhost"
1215

1316
// Uncomment the next line if you will use a ptrace-based debugger like C++, Go, and Rust.
1417
// "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"

containers/kubernetes-helm/README.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
| Metadata | Value |
88
|----------|-------|
9-
| *Contributors* | The VS Code team |
9+
| *Contributors* | The VS Code team and Phetsinorath William |
1010
| *Definition type* | Dockerfile |
1111
| *Languages, platforms* | Any |
1212

@@ -50,14 +50,26 @@ You can adapt your own existing development container Dockerfile to support this
5050
"-v", "$HOME/.kube:/root/.kube-localhost"]
5151
```
5252

53-
3. Update `.bashrc` to automatically swap out localhost for host.docker.internal in a containr copy of the Kubernetes config. From `.devcontainer/Dockerfile`:
53+
3. Update `.bashrc` to automatically swap out localhost for host.docker.internal in a container copy of the Kubernetes config and optionally Minikube certificates if the volume is enabled. From `.devcontainer/Dockerfile`:
5454

5555
```Dockerfile
56-
RUN echo 'if [ "$SYNC_LOCALHOST_KUBECONFIG" == "true" ]; then \
57-
mkdir -p $HOME/.kube \
58-
&& cp -r $HOME/.kube-localhost/* $HOME/.kube \
59-
&& sed -i -e "s/localhost/host.docker.internal/g" $HOME/.kube/config; \
60-
fi' >> $HOME/.bashrc
56+
RUN echo '\n\
57+
if [ "$SYNC_LOCALHOST_KUBECONFIG" == "true" ]; then\n\
58+
mkdir -p $HOME/.kube\n\
59+
cp -r $HOME/.kube-localhost/* $HOME/.kube\n\
60+
sed -i -e "s/localhost/host.docker.internal/g" $HOME/.kube/config\n\
61+
\n\
62+
if [ -d "$HOME/.minikube-localhost" ]; then\n\
63+
mkdir -p $HOME/.minikube\n\
64+
cp -r $HOME/.minikube-localhost/ca.crt $HOME/.minikube\n\
65+
sed -i -r "s|(\s*certificate-authority:\s).*|\\1$HOME\/.minikube\/ca.crt|g" $HOME/.kube/config\n\
66+
cp -r $HOME/.minikube-localhost/client.crt $HOME/.minikube\n\
67+
sed -i -r "s|(\s*client-certificate:\s).*|\\1$HOME\/.minikube\/client.crt|g" $HOME/.kube/config\n\
68+
cp -r $HOME/.minikube-localhost/client.key $HOME/.minikube\n\
69+
sed -i -r "s|(\s*client-key:\s).*|\\1$HOME\/.minikube\/client.key|g" $HOME/.kube/config\n\
70+
fi\n\
71+
fi' \
72+
>> $HOME/.bashrc
6173
```
6274

6375
5. Add a container specific user settings file that forces the Docker extension to be installed inside the container instead of locally. From `.devcontainer/Dockerfile`:
@@ -119,10 +131,10 @@ Follow the steps below for your operating system to use the definition.
119131
helm init
120132
```
121133
122-
## Linux Setup
134+
## Linux/Minikube Setup
123135
124136
1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine.
125-
137+
126138
2. Install [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) and [Minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/) on your local OS if you have not already.
127139
128140
3. Start Minikube as follows:
@@ -143,9 +155,11 @@ Follow the steps below for your operating system to use the definition.
143155

144156
6. After following step 2 or 3, the contents of the `.devcontainer` folder in your project can be adapted to meet your needs.
145157

146-
7. Finally, press <kbd>F1</kbd> and run **Remote-Containers: Reopen Folder in Container** to start using the definition.
158+
7. Open `.devcontainer/devcontainer.json` and uncomment the minikube volume binding.
147159

148-
8. [Optional] If you want to use [Helm](https://helm.sh), open a VS Code terminal and run:
160+
8. Finally, press <kbd>F1</kbd> and run **Remote-Containers: Reopen Folder in Container** to start using the definition.
161+
162+
9. [Optional] If you want to use [Helm](https://helm.sh), open a VS Code terminal and run:
149163
```
150164
helm init
151165
```

0 commit comments

Comments
 (0)