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

Commit bc044c9

Browse files
authored
Merge pull request #35 from Shikanime/master
Fix kubernete-helm certificates
2 parents 543b220 + 0220ff5 commit bc044c9

File tree

3 files changed

+61
-32
lines changed

3 files changed

+61
-32
lines changed

containers/kubernetes-helm/.devcontainer/Dockerfile

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,23 @@ RUN curl -s https://raw.githubusercontent.com/helm/helm/master/scripts/get | bas
3535

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.
38-
RUN echo 'if [ "$SYNC_LOCALHOST_KUBECONFIG" == "true" ]; then \
39-
mkdir -p $HOME/.kube \
40-
&& cp -r $HOME/.kube-localhost/* $HOME/.kube \
41-
&& sed -i -e "s/localhost/host.docker.internal/g" $HOME/.kube/config; \
42-
fi' >> $HOME/.bashrc
38+
RUN echo '\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\
53+
fi' \
54+
>> $HOME/.bashrc
4355

4456
# Clean up
4557
RUN apt-get autoremove -y \
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
{
2-
"name": "Kubernetes & Helm",
3-
"dockerFile": "Dockerfile",
4-
"extensions": [
5-
"peterjausovec.vscode-docker",
6-
"ms-kubernetes-tools.vscode-kubernetes-tools"
7-
],
8-
"runArgs": [
9-
"-e", "SYNC_LOCALHOST_KUBECONFIG=true",
10-
"-v", "/var/run/docker.sock:/var/run/docker.sock",
11-
"-v", "${env:HOME}${env:USERPROFILE}/.kube:/root/.kube-localhost",
2+
"name": "Kubernetes & Helm",
3+
"dockerFile": "Dockerfile",
4+
"extensions": [
5+
"peterjausovec.vscode-docker",
6+
"ms-kubernetes-tools.vscode-kubernetes-tools"
7+
],
8+
"runArgs": [
9+
"-e", "SYNC_LOCALHOST_KUBECONFIG=true",
10+
"--mount", "type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock",
11+
"--mount", "type=bind,source=${env:HOME}${env:USERPROFILE}/.kube,target=/root/.kube-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"
15+
16+
// Uncomment the next line if you will use a ptrace-based debugger like C++, Go, and Rust.
17+
// "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"
18+
],
1219

13-
// Uncomment the next line if you will use a ptrace-based debugger like C++, Go, and Rust.
14-
// "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"
15-
],
16-
1720
// Uncomment the next line if you want to publish any ports.
1821
// "appPort": [],
1922

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

23-
}
26+
}

containers/kubernetes-helm/README.md

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

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

95-
### macOS / Windows
107+
### macOS / Windows
96108

97109
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.
98110

@@ -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)