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

Commit

Permalink
Kubernetes + Helm container
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuxel committed Feb 6, 2019
1 parent 44e36e2 commit e15c0a5
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dev-containers/kubernetes-helm-container/.vscode/devContainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"dockerFile": "dev-container.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", "$HOME/.kube:/root/.kube-localhost"]
}
85 changes: 85 additions & 0 deletions dev-containers/kubernetes-helm-container/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Kubernetes and Helm Container

This sample dev container allows you to work with Kubernetes clusters and use the Kubernetes extension from within the container!

The container includes the kubectl for Kubernetes, Helm, and the Docker CLI and can be easily set up to work with a local Minikube install. Just follow the steps below for your operating system.


## macOS Setup

1. Install "Docker Desktop for Mac" locally if you have not.

2. Start Docker, right-click on the Docker icon and select "Preferences..."

3. Check **Kubernetes > Enable Kubernetes**

4. Open this folder in VS Code

5. Edit `.vscode/devConatiner.json` and change `$HOME` in the last item in the `runArgs` array to the absolute path of your home folder. e.g.
```
"runArgs": ["-e", "SYNC_LOCALHOST_KUBECONFIG=true",
"-v","/var/run/docker.sock:/var/run/docker.sock",
"-v", "/Users/clantz/.kube:/root/.kube-localhost"]
```
> **Note:** Resolving [vscode-remote#670](https://github.com/Microsoft/vscode-remote/issues/670) will remove this step.
6. Run the **Remote: Reopen folder in Container** command. Once connected, you should see your clusters in the Kubernetes explorer.

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

## Windows Setup

1. Install "Docker Desktop for Windows" locally if you have not.

2. Right Click on Docker system tray icon and select "Settings"

3. Check **General > "Expose daemon on tcp://localhost:2375 without TLS"**

4. Check **Kubernetes > Enable Kubernetes**

5. Open this folder in VS Code

6. Edit `.vscode/devConatiner.json` replace the **entire** contents `runArgs` of with the following. Replace `C:\\Users\\clantz\\` with the path your your user directory.
```
"runArgs": ["-e", "SYNC_LOCALHOST_KUBECONFIG=true",
"-e", "DOCKER_HOST=tcp://host.docker.internal:2375",
"-v", "C:\\Users\\clantz\\.kube:/root/.kube-localhost"]
```
> **Note:** Resolving [vscode-remote#670](https://github.com/Microsoft/vscode-remote/issues/670) and [vscode-remote#669](https://github.com/Microsoft/vscode-remote/issues/669) will remove this step.
7. Run the **Remote: Reopen folder in Container** command. Once connected, you should see your clusters in the Kubernetes explorer.

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

## Linux Setup

1. Install [Docker CE](https://docs.docker.com/install/linux/docker-ce/ubuntu/), [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.

2. Start Minikube as follows:
```
minikube start
kubectl config set-context minikube
```

4. Open this folder in VS Code

5. Edit `.vscode/devConatiner.json` and change `$HOME` in the last item in the `runArgs` array to the absolute path of your home folder. e.g.
```
"runArgs": ["-e", "SYNC_LOCALHOST_KUBECONFIG=true",
"-v","/var/run/docker.sock:/var/run/docker.sock",
"-v", "/home/clantz/.kube:/root/.kube-localhost"]
```
> **Note:** Resolving [vscode-remote#670](https://github.com/Microsoft/vscode-remote/issues/670) will remove this step.
6. Run the **Remote: Reopen folder in Container** command. Once connected, you should see your clusters in the Kubernetes explorer.

7. [Optional] If you want to use [Helm](https://helm.sh), open a VS Code terminal and run:
```
helm init
```
35 changes: 35 additions & 0 deletions dev-containers/kubernetes-helm-container/dev-container.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM ubuntu:latest

# Install required tools
RUN apt-get update \
&& apt-get install -y git

# Install Docker CE CLI
RUN apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
&& apt-get update \
&& apt-get install -y docker-ce-cli

# Install kubectl
RUN curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - \
&& echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list \
&& apt-get update \
&& apt-get install -y kubectl

# Install Helm
RUN curl -s https://raw.githubusercontent.com/helm/helm/master/scripts/get | bash -

# 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

# Clean up
RUN apt-get autoremove -y \
&& apt-get clean -y \
&& apt-get autoclean -y \
&& rm -rf /var/lib/apt/lists/*

0 comments on commit e15c0a5

Please sign in to comment.