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

Commit

Permalink
Add optionnal volume binding for Minikube
Browse files Browse the repository at this point in the history
  • Loading branch information
shikanime committed May 22, 2019
1 parent 0825ec4 commit caa0cc4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
33 changes: 14 additions & 19 deletions containers/kubernetes-helm/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,20 @@ RUN curl -s https://raw.githubusercontent.com/helm/helm/master/scripts/get | bas
# Copy localhost's ~/.kube/config file into the container and swap out localhost
# for host.docker.internal whenever a new shell starts to keep them in sync.
RUN echo '\n\
mkdir -p $HOME/.kube\n\
cp -r $HOME/.kube-localhost/* $HOME/.kube\n\
sed -i -e "s/localhost/host.docker.internal/g" $HOME/.kube/config' \
>> $HOME/.bashrc

# Copy localhost's minikube certificate file into the container and swap out localhost
RUN echo '\n\
mkdir -p $HOME/.minikube\n\
if [[ -f "$HOME/.minikube-localhost/ca.crt" ]]; then\n\
cp -r $HOME/.minikube-localhost/ca.crt $HOME/.minikube\n\
sed -i -r "s|(\s*certificate-authority:\s).*|\\1$HOME\/.minikube\/ca.crt|g" $HOME/.kube/config\n\
fi\n\
if [[ -f "$HOME/.minikube-localhost/client.crt" ]]; then\n\
cp -r $HOME/.minikube-localhost/client.crt $HOME/.minikube\n\
sed -i -r "s|(\s*client-certificate:\s).*|\\1$HOME\/.minikube\/client.crt|g" $HOME/.kube/config\n\
fi\n\
if [[ -f "$HOME/.minikube-localhost/client.key" ]]; then\n\
cp -r $HOME/.minikube-localhost/client.key $HOME/.minikube\n\
sed -i -r "s|(\s*client-key:\s).*|\\1$HOME\/.minikube\/client.key|g" $HOME/.kube/config\n\
if [ "$SYNC_LOCALHOST_KUBECONFIG" == "true" ]; then\n\
mkdir -p $HOME/.kube\n\
cp -r $HOME/.kube-localhost/* $HOME/.kube\n\
sed -i -e "s/localhost/host.docker.internal/g" $HOME/.kube/config\n\
\n\
if [ -d "$HOME/.minikube-localhost" ]; then\n\
mkdir -p $HOME/.minikube\n\
cp -r $HOME/.minikube-localhost/ca.crt $HOME/.minikube\n\
sed -i -r "s|(\s*certificate-authority:\s).*|\\1$HOME\/.minikube\/ca.crt|g" $HOME/.kube/config\n\
cp -r $HOME/.minikube-localhost/client.crt $HOME/.minikube\n\
sed -i -r "s|(\s*client-certificate:\s).*|\\1$HOME\/.minikube\/client.crt|g" $HOME/.kube/config\n\
cp -r $HOME/.minikube-localhost/client.key $HOME/.minikube\n\
sed -i -r "s|(\s*client-key:\s).*|\\1$HOME\/.minikube\/client.key|g" $HOME/.kube/config\n\
fi\n\
fi' \
>> $HOME/.bashrc

Expand Down
5 changes: 4 additions & 1 deletion containers/kubernetes-helm/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
"ms-kubernetes-tools.vscode-kubernetes-tools"
],
"runArgs": [
"-e", "SYNC_LOCALHOST_KUBECONFIG=true",
"--mount", "type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock",
"--mount", "type=bind,source=${env:HOME}${env:USERPROFILE}/.kube,target=/root/.kube-localhost",
"-v", "${env:HOME}${env:USERPROFILE}/.minikube:/root/.minikube-localhost"

// Uncomment the next line to also sync certs in your .minikube folder
// "--mount", "type=bind,source=${env:HOME}${env:USERPROFILE}/.minikube,target=/root/.minikube-localhost"

// Uncomment the next line if you will use a ptrace-based debugger like C++, Go, and Rust.
// "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"
Expand Down
36 changes: 25 additions & 11 deletions containers/kubernetes-helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

| Metadata | Value |
|----------|-------|
| *Contributors* | The VS Code team |
| *Contributors* | The VS Code team and Phetsinorath William |
| *Definition type* | Dockerfile |
| *Languages, platforms* | Any |

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

3. Update `.bashrc` to automatically swap out localhost for host.docker.internal in a containr copy of the Kubernetes config. From `.devcontainer/Dockerfile`:
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`:

```Dockerfile
RUN echo 'if [ "$SYNC_LOCALHOST_KUBECONFIG" == "true" ]; then \
mkdir -p $HOME/.kube \
&& cp -r $HOME/.kube-localhost/* $HOME/.kube \
&& sed -i -e "s/localhost/host.docker.internal/g" $HOME/.kube/config; \
fi' >> $HOME/.bashrc
RUN echo '\n\
if [ "$SYNC_LOCALHOST_KUBECONFIG" == "true" ]; then\n\
mkdir -p $HOME/.kube\n\
cp -r $HOME/.kube-localhost/* $HOME/.kube\n\
sed -i -e "s/localhost/host.docker.internal/g" $HOME/.kube/config\n\
\n\
if [ -d "$HOME/.minikube-localhost" ]; then\n\
mkdir -p $HOME/.minikube\n\
cp -r $HOME/.minikube-localhost/ca.crt $HOME/.minikube\n\
sed -i -r "s|(\s*certificate-authority:\s).*|\\1$HOME\/.minikube\/ca.crt|g" $HOME/.kube/config\n\
cp -r $HOME/.minikube-localhost/client.crt $HOME/.minikube\n\
sed -i -r "s|(\s*client-certificate:\s).*|\\1$HOME\/.minikube\/client.crt|g" $HOME/.kube/config\n\
cp -r $HOME/.minikube-localhost/client.key $HOME/.minikube\n\
sed -i -r "s|(\s*client-key:\s).*|\\1$HOME\/.minikube\/client.key|g" $HOME/.kube/config\n\
fi\n\
fi' \
>> $HOME/.bashrc
```

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`:
Expand Down Expand Up @@ -119,10 +131,10 @@ Follow the steps below for your operating system to use the definition.
helm init
```

## Linux Setup
## Linux/Minikube Setup

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.

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.

3. Start Minikube as follows:
Expand All @@ -143,9 +155,11 @@ Follow the steps below for your operating system to use the definition.

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

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

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

9. [Optional] If you want to use [Helm](https://helm.sh), open a VS Code terminal and run:
```
helm init
```
Expand Down

0 comments on commit caa0cc4

Please sign in to comment.