- Notifications
You must be signed in to change notification settings - Fork646
add initial k8s instructions#71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionsdeploy-k8s/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
code-server/ |
11 changes: 11 additions & 0 deletionsdeploy-k8s/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# deploy-k8s | ||
Some helper scripts and example images for deploying to Kubernetes. These are still a work in progress and the images do not have CI/CD set up. | ||
Note: This is a quick way to get up and running with code-server Helm charts. We recommend managing these workspaces with something other than bash scripts 😂 | ||
1. Ensure you have kubectl, helm, installed and your kube context is pointed at an active cluster. | ||
1. Clone this repo and run `init.sh` to clone code-server | ||
1. Build the images with `build-images.sh`. | ||
1. Edit the examples in `workspaces/` to use your images | ||
1. Run `provision-workspaces.sh` and then `get-deployments.sh` |
31 changes: 31 additions & 0 deletionsdeploy-k8s/build-images.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/sh | ||
# This will build and push public images in the images/ folder to | ||
# DockerHub based on your Docker username with the | ||
# format: $username/dev-env-$folder:latest | ||
set -e | ||
docker_username=$(docker-credential-$(jq -r .credsStore ~/.docker/config.json) list | jq -r '. | to_entries[] | select(.key | contains("docker.io")) | last(.value)') | ||
build_and_push() { | ||
folder=$1 | ||
basename=$(basename -- "$folder") | ||
name=${basename%.*} | ||
docker build $folder -t bencdr/dev-env-$name:latest | ||
docker push $docker_username/dev-env-$name:latest | ||
} | ||
build_and_push "images/base" | ||
# Build all other images in the images/ folder | ||
# note: if you have multiple base images or heirchal images | ||
# you'll want to build them in a controlled order above and | ||
# exclude them. can be comma or space seperated :) | ||
exclude="images/base" | ||
for folder in images/*; do | ||
if [[ ! "$exclude" == *"$folder"* ]]; then | ||
build_and_push $folder | ||
fi | ||
done |
10 changes: 10 additions & 0 deletionsdeploy-k8s/extras/new-image.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
# This creates a new image folder and opens it in | ||
# VS Code, if you have it installed | ||
cp -r images/frontend images/new | ||
if command -v code &> /dev/null; then | ||
code images/new/Dockerfile | ||
fi |
10 changes: 10 additions & 0 deletionsdeploy-k8s/extras/new-workspace.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
# This creates a new workspace file and opens it in | ||
# VS Code, if you have it installed | ||
cp workspaces/ben.yaml workspaces/new.yaml | ||
if command -v code &> /dev/null; then | ||
code workspaces/new.yaml | ||
fi |
22 changes: 22 additions & 0 deletionsdeploy-k8s/get-deployments.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
# This will look in your workspaces/ folder and | ||
# look up the helm deployments in a basic manner | ||
get_deployment() { | ||
name=$1 | ||
ip=$(kubectl get svc $name-dev-code-server -o jsonpath='{.status.loadBalancer.ingress[0].ip}') | ||
port=$(kubectl get svc $name-dev-code-server -o jsonpath='{.spec.ports[0].port}') | ||
image=$(helm get values $name-dev -o json | jq .image.repository) | ||
echo "$name (image: $image)" | ||
echo "http://$ip:$port" | ||
echo $(kubectl get secret $name-dev-code-server -o jsonpath="{.data.password}" | base64 --decode) | ||
echo "---" | ||
} | ||
for file in workspaces/*.yaml; do | ||
basename=$(basename -- "$file") | ||
name=${basename%.*} | ||
get_deployment $name | ||
done |
12 changes: 12 additions & 0 deletionsdeploy-k8s/images/base/Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM codercom/code-server:3.12.0 | ||
# Install Homebrew, must be as a non-root user | ||
RUN /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | ||
ENV PATH /home/linuxbrew/.linuxbrew/bin:${PATH} | ||
USER root | ||
RUN apt-get update && \ | ||
apt-get install -y python3 python3-pip | ||
USER coder |
37 changes: 37 additions & 0 deletionsdeploy-k8s/images/devops/Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
FROM bencdr/dev-env-base:latest | ||
USER root | ||
RUN apt-get update | ||
RUN apt-get install -y apt-transport-https gnupg | ||
# Install kubectl | ||
RUN curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg && \ | ||
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list && \ | ||
apt-get update && apt-get install -y kubectl | ||
# Install helm | ||
RUN curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash | ||
# Install gcloud | ||
RUN curl -fsSLo /usr/share/keyrings/cloud.google.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg && \ | ||
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \ | ||
apt-get update && apt-get install -y google-cloud-sdk | ||
# Install AWS CLI | ||
RUN pip3 install awscli | ||
USER coder | ||
# Install terraform | ||
RUN brew tap hashicorp/tap && \ | ||
brew install hashicorp/tap/terraform | ||
# Install kubectx | ||
RUN brew install kubectl | ||
# Install Docker | ||
RUN sudo apt-get install -y docker.io systemd systemd-sysv | ||
RUN systemctl enable docker | ||
USER coder |
13 changes: 13 additions & 0 deletionsdeploy-k8s/images/frontend/Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM bencdr/dev-env-base:latest | ||
USER root | ||
# Install Node.js | ||
ARG NODE_VERSION=14 | ||
RUN curl -sL "https://deb.nodesource.com/setup_$NODE_VERSION.x" | bash - | ||
RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y nodejs | ||
# Install yarn | ||
RUN npm install -g yarn | ||
USER coder |
24 changes: 24 additions & 0 deletionsdeploy-k8s/init.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
# This will create a namespace on your cluster | ||
# and ensure you have the proper commands. | ||
# It will also clone code server so that you | ||
# can use the helmchart :) | ||
NAMESPACE=${NAMESPACE:-dev-envs} | ||
git clone https://github.com/cdr/code-server | ||
kubectl create namespace $NAMESPACE | ||
./set-namespace.sh $NAMESPACE | ||
if ! command -v helm &> /dev/null; then | ||
echo "! Please install the helm: https://helm.sh/docs/intro/install/" | ||
exit | ||
fi | ||
if ! command -v jq &> /dev/null; then | ||
echo "! Please install the yq command: https://stedolan.github.io/jq/" | ||
exit | ||
fi |
18 changes: 18 additions & 0 deletionsdeploy-k8s/provision-workspaces.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/sh | ||
# This will create/update helm deployments based | ||
# on the charts in your workspaces folder. | ||
# To create a new deployment: clone a chart, | ||
# modify accordingly, and run this script. | ||
for file in workspaces/*.yaml; do | ||
basename=$(basename -- "$file") | ||
name=${basename%.*} | ||
helm upgrade --install $name-dev code-server/ci/helm-chart --values $file | ||
# restart the pods to grab the latest version | ||
# this is not needed if you version-control images | ||
kubectl rollout restart deployment $name-dev-code-server | ||
echo "---" | ||
done |
8 changes: 8 additions & 0 deletionsdeploy-k8s/set-namespace.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/sh | ||
# Pretty lame, but helpful command :) | ||
# kubens is cool too. | ||
# ex: ./set-namespace.sh dev-envs | ||
kubectl config set-context --current --namespace=$1 |
90 changes: 90 additions & 0 deletionsdeploy-k8s/workspaces/ben.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
replicaCount: 1 | ||
hostnameOverride: "ben-dev" | ||
image: | ||
repository: bencdr/dev-env-devops | ||
tag: "latest" | ||
pullPolicy: Always | ||
resources: | ||
limits: | ||
cpu: 2000m | ||
memory: 8000Mi | ||
requests: | ||
cpu: 500m | ||
memory: 1000Mi | ||
persistence: | ||
enabled: true | ||
accessMode: ReadWriteOnce | ||
size: 10Gi | ||
annotations: {} | ||
extraContainers: | | ||
- name: docker-dind | ||
image: docker:20.10-dind | ||
imagePullPolicy: IfNotPresent | ||
resources: | ||
requests: | ||
cpu: 250m | ||
memory: 256M | ||
securityContext: | ||
privileged: true | ||
procMount: Default | ||
env: | ||
- name: DOCKER_TLS_CERTDIR | ||
value: "" | ||
- name: DOCKER_DRIVER | ||
value: "overlay2" | ||
volumePermissions: | ||
enabled: true | ||
securityContext: | ||
runAsUser: 0 | ||
securityContext: | ||
enabled: true | ||
fsGroup: 1000 | ||
runAsUser: 1000 | ||
service: | ||
type: LoadBalancer | ||
port: 8080 | ||
ingress: | ||
enabled: false | ||
#annotations: | ||
# kubernetes.io/ingress.class: nginx | ||
# kubernetes.io/tls-acme: "true" | ||
#hosts: | ||
# - host: code-server.example.loc | ||
# paths: | ||
# - / | ||
#tls: | ||
# - secretName: code-server | ||
# hosts: | ||
# - code-server.example.loc | ||
extraArgs: [] | ||
extraVars: | ||
- name: DOCKER_HOST | ||
value: tcp://localhost:2375 | ||
nodeSelector: {} | ||
tolerations: [] | ||
affinity: {} | ||
extraSecretMounts: [] | ||
extraVolumeMounts: [] | ||
hostPath: "" | ||
extraConfigmapMounts: [] | ||
serviceAccount: | ||
create: false |
70 changes: 70 additions & 0 deletionsdeploy-k8s/workspaces/jordan.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
replicaCount: 1 | ||
hostnameOverride: "jordan-dev" | ||
image: | ||
repository: bencdr/dev-env-frontend | ||
tag: "latest" | ||
pullPolicy: Always | ||
resources: | ||
limits: | ||
cpu: 4000m | ||
memory: 8000Mi | ||
requests: | ||
cpu: 1000m | ||
memory: 2000Mi | ||
persistence: | ||
enabled: true | ||
accessMode: ReadWriteOnce | ||
size: 10Gi | ||
annotations: {} | ||
volumePermissions: | ||
enabled: true | ||
securityContext: | ||
runAsUser: 0 | ||
securityContext: | ||
enabled: true | ||
fsGroup: 1000 | ||
runAsUser: 1000 | ||
service: | ||
type: LoadBalancer | ||
port: 8083 | ||
ingress: | ||
enabled: false | ||
#annotations: | ||
# kubernetes.io/ingress.class: nginx | ||
# kubernetes.io/tls-acme: "true" | ||
#hosts: | ||
# - host: code-server.example.loc | ||
# paths: | ||
# - / | ||
#tls: | ||
# - secretName: code-server | ||
# hosts: | ||
# - code-server.example.loc | ||
extraArgs: [] | ||
nodeSelector: {} | ||
tolerations: [] | ||
affinity: {} | ||
extraSecretMounts: [] | ||
extraVolumeMounts: [] | ||
hostPath: "" | ||
extraConfigmapMounts: [] | ||
serviceAccount: | ||
create: false |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.