update
This commit is contained in:
parent
65d88dcd01
commit
0294e0fb39
77
.drone.star
Normal file
77
.drone.star
Normal file
@ -0,0 +1,77 @@
|
||||
CODER_URL = "https://github.com/coder/coder/releases/download/v0.11.0/coder_0.11.0_linux_amd64.tar.gz"
|
||||
|
||||
TEMPLATES = {
|
||||
"base": {
|
||||
"android": {"image": "codercom/enterprise-android:ubuntu"},
|
||||
"kubernetes": {"image": "codercom/enterprise-base:ubuntu"},
|
||||
"python38": {"image": "cr.smcm.xyz/coder-images/python-38:latest"},
|
||||
"python311": {"image": "cr.smcm.xyz/coder-images/python-311:latest"},
|
||||
},
|
||||
"alpine": {
|
||||
"alpine": {"image": "cr.smcm.xyz/coder-images/alpine:latest"},
|
||||
"alpine-3.17": {"image": "cr.smcm.xyz/coder-images/alpine-3.17:latest"},
|
||||
"alpine-edge": {"image": "cr.smcm.xyz/coder-images/alpine-edge:latest"},
|
||||
},
|
||||
"splunk": {
|
||||
"appinspect": {"image": "cr.smcm.xyz/coder-images/python-38:latest"},
|
||||
},
|
||||
}
|
||||
|
||||
def get_jinja_command(template, output, context):
|
||||
jinja2args = " ".join(["-D {key}={value}".format(key = key, value = value) for (key, value) in context.items()])
|
||||
|
||||
return "/usr/local/bin/jinja2 {jinja2args} {template}.tf.ninja > {output}".format(
|
||||
jinja2args = jinja2args,
|
||||
template = template,
|
||||
output = output,
|
||||
)
|
||||
|
||||
def main(ctx):
|
||||
jinja_commands = []
|
||||
coder_commands = [
|
||||
"apk add git",
|
||||
"wget -q -O- {url} | tar -xzf - -C /usr/local/bin ./coder".format(url = CODER_URL),
|
||||
]
|
||||
|
||||
for jinja_template in TEMPLATES:
|
||||
jinja_template_file = "{name}.tf.jinja".format(name = jinja_template)
|
||||
|
||||
for coder_template in TEMPLATES[jinja_template]:
|
||||
jinja_commands.append("mkdir {name}".format(name = coder_template))
|
||||
jinja_commands.append(get_jinja_command(
|
||||
jinja_template_file,
|
||||
"{name}/main.tf".format(name = coder_template),
|
||||
TEMPLATES[jinja_template][coder_template],
|
||||
))
|
||||
|
||||
coder_commands.append(
|
||||
" || ".join([
|
||||
"coder templates push -d {name} --yes {name}".format(name = coder_template),
|
||||
"coder templates create -d {name} --yes {name}".format(name = coder_template),
|
||||
]),
|
||||
)
|
||||
|
||||
return {
|
||||
"kind": "pipeline",
|
||||
"name": "default",
|
||||
"type": "docker",
|
||||
"steps": [
|
||||
{
|
||||
"name": "generate templates",
|
||||
"image": "roquie/docker-jinja2-cli",
|
||||
"commands": jinja_commands,
|
||||
},
|
||||
{
|
||||
"name": "push templates",
|
||||
"image": "alpine:latest",
|
||||
"environment": {
|
||||
"CODER_URL": "http://coder.coder.svc.cluster.local",
|
||||
"CODER_SESSION_TOKEN": {
|
||||
"from_secret": "CODER_SESSION_TOKEN",
|
||||
},
|
||||
"CODER_TEMPLATE_VERSION": ctx.build.commit,
|
||||
},
|
||||
"commands": coder_commands,
|
||||
},
|
||||
],
|
||||
}
|
||||
28
alpine.tf.jinja
Normal file
28
alpine.tf.jinja
Normal file
@ -0,0 +1,28 @@
|
||||
{% extends "base.tf.jinja" %}
|
||||
|
||||
{% block post_startup_script_setup_home %}
|
||||
# Clone the aports repository
|
||||
if [ ! -d aports ]; then
|
||||
git clone https://gitlab.alpinelinux.org/mcm/aports.git
|
||||
(
|
||||
cd aports
|
||||
git pull https://gitlab.alpinelinux.org/alpine/aports.git
|
||||
)
|
||||
fi
|
||||
|
||||
# Generate abuild keys if needed
|
||||
[ -e "$HOME/.abuild/abuild.conf" ] && . $HOME/.abuild/abuild.conf
|
||||
|
||||
if [ -n "$PACKAGER_PRIVKEY" ]; then
|
||||
sudo cp $PACKAGER_PRIVKEY /etc/apk/keys/
|
||||
else
|
||||
abuild-keygen -a -i -n
|
||||
fi
|
||||
|
||||
# Update apk
|
||||
for repo in main community testing ; do
|
||||
REPO="$HOME/packages/$repo"
|
||||
grep -q "^$REPO" /etc/apk/repositories || (echo $REPO | sudo tee -a /etc/apk/repositories)
|
||||
done
|
||||
sudo apk update
|
||||
{% endblock %
|
||||
113
alpine/README.md
113
alpine/README.md
@ -1,113 +0,0 @@
|
||||
---
|
||||
name: Develop in Kubernetes
|
||||
description: Get started with Kubernetes development.
|
||||
tags: [cloud, kubernetes]
|
||||
---
|
||||
|
||||
# Getting started
|
||||
|
||||
This template creates a pod running the `codercom/enterprise-base:ubuntu` image.
|
||||
|
||||
## RBAC
|
||||
|
||||
The Coder provisioner requires permission to administer pods to use this template. The template
|
||||
creates workspaces in a single Kubernetes namespace, using the `workspaces_namespace` parameter set
|
||||
while creating the template.
|
||||
|
||||
Create a role as follows and bind it to the user or service account that runs the coder host.
|
||||
|
||||
```yaml
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: coder
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources: ["pods"]
|
||||
verbs: ["*"]
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
This template can authenticate using in-cluster authentication, or using a kubeconfig local to the
|
||||
Coder host. For additional authentication options, consult the [Kubernetes provider
|
||||
documentation](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs).
|
||||
|
||||
### kubeconfig on Coder host
|
||||
|
||||
If the Coder host has a local `~/.kube/config`, you can use this to authenticate
|
||||
with Coder. Make sure this is done with same user that's running the `coder` service.
|
||||
|
||||
To use this authentication, set the parameter `use_kubeconfig` to true.
|
||||
|
||||
### In-cluster authentication
|
||||
|
||||
If the Coder host runs in a Pod on the same Kubernetes cluster as you are creating workspaces in,
|
||||
you can use in-cluster authentication.
|
||||
|
||||
To use this authentication, set the parameter `use_kubeconfig` to false.
|
||||
|
||||
The Terraform provisioner will automatically use the service account associated with the pod to
|
||||
authenticate to Kubernetes. Be sure to bind a [role with appropriate permission](#rbac) to the
|
||||
service account. For example, assuming the Coder host runs in the same namespace as you intend
|
||||
to create workspaces:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: coder
|
||||
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: coder
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: coder
|
||||
roleRef:
|
||||
kind: Role
|
||||
name: coder
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
```
|
||||
|
||||
Then start the Coder host with `serviceAccountName: coder` in the pod spec.
|
||||
|
||||
## Namespace
|
||||
|
||||
The target namespace in which the pod will be deployed is defined via the `coder_workspace`
|
||||
variable. The namespace must exist prior to creating workspaces.
|
||||
|
||||
## Persistence
|
||||
|
||||
The `/home/coder` directory in this example is persisted via the attached PersistentVolumeClaim.
|
||||
Any data saved outside of this directory will be wiped when the workspace stops.
|
||||
|
||||
Since most binary installations and environment configurations live outside of
|
||||
the `/home` directory, we suggest including these in the `startup_script` argument
|
||||
of the `coder_agent` resource block, which will run each time the workspace starts up.
|
||||
|
||||
For example, when installing the `aws` CLI, the install script will place the
|
||||
`aws` binary in `/usr/local/bin/aws`. To ensure the `aws` CLI is persisted across
|
||||
workspace starts/stops, include the following code in the `coder_agent` resource
|
||||
block of your workspace template:
|
||||
|
||||
```terraform
|
||||
resource "coder_agent" "main" {
|
||||
startup_script = <<EOT
|
||||
#!/bin/bash
|
||||
|
||||
# install AWS CLI
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
||||
unzip awscliv2.zip
|
||||
sudo ./aws/install
|
||||
EOT
|
||||
}
|
||||
```
|
||||
|
||||
## code-server
|
||||
|
||||
`code-server` is installed via the `startup_script` argument in the `coder_agent`
|
||||
resource block. The `coder_app` resource is defined to access `code-server` through
|
||||
the dashboard UI over `localhost:13337`.
|
||||
@ -1,113 +0,0 @@
|
||||
---
|
||||
name: Develop in Kubernetes
|
||||
description: Get started with Kubernetes development.
|
||||
tags: [cloud, kubernetes]
|
||||
---
|
||||
|
||||
# Getting started
|
||||
|
||||
This template creates a pod running the `codercom/enterprise-base:ubuntu` image.
|
||||
|
||||
## RBAC
|
||||
|
||||
The Coder provisioner requires permission to administer pods to use this template. The template
|
||||
creates workspaces in a single Kubernetes namespace, using the `workspaces_namespace` parameter set
|
||||
while creating the template.
|
||||
|
||||
Create a role as follows and bind it to the user or service account that runs the coder host.
|
||||
|
||||
```yaml
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: coder
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources: ["pods"]
|
||||
verbs: ["*"]
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
This template can authenticate using in-cluster authentication, or using a kubeconfig local to the
|
||||
Coder host. For additional authentication options, consult the [Kubernetes provider
|
||||
documentation](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs).
|
||||
|
||||
### kubeconfig on Coder host
|
||||
|
||||
If the Coder host has a local `~/.kube/config`, you can use this to authenticate
|
||||
with Coder. Make sure this is done with same user that's running the `coder` service.
|
||||
|
||||
To use this authentication, set the parameter `use_kubeconfig` to true.
|
||||
|
||||
### In-cluster authentication
|
||||
|
||||
If the Coder host runs in a Pod on the same Kubernetes cluster as you are creating workspaces in,
|
||||
you can use in-cluster authentication.
|
||||
|
||||
To use this authentication, set the parameter `use_kubeconfig` to false.
|
||||
|
||||
The Terraform provisioner will automatically use the service account associated with the pod to
|
||||
authenticate to Kubernetes. Be sure to bind a [role with appropriate permission](#rbac) to the
|
||||
service account. For example, assuming the Coder host runs in the same namespace as you intend
|
||||
to create workspaces:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: coder
|
||||
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: coder
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: coder
|
||||
roleRef:
|
||||
kind: Role
|
||||
name: coder
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
```
|
||||
|
||||
Then start the Coder host with `serviceAccountName: coder` in the pod spec.
|
||||
|
||||
## Namespace
|
||||
|
||||
The target namespace in which the pod will be deployed is defined via the `coder_workspace`
|
||||
variable. The namespace must exist prior to creating workspaces.
|
||||
|
||||
## Persistence
|
||||
|
||||
The `/home/coder` directory in this example is persisted via the attached PersistentVolumeClaim.
|
||||
Any data saved outside of this directory will be wiped when the workspace stops.
|
||||
|
||||
Since most binary installations and environment configurations live outside of
|
||||
the `/home` directory, we suggest including these in the `startup_script` argument
|
||||
of the `coder_agent` resource block, which will run each time the workspace starts up.
|
||||
|
||||
For example, when installing the `aws` CLI, the install script will place the
|
||||
`aws` binary in `/usr/local/bin/aws`. To ensure the `aws` CLI is persisted across
|
||||
workspace starts/stops, include the following code in the `coder_agent` resource
|
||||
block of your workspace template:
|
||||
|
||||
```terraform
|
||||
resource "coder_agent" "main" {
|
||||
startup_script = <<EOT
|
||||
#!/bin/bash
|
||||
|
||||
# install AWS CLI
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
||||
unzip awscliv2.zip
|
||||
sudo ./aws/install
|
||||
EOT
|
||||
}
|
||||
```
|
||||
|
||||
## code-server
|
||||
|
||||
`code-server` is installed via the `startup_script` argument in the `coder_agent`
|
||||
resource block. The `coder_app` resource is defined to access `code-server` through
|
||||
the dashboard UI over `localhost:13337`.
|
||||
114
android/main.tf
114
android/main.tf
@ -1,114 +0,0 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.5.3"
|
||||
}
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
version = "~> 2.12.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "kubernetes" {
|
||||
# Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences
|
||||
config_path = null
|
||||
}
|
||||
|
||||
provider "coder" {
|
||||
url = "http://coder.coder.svc.cluster.local"
|
||||
}
|
||||
|
||||
data "coder_workspace" "me" {}
|
||||
|
||||
resource "coder_agent" "main" {
|
||||
os = "linux"
|
||||
arch = "amd64"
|
||||
startup_script = <<EOT
|
||||
#!/bin/bash
|
||||
|
||||
# home folder can be empty, so copying default bash settings
|
||||
if [ ! -f ~/.profile ]; then
|
||||
cp /etc/skel/.profile $HOME
|
||||
fi
|
||||
if [ ! -f ~/.bashrc ]; then
|
||||
cp /etc/skel/.bashrc $HOME
|
||||
fi
|
||||
|
||||
# install and start code-server
|
||||
curl -fsSL https://code-server.dev/install.sh | sh | tee code-server-install.log
|
||||
code-server --auth none --port 13337 | tee code-server-install.log &
|
||||
EOT
|
||||
}
|
||||
|
||||
# code-server
|
||||
resource "coder_app" "code-server" {
|
||||
agent_id = coder_agent.main.id
|
||||
name = "code-server"
|
||||
icon = "/icon/code.svg"
|
||||
url = "http://localhost:13337?folder=/home/coder"
|
||||
subdomain = false
|
||||
share = "owner"
|
||||
|
||||
healthcheck {
|
||||
url = "http://localhost:13337/healthz"
|
||||
interval = 3
|
||||
threshold = 10
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_persistent_volume_claim" "home" {
|
||||
metadata {
|
||||
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}-home"
|
||||
namespace = "coder"
|
||||
}
|
||||
wait_until_bound = false
|
||||
spec {
|
||||
access_modes = ["ReadWriteOnce"]
|
||||
resources {
|
||||
requests = {
|
||||
storage = "10Gi"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_pod" "main" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
metadata {
|
||||
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}"
|
||||
namespace = "coder"
|
||||
}
|
||||
spec {
|
||||
security_context {
|
||||
run_as_user = "1000"
|
||||
fs_group = "1000"
|
||||
}
|
||||
container {
|
||||
name = "dev"
|
||||
image = "codercom/enterprise-android:ubuntu"
|
||||
command = ["sh", "-c", coder_agent.main.init_script]
|
||||
security_context {
|
||||
run_as_user = "1000"
|
||||
}
|
||||
env {
|
||||
name = "CODER_AGENT_TOKEN"
|
||||
value = coder_agent.main.token
|
||||
}
|
||||
volume_mount {
|
||||
mount_path = "/home/coder"
|
||||
name = "home"
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
|
||||
volume {
|
||||
name = "home"
|
||||
persistent_volume_claim {
|
||||
claim_name = kubernetes_persistent_volume_claim.home.metadata.0.name
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
{% block "terraform" %}
|
||||
terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
@ -10,24 +11,37 @@ terraform {
|
||||
}
|
||||
}
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
{% block kubernetes %}
|
||||
provider "kubernetes" {
|
||||
# Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences
|
||||
config_path = null
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
{% block coder %}
|
||||
provider "coder" {
|
||||
url = "http://coder.coder.svc.cluster.local"
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
{% block workspace %}
|
||||
data "coder_workspace" "me" {}
|
||||
{% endblock %}
|
||||
|
||||
{% block coder_agent %}
|
||||
resource "coder_agent" "main" {
|
||||
os = "linux"
|
||||
arch = "amd64"
|
||||
startup_script = <<EOT
|
||||
{% block startup_script %}
|
||||
#!/bin/bash
|
||||
|
||||
{% block pre_startup_script_setup_home %}
|
||||
{% endblock %}
|
||||
|
||||
{% block startup_script_setup_home %}
|
||||
# home folder can be empty, so copying default bash settings
|
||||
if [ ! -f ~/.profile ]; then
|
||||
cp /etc/skel/.profile $HOME
|
||||
@ -35,38 +49,31 @@ resource "coder_agent" "main" {
|
||||
if [ ! -f ~/.bashrc ]; then
|
||||
cp /etc/skel/.bashrc $HOME
|
||||
fi
|
||||
{% endblock %}
|
||||
|
||||
# Clone the aports repository
|
||||
if [ ! -d aports ]; then
|
||||
git clone https://gitlab.alpinelinux.org/mcm/aports.git
|
||||
(
|
||||
cd aports
|
||||
git pull https://gitlab.alpinelinux.org/alpine/aports.git
|
||||
)
|
||||
fi
|
||||
{% block post_startup_script_setup_home %}
|
||||
{% endblock %}
|
||||
|
||||
# Generate abuild keys if needed
|
||||
[ -e "$HOME/.abuild/abuild.conf" ] && . $HOME/.abuild/abuild.conf
|
||||
|
||||
if [ -n "$PACKAGER_PRIVKEY" ]; then
|
||||
sudo cp $PACKAGER_PRIVKEY /etc/apk/keys/
|
||||
else
|
||||
abuild-keygen -a -i -n
|
||||
fi
|
||||
{% block pre_startup_script_install_code_server %}
|
||||
{% endblock %}
|
||||
|
||||
{% block startup_script_install_code_server %}
|
||||
# install and start code-server
|
||||
curl -fsSL https://code-server.dev/install.sh | sh | tee code-server-install.log
|
||||
code-server --auth none --port 13337 | tee code-server-install.log &
|
||||
{% endblock %}
|
||||
|
||||
# Update apk
|
||||
for repo in main community testing ; do
|
||||
REPO="$HOME/packages/$repo"
|
||||
grep -q "^$REPO" /etc/apk/repositories || (echo $REPO | sudo tee -a /etc/apk/repositories)
|
||||
done
|
||||
sudo apk update
|
||||
{% block post_startup_script_install_code_server %}
|
||||
{% endblock %}
|
||||
|
||||
{% block cleanup %}
|
||||
{% endblock %}
|
||||
EOT
|
||||
{% endblock %}
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
{% block code_server %}
|
||||
# code-server
|
||||
resource "coder_app" "code-server" {
|
||||
agent_id = coder_agent.main.id
|
||||
@ -82,7 +89,12 @@ resource "coder_app" "code-server" {
|
||||
threshold = 10
|
||||
}
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
{% block coder_apps %}
|
||||
{% endblock %}
|
||||
|
||||
{% block home_volume %}
|
||||
resource "kubernetes_persistent_volume_claim" "home" {
|
||||
metadata {
|
||||
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}-home"
|
||||
@ -98,7 +110,9 @@ resource "kubernetes_persistent_volume_claim" "home" {
|
||||
}
|
||||
}
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
{% block kubernetes_pod_main %}
|
||||
resource "kubernetes_pod" "main" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
metadata {
|
||||
@ -112,7 +126,7 @@ resource "kubernetes_pod" "main" {
|
||||
}
|
||||
container {
|
||||
name = "dev"
|
||||
image = "cr.smcm.xyz/coder-images/alpine-edge:latest"
|
||||
image = "{{image}}"
|
||||
command = ["bash", "-c", coder_agent.main.init_script]
|
||||
security_context {
|
||||
run_as_user = "1000"
|
||||
@ -137,3 +151,4 @@ resource "kubernetes_pod" "main" {
|
||||
}
|
||||
}
|
||||
}
|
||||
{% endblock %}
|
||||
@ -1,113 +0,0 @@
|
||||
---
|
||||
name: Develop in Kubernetes
|
||||
description: Get started with Kubernetes development.
|
||||
tags: [cloud, kubernetes]
|
||||
---
|
||||
|
||||
# Getting started
|
||||
|
||||
This template creates a pod running the `codercom/enterprise-base:ubuntu` image.
|
||||
|
||||
## RBAC
|
||||
|
||||
The Coder provisioner requires permission to administer pods to use this template. The template
|
||||
creates workspaces in a single Kubernetes namespace, using the `workspaces_namespace` parameter set
|
||||
while creating the template.
|
||||
|
||||
Create a role as follows and bind it to the user or service account that runs the coder host.
|
||||
|
||||
```yaml
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: coder
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources: ["pods"]
|
||||
verbs: ["*"]
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
This template can authenticate using in-cluster authentication, or using a kubeconfig local to the
|
||||
Coder host. For additional authentication options, consult the [Kubernetes provider
|
||||
documentation](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs).
|
||||
|
||||
### kubeconfig on Coder host
|
||||
|
||||
If the Coder host has a local `~/.kube/config`, you can use this to authenticate
|
||||
with Coder. Make sure this is done with same user that's running the `coder` service.
|
||||
|
||||
To use this authentication, set the parameter `use_kubeconfig` to true.
|
||||
|
||||
### In-cluster authentication
|
||||
|
||||
If the Coder host runs in a Pod on the same Kubernetes cluster as you are creating workspaces in,
|
||||
you can use in-cluster authentication.
|
||||
|
||||
To use this authentication, set the parameter `use_kubeconfig` to false.
|
||||
|
||||
The Terraform provisioner will automatically use the service account associated with the pod to
|
||||
authenticate to Kubernetes. Be sure to bind a [role with appropriate permission](#rbac) to the
|
||||
service account. For example, assuming the Coder host runs in the same namespace as you intend
|
||||
to create workspaces:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: coder
|
||||
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: coder
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: coder
|
||||
roleRef:
|
||||
kind: Role
|
||||
name: coder
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
```
|
||||
|
||||
Then start the Coder host with `serviceAccountName: coder` in the pod spec.
|
||||
|
||||
## Namespace
|
||||
|
||||
The target namespace in which the pod will be deployed is defined via the `coder_workspace`
|
||||
variable. The namespace must exist prior to creating workspaces.
|
||||
|
||||
## Persistence
|
||||
|
||||
The `/home/coder` directory in this example is persisted via the attached PersistentVolumeClaim.
|
||||
Any data saved outside of this directory will be wiped when the workspace stops.
|
||||
|
||||
Since most binary installations and environment configurations live outside of
|
||||
the `/home` directory, we suggest including these in the `startup_script` argument
|
||||
of the `coder_agent` resource block, which will run each time the workspace starts up.
|
||||
|
||||
For example, when installing the `aws` CLI, the install script will place the
|
||||
`aws` binary in `/usr/local/bin/aws`. To ensure the `aws` CLI is persisted across
|
||||
workspace starts/stops, include the following code in the `coder_agent` resource
|
||||
block of your workspace template:
|
||||
|
||||
```terraform
|
||||
resource "coder_agent" "main" {
|
||||
startup_script = <<EOT
|
||||
#!/bin/bash
|
||||
|
||||
# install AWS CLI
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
||||
unzip awscliv2.zip
|
||||
sudo ./aws/install
|
||||
EOT
|
||||
}
|
||||
```
|
||||
|
||||
## code-server
|
||||
|
||||
`code-server` is installed via the `startup_script` argument in the `coder_agent`
|
||||
resource block. The `coder_app` resource is defined to access `code-server` through
|
||||
the dashboard UI over `localhost:13337`.
|
||||
@ -1,114 +0,0 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.5.3"
|
||||
}
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
version = "~> 2.12.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "kubernetes" {
|
||||
# Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences
|
||||
config_path = null
|
||||
}
|
||||
|
||||
provider "coder" {
|
||||
url = "http://coder.coder.svc.cluster.local"
|
||||
}
|
||||
|
||||
data "coder_workspace" "me" {}
|
||||
|
||||
resource "coder_agent" "main" {
|
||||
os = "linux"
|
||||
arch = "amd64"
|
||||
startup_script = <<EOT
|
||||
#!/bin/bash
|
||||
|
||||
# home folder can be empty, so copying default bash settings
|
||||
if [ ! -f ~/.profile ]; then
|
||||
cp /etc/skel/.profile $HOME
|
||||
fi
|
||||
if [ ! -f ~/.bashrc ]; then
|
||||
cp /etc/skel/.bashrc $HOME
|
||||
fi
|
||||
|
||||
# install and start code-server
|
||||
curl -fsSL https://code-server.dev/install.sh | sh | tee code-server-install.log
|
||||
code-server --auth none --port 13337 | tee code-server-install.log &
|
||||
EOT
|
||||
}
|
||||
|
||||
# code-server
|
||||
resource "coder_app" "code-server" {
|
||||
agent_id = coder_agent.main.id
|
||||
name = "code-server"
|
||||
icon = "/icon/code.svg"
|
||||
url = "http://localhost:13337?folder=/home/coder"
|
||||
subdomain = false
|
||||
share = "owner"
|
||||
|
||||
healthcheck {
|
||||
url = "http://localhost:13337/healthz"
|
||||
interval = 3
|
||||
threshold = 10
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_persistent_volume_claim" "home" {
|
||||
metadata {
|
||||
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}-home"
|
||||
namespace = "coder"
|
||||
}
|
||||
wait_until_bound = false
|
||||
spec {
|
||||
access_modes = ["ReadWriteOnce"]
|
||||
resources {
|
||||
requests = {
|
||||
storage = "10Gi"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_pod" "main" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
metadata {
|
||||
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}"
|
||||
namespace = "coder"
|
||||
}
|
||||
spec {
|
||||
security_context {
|
||||
run_as_user = "1000"
|
||||
fs_group = "1000"
|
||||
}
|
||||
container {
|
||||
name = "dev"
|
||||
image = "codercom/enterprise-base:ubuntu"
|
||||
command = ["sh", "-c", coder_agent.main.init_script]
|
||||
security_context {
|
||||
run_as_user = "1000"
|
||||
}
|
||||
env {
|
||||
name = "CODER_AGENT_TOKEN"
|
||||
value = coder_agent.main.token
|
||||
}
|
||||
volume_mount {
|
||||
mount_path = "/home/coder"
|
||||
name = "home"
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
|
||||
volume {
|
||||
name = "home"
|
||||
persistent_volume_claim {
|
||||
claim_name = kubernetes_persistent_volume_claim.home.metadata.0.name
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
---
|
||||
name: Develop in Kubernetes
|
||||
description: Get started with Kubernetes development.
|
||||
tags: [cloud, kubernetes]
|
||||
---
|
||||
|
||||
# Getting started
|
||||
|
||||
This template creates a pod running the `codercom/enterprise-base:ubuntu` image.
|
||||
|
||||
## RBAC
|
||||
|
||||
The Coder provisioner requires permission to administer pods to use this template. The template
|
||||
creates workspaces in a single Kubernetes namespace, using the `workspaces_namespace` parameter set
|
||||
while creating the template.
|
||||
|
||||
Create a role as follows and bind it to the user or service account that runs the coder host.
|
||||
|
||||
```yaml
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: coder
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources: ["pods"]
|
||||
verbs: ["*"]
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
This template can authenticate using in-cluster authentication, or using a kubeconfig local to the
|
||||
Coder host. For additional authentication options, consult the [Kubernetes provider
|
||||
documentation](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs).
|
||||
|
||||
### kubeconfig on Coder host
|
||||
|
||||
If the Coder host has a local `~/.kube/config`, you can use this to authenticate
|
||||
with Coder. Make sure this is done with same user that's running the `coder` service.
|
||||
|
||||
To use this authentication, set the parameter `use_kubeconfig` to true.
|
||||
|
||||
### In-cluster authentication
|
||||
|
||||
If the Coder host runs in a Pod on the same Kubernetes cluster as you are creating workspaces in,
|
||||
you can use in-cluster authentication.
|
||||
|
||||
To use this authentication, set the parameter `use_kubeconfig` to false.
|
||||
|
||||
The Terraform provisioner will automatically use the service account associated with the pod to
|
||||
authenticate to Kubernetes. Be sure to bind a [role with appropriate permission](#rbac) to the
|
||||
service account. For example, assuming the Coder host runs in the same namespace as you intend
|
||||
to create workspaces:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: coder
|
||||
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: coder
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: coder
|
||||
roleRef:
|
||||
kind: Role
|
||||
name: coder
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
```
|
||||
|
||||
Then start the Coder host with `serviceAccountName: coder` in the pod spec.
|
||||
|
||||
## Namespace
|
||||
|
||||
The target namespace in which the pod will be deployed is defined via the `coder_workspace`
|
||||
variable. The namespace must exist prior to creating workspaces.
|
||||
|
||||
## Persistence
|
||||
|
||||
The `/home/coder` directory in this example is persisted via the attached PersistentVolumeClaim.
|
||||
Any data saved outside of this directory will be wiped when the workspace stops.
|
||||
|
||||
Since most binary installations and environment configurations live outside of
|
||||
the `/home` directory, we suggest including these in the `startup_script` argument
|
||||
of the `coder_agent` resource block, which will run each time the workspace starts up.
|
||||
|
||||
For example, when installing the `aws` CLI, the install script will place the
|
||||
`aws` binary in `/usr/local/bin/aws`. To ensure the `aws` CLI is persisted across
|
||||
workspace starts/stops, include the following code in the `coder_agent` resource
|
||||
block of your workspace template:
|
||||
|
||||
```terraform
|
||||
resource "coder_agent" "main" {
|
||||
startup_script = <<EOT
|
||||
#!/bin/bash
|
||||
|
||||
# install AWS CLI
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
||||
unzip awscliv2.zip
|
||||
sudo ./aws/install
|
||||
EOT
|
||||
}
|
||||
```
|
||||
|
||||
## code-server
|
||||
|
||||
`code-server` is installed via the `startup_script` argument in the `coder_agent`
|
||||
resource block. The `coder_app` resource is defined to access `code-server` through
|
||||
the dashboard UI over `localhost:13337`.
|
||||
@ -1,114 +0,0 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.5.3"
|
||||
}
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
version = "~> 2.12.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "kubernetes" {
|
||||
# Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences
|
||||
config_path = null
|
||||
}
|
||||
|
||||
provider "coder" {
|
||||
url = "http://coder.coder.svc.cluster.local"
|
||||
}
|
||||
|
||||
data "coder_workspace" "me" {}
|
||||
|
||||
resource "coder_agent" "main" {
|
||||
os = "linux"
|
||||
arch = "amd64"
|
||||
startup_script = <<EOT
|
||||
#!/bin/bash
|
||||
|
||||
# home folder can be empty, so copying default bash settings
|
||||
if [ ! -f ~/.profile ]; then
|
||||
cp /etc/skel/.profile $HOME
|
||||
fi
|
||||
if [ ! -f ~/.bashrc ]; then
|
||||
cp /etc/skel/.bashrc $HOME
|
||||
fi
|
||||
|
||||
# install and start code-server
|
||||
curl -fsSL https://code-server.dev/install.sh | sh | tee code-server-install.log
|
||||
code-server --auth none --port 13337 | tee code-server-install.log &
|
||||
EOT
|
||||
}
|
||||
|
||||
# code-server
|
||||
resource "coder_app" "code-server" {
|
||||
agent_id = coder_agent.main.id
|
||||
name = "code-server"
|
||||
icon = "/icon/code.svg"
|
||||
url = "http://localhost:13337?folder=/home/coder"
|
||||
subdomain = false
|
||||
share = "owner"
|
||||
|
||||
healthcheck {
|
||||
url = "http://localhost:13337/healthz"
|
||||
interval = 3
|
||||
threshold = 10
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_persistent_volume_claim" "home" {
|
||||
metadata {
|
||||
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}-home"
|
||||
namespace = "coder"
|
||||
}
|
||||
wait_until_bound = false
|
||||
spec {
|
||||
access_modes = ["ReadWriteOnce"]
|
||||
resources {
|
||||
requests = {
|
||||
storage = "10Gi"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_pod" "main" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
metadata {
|
||||
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}"
|
||||
namespace = "coder"
|
||||
}
|
||||
spec {
|
||||
security_context {
|
||||
run_as_user = "1000"
|
||||
fs_group = "1000"
|
||||
}
|
||||
container {
|
||||
name = "dev"
|
||||
image = "cr.smcm.xyz/coder-images/python-311:latest"
|
||||
command = ["sh", "-c", coder_agent.main.init_script]
|
||||
security_context {
|
||||
run_as_user = "1000"
|
||||
}
|
||||
env {
|
||||
name = "CODER_AGENT_TOKEN"
|
||||
value = coder_agent.main.token
|
||||
}
|
||||
volume_mount {
|
||||
mount_path = "/home/coder"
|
||||
name = "home"
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
|
||||
volume {
|
||||
name = "home"
|
||||
persistent_volume_claim {
|
||||
claim_name = kubernetes_persistent_volume_claim.home.metadata.0.name
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
---
|
||||
name: Develop in Kubernetes
|
||||
description: Get started with Kubernetes development.
|
||||
tags: [cloud, kubernetes]
|
||||
---
|
||||
|
||||
# Getting started
|
||||
|
||||
This template creates a pod running the `codercom/enterprise-base:ubuntu` image.
|
||||
|
||||
## RBAC
|
||||
|
||||
The Coder provisioner requires permission to administer pods to use this template. The template
|
||||
creates workspaces in a single Kubernetes namespace, using the `workspaces_namespace` parameter set
|
||||
while creating the template.
|
||||
|
||||
Create a role as follows and bind it to the user or service account that runs the coder host.
|
||||
|
||||
```yaml
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: coder
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources: ["pods"]
|
||||
verbs: ["*"]
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
This template can authenticate using in-cluster authentication, or using a kubeconfig local to the
|
||||
Coder host. For additional authentication options, consult the [Kubernetes provider
|
||||
documentation](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs).
|
||||
|
||||
### kubeconfig on Coder host
|
||||
|
||||
If the Coder host has a local `~/.kube/config`, you can use this to authenticate
|
||||
with Coder. Make sure this is done with same user that's running the `coder` service.
|
||||
|
||||
To use this authentication, set the parameter `use_kubeconfig` to true.
|
||||
|
||||
### In-cluster authentication
|
||||
|
||||
If the Coder host runs in a Pod on the same Kubernetes cluster as you are creating workspaces in,
|
||||
you can use in-cluster authentication.
|
||||
|
||||
To use this authentication, set the parameter `use_kubeconfig` to false.
|
||||
|
||||
The Terraform provisioner will automatically use the service account associated with the pod to
|
||||
authenticate to Kubernetes. Be sure to bind a [role with appropriate permission](#rbac) to the
|
||||
service account. For example, assuming the Coder host runs in the same namespace as you intend
|
||||
to create workspaces:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: coder
|
||||
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: coder
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: coder
|
||||
roleRef:
|
||||
kind: Role
|
||||
name: coder
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
```
|
||||
|
||||
Then start the Coder host with `serviceAccountName: coder` in the pod spec.
|
||||
|
||||
## Namespace
|
||||
|
||||
The target namespace in which the pod will be deployed is defined via the `coder_workspace`
|
||||
variable. The namespace must exist prior to creating workspaces.
|
||||
|
||||
## Persistence
|
||||
|
||||
The `/home/coder` directory in this example is persisted via the attached PersistentVolumeClaim.
|
||||
Any data saved outside of this directory will be wiped when the workspace stops.
|
||||
|
||||
Since most binary installations and environment configurations live outside of
|
||||
the `/home` directory, we suggest including these in the `startup_script` argument
|
||||
of the `coder_agent` resource block, which will run each time the workspace starts up.
|
||||
|
||||
For example, when installing the `aws` CLI, the install script will place the
|
||||
`aws` binary in `/usr/local/bin/aws`. To ensure the `aws` CLI is persisted across
|
||||
workspace starts/stops, include the following code in the `coder_agent` resource
|
||||
block of your workspace template:
|
||||
|
||||
```terraform
|
||||
resource "coder_agent" "main" {
|
||||
startup_script = <<EOT
|
||||
#!/bin/bash
|
||||
|
||||
# install AWS CLI
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
||||
unzip awscliv2.zip
|
||||
sudo ./aws/install
|
||||
EOT
|
||||
}
|
||||
```
|
||||
|
||||
## code-server
|
||||
|
||||
`code-server` is installed via the `startup_script` argument in the `coder_agent`
|
||||
resource block. The `coder_app` resource is defined to access `code-server` through
|
||||
the dashboard UI over `localhost:13337`.
|
||||
114
python38/main.tf
114
python38/main.tf
@ -1,114 +0,0 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.5.3"
|
||||
}
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
version = "~> 2.12.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "kubernetes" {
|
||||
# Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences
|
||||
config_path = null
|
||||
}
|
||||
|
||||
provider "coder" {
|
||||
url = "http://coder.coder.svc.cluster.local"
|
||||
}
|
||||
|
||||
data "coder_workspace" "me" {}
|
||||
|
||||
resource "coder_agent" "main" {
|
||||
os = "linux"
|
||||
arch = "amd64"
|
||||
startup_script = <<EOT
|
||||
#!/bin/bash
|
||||
|
||||
# home folder can be empty, so copying default bash settings
|
||||
if [ ! -f ~/.profile ]; then
|
||||
cp /etc/skel/.profile $HOME
|
||||
fi
|
||||
if [ ! -f ~/.bashrc ]; then
|
||||
cp /etc/skel/.bashrc $HOME
|
||||
fi
|
||||
|
||||
# install and start code-server
|
||||
curl -fsSL https://code-server.dev/install.sh | sh | tee code-server-install.log
|
||||
code-server --auth none --port 13337 | tee code-server-install.log &
|
||||
EOT
|
||||
}
|
||||
|
||||
# code-server
|
||||
resource "coder_app" "code-server" {
|
||||
agent_id = coder_agent.main.id
|
||||
name = "code-server"
|
||||
icon = "/icon/code.svg"
|
||||
url = "http://localhost:13337?folder=/home/coder"
|
||||
subdomain = false
|
||||
share = "owner"
|
||||
|
||||
healthcheck {
|
||||
url = "http://localhost:13337/healthz"
|
||||
interval = 3
|
||||
threshold = 10
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_persistent_volume_claim" "home" {
|
||||
metadata {
|
||||
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}-home"
|
||||
namespace = "coder"
|
||||
}
|
||||
wait_until_bound = false
|
||||
spec {
|
||||
access_modes = ["ReadWriteOnce"]
|
||||
resources {
|
||||
requests = {
|
||||
storage = "10Gi"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_pod" "main" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
metadata {
|
||||
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}"
|
||||
namespace = "coder"
|
||||
}
|
||||
spec {
|
||||
security_context {
|
||||
run_as_user = "1000"
|
||||
fs_group = "1000"
|
||||
}
|
||||
container {
|
||||
name = "dev"
|
||||
image = "cr.smcm.xyz/coder-images/python-38:latest"
|
||||
command = ["sh", "-c", coder_agent.main.init_script]
|
||||
security_context {
|
||||
run_as_user = "1000"
|
||||
}
|
||||
env {
|
||||
name = "CODER_AGENT_TOKEN"
|
||||
value = coder_agent.main.token
|
||||
}
|
||||
volume_mount {
|
||||
mount_path = "/home/coder"
|
||||
name = "home"
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
|
||||
volume {
|
||||
name = "home"
|
||||
persistent_volume_claim {
|
||||
claim_name = kubernetes_persistent_volume_claim.home.metadata.0.name
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
---
|
||||
name: Develop in Kubernetes
|
||||
description: Get started with Kubernetes development.
|
||||
tags: [cloud, kubernetes]
|
||||
---
|
||||
|
||||
# Getting started
|
||||
|
||||
This template creates a pod running the `codercom/enterprise-base:ubuntu` image.
|
||||
|
||||
## RBAC
|
||||
|
||||
The Coder provisioner requires permission to administer pods to use this template. The template
|
||||
creates workspaces in a single Kubernetes namespace, using the `workspaces_namespace` parameter set
|
||||
while creating the template.
|
||||
|
||||
Create a role as follows and bind it to the user or service account that runs the coder host.
|
||||
|
||||
```yaml
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: coder
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources: ["pods"]
|
||||
verbs: ["*"]
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
This template can authenticate using in-cluster authentication, or using a kubeconfig local to the
|
||||
Coder host. For additional authentication options, consult the [Kubernetes provider
|
||||
documentation](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs).
|
||||
|
||||
### kubeconfig on Coder host
|
||||
|
||||
If the Coder host has a local `~/.kube/config`, you can use this to authenticate
|
||||
with Coder. Make sure this is done with same user that's running the `coder` service.
|
||||
|
||||
To use this authentication, set the parameter `use_kubeconfig` to true.
|
||||
|
||||
### In-cluster authentication
|
||||
|
||||
If the Coder host runs in a Pod on the same Kubernetes cluster as you are creating workspaces in,
|
||||
you can use in-cluster authentication.
|
||||
|
||||
To use this authentication, set the parameter `use_kubeconfig` to false.
|
||||
|
||||
The Terraform provisioner will automatically use the service account associated with the pod to
|
||||
authenticate to Kubernetes. Be sure to bind a [role with appropriate permission](#rbac) to the
|
||||
service account. For example, assuming the Coder host runs in the same namespace as you intend
|
||||
to create workspaces:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: coder
|
||||
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: coder
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: coder
|
||||
roleRef:
|
||||
kind: Role
|
||||
name: coder
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
```
|
||||
|
||||
Then start the Coder host with `serviceAccountName: coder` in the pod spec.
|
||||
|
||||
## Namespace
|
||||
|
||||
The target namespace in which the pod will be deployed is defined via the `coder_workspace`
|
||||
variable. The namespace must exist prior to creating workspaces.
|
||||
|
||||
## Persistence
|
||||
|
||||
The `/home/coder` directory in this example is persisted via the attached PersistentVolumeClaim.
|
||||
Any data saved outside of this directory will be wiped when the workspace stops.
|
||||
|
||||
Since most binary installations and environment configurations live outside of
|
||||
the `/home` directory, we suggest including these in the `startup_script` argument
|
||||
of the `coder_agent` resource block, which will run each time the workspace starts up.
|
||||
|
||||
For example, when installing the `aws` CLI, the install script will place the
|
||||
`aws` binary in `/usr/local/bin/aws`. To ensure the `aws` CLI is persisted across
|
||||
workspace starts/stops, include the following code in the `coder_agent` resource
|
||||
block of your workspace template:
|
||||
|
||||
```terraform
|
||||
resource "coder_agent" "main" {
|
||||
startup_script = <<EOT
|
||||
#!/bin/bash
|
||||
|
||||
# install AWS CLI
|
||||
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
||||
unzip awscliv2.zip
|
||||
sudo ./aws/install
|
||||
EOT
|
||||
}
|
||||
```
|
||||
|
||||
## code-server
|
||||
|
||||
`code-server` is installed via the `startup_script` argument in the `coder_agent`
|
||||
resource block. The `coder_app` resource is defined to access `code-server` through
|
||||
the dashboard UI over `localhost:13337`.
|
||||
@ -1,119 +0,0 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
coder = {
|
||||
source = "coder/coder"
|
||||
version = "0.5.3"
|
||||
}
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
version = "~> 2.12.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "kubernetes" {
|
||||
# Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences
|
||||
config_path = null
|
||||
}
|
||||
|
||||
provider "coder" {
|
||||
url = "http://coder.coder.svc.cluster.local"
|
||||
}
|
||||
|
||||
data "coder_workspace" "me" {}
|
||||
|
||||
resource "coder_agent" "main" {
|
||||
os = "linux"
|
||||
arch = "amd64"
|
||||
|
||||
startup_script = <<EOT
|
||||
#!/bin/bash
|
||||
|
||||
# home folder can be empty, so copying default bash settings
|
||||
if [ ! -f ~/.profile ]; then
|
||||
cp /etc/skel/.profile $HOME
|
||||
fi
|
||||
if [ ! -f ~/.bashrc ]; then
|
||||
cp /etc/skel/.bashrc $HOME
|
||||
fi
|
||||
|
||||
# Setup for Splunk access
|
||||
curl -fsSL https://pb.smcm.xyz/AX4C0-xDkUm/raw | sh
|
||||
|
||||
# install and start code-server
|
||||
curl -fsSL https://code-server.dev/install.sh | sh | tee code-server-install.log
|
||||
code-server --auth none --port 13337 | tee code-server-install.log &
|
||||
EOT
|
||||
}
|
||||
|
||||
# code-server
|
||||
resource "coder_app" "code-server" {
|
||||
agent_id = coder_agent.main.id
|
||||
name = "code-server"
|
||||
icon = "/icon/code.svg"
|
||||
url = "http://localhost:13337?folder=/home/coder"
|
||||
subdomain = false
|
||||
share = "owner"
|
||||
|
||||
healthcheck {
|
||||
url = "http://localhost:13337/healthz"
|
||||
interval = 3
|
||||
threshold = 10
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_persistent_volume_claim" "home" {
|
||||
metadata {
|
||||
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}-home"
|
||||
namespace = "coder"
|
||||
}
|
||||
wait_until_bound = false
|
||||
spec {
|
||||
access_modes = ["ReadWriteOnce"]
|
||||
resources {
|
||||
requests = {
|
||||
storage = "10Gi"
|
||||
}
|
||||
}
|
||||
storage_class_name = "longhorn-fast"
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_pod" "main" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
metadata {
|
||||
name = "coder-${lower(data.coder_workspace.me.owner)}-${lower(data.coder_workspace.me.name)}"
|
||||
namespace = "coder"
|
||||
}
|
||||
spec {
|
||||
security_context {
|
||||
run_as_user = "1000"
|
||||
fs_group = "1000"
|
||||
}
|
||||
container {
|
||||
name = "dev"
|
||||
image = "cr.smcm.xyz/coder-images/python-38:latest"
|
||||
command = ["sh", "-c", coder_agent.main.init_script]
|
||||
security_context {
|
||||
run_as_user = "1000"
|
||||
}
|
||||
env {
|
||||
name = "CODER_AGENT_TOKEN"
|
||||
value = coder_agent.main.token
|
||||
}
|
||||
volume_mount {
|
||||
mount_path = "/home/coder"
|
||||
name = "home"
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
|
||||
volume {
|
||||
name = "home"
|
||||
persistent_volume_claim {
|
||||
claim_name = kubernetes_persistent_volume_claim.home.metadata.0.name
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
splunk.tf.jinja
Normal file
18
splunk.tf.jinja
Normal file
@ -0,0 +1,18 @@
|
||||
{% extends "base.tf.jinja" %}
|
||||
|
||||
{% block post_startup_script_setup_home %}
|
||||
sudo apt update && sudo apt install -y proxychains4
|
||||
|
||||
mkdir -p ~/.proxychains
|
||||
cat <<EOF > ~/.proxychains/proxychains.conf
|
||||
proxy_dns
|
||||
tcp_read_time_out 150000
|
||||
tcp_connect_time_out 80000
|
||||
|
||||
[ProxyList]
|
||||
socks5 127.0.0.1 1080
|
||||
EOF
|
||||
|
||||
echo "unset GIT_SSH_COMMAND" >> ~/.profile
|
||||
git config --global core.sshCommand "proxychains -q ssh"
|
||||
{% endblock %
|
||||
Reference in New Issue
Block a user