From e15c0a55e822304d1a7b27b526c7bdeb17b04b32 Mon Sep 17 00:00:00 2001 From: Chuck Lantz Date: Tue, 5 Feb 2019 19:36:38 -0800 Subject: [PATCH] Kubernetes + Helm container --- .../.vscode/devContainer.json | 10 +++ .../kubernetes-helm-container/README.md | 85 +++++++++++++++++++ .../dev-container.dockerfile | 35 ++++++++ 3 files changed, 130 insertions(+) create mode 100644 dev-containers/kubernetes-helm-container/.vscode/devContainer.json create mode 100644 dev-containers/kubernetes-helm-container/README.md create mode 100644 dev-containers/kubernetes-helm-container/dev-container.dockerfile diff --git a/dev-containers/kubernetes-helm-container/.vscode/devContainer.json b/dev-containers/kubernetes-helm-container/.vscode/devContainer.json new file mode 100644 index 0000000000..f16383009c --- /dev/null +++ b/dev-containers/kubernetes-helm-container/.vscode/devContainer.json @@ -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"] +} \ No newline at end of file diff --git a/dev-containers/kubernetes-helm-container/README.md b/dev-containers/kubernetes-helm-container/README.md new file mode 100644 index 0000000000..548927629e --- /dev/null +++ b/dev-containers/kubernetes-helm-container/README.md @@ -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 + ``` diff --git a/dev-containers/kubernetes-helm-container/dev-container.dockerfile b/dev-containers/kubernetes-helm-container/dev-container.dockerfile new file mode 100644 index 0000000000..94022188ce --- /dev/null +++ b/dev-containers/kubernetes-helm-container/dev-container.dockerfile @@ -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/*