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

Commit

Permalink
Merge pull request #35 from Shikanime/master
Browse files Browse the repository at this point in the history
Fix kubernete-helm certificates
  • Loading branch information
Chuxel committed May 22, 2019
2 parents 543b220 + 0220ff5 commit bc044c9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 32 deletions.
22 changes: 17 additions & 5 deletions containers/kubernetes-helm/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,23 @@ 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 '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

# Clean up
RUN apt-get autoremove -y \
Expand Down
33 changes: 18 additions & 15 deletions containers/kubernetes-helm/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"name": "Kubernetes & Helm",
"dockerFile": "Dockerfile",
"extensions": [
"peterjausovec.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools"
],
"runArgs": [
"-e", "SYNC_LOCALHOST_KUBECONFIG=true",
"-v", "/var/run/docker.sock:/var/run/docker.sock",
"-v", "${env:HOME}${env:USERPROFILE}/.kube:/root/.kube-localhost",
"name": "Kubernetes & Helm",
"dockerFile": "Dockerfile",
"extensions": [
"peterjausovec.vscode-docker",
"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",

// 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"
],

// 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"
],

// Uncomment the next line if you want to publish any ports.
// "appPort": [],

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "kubectl version"

}
}
38 changes: 26 additions & 12 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 @@ -92,7 +104,7 @@ In addition, if you want to **disable sync'ing** local Kubernetes config into th

Follow the steps below for your operating system to use the definition.

### macOS / Windows
### macOS / Windows

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.

Expand All @@ -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 bc044c9

Please sign in to comment.