diff --git a/examples/templates/kubernetes-multi-service/main.tf b/examples/templates/kubernetes-multi-service/main.tf deleted file mode 100644 index 118c258bc21fa..0000000000000 --- a/examples/templates/kubernetes-multi-service/main.tf +++ /dev/null @@ -1,101 +0,0 @@ -terraform { - required_providers { - coder = { - source = "coder/coder" - version = "0.4.9" - } - kubernetes = { - source = "hashicorp/kubernetes" - version = "~> 2.10" - } - } -} - -variable "use_kubeconfig" { - type = bool - sensitive = true - description = <<-EOF - Use host kubeconfig? (true/false) - - Set this to false if the Coder host is itself running as a Pod on the same - Kubernetes cluster as you are deploying workspaces to. - - Set this to true if the Coder host is running outside the Kubernetes cluster - for workspaces. A valid "~/.kube/config" must be present on the Coder host. - EOF -} - -variable "workspaces_namespace" { - type = string - sensitive = true - description = "The namespace to create workspaces in (must exist prior to creating workspaces)" - default = "coder-workspaces" -} - -provider "kubernetes" { - # Authenticate via ~/.kube/config or a Coder-specific ServiceAccount, depending on admin preferences - config_path = var.use_kubeconfig == true ? "~/.kube/config" : null -} - -data "coder_workspace" "me" {} - -resource "coder_agent" "go" { - os = "linux" - arch = "amd64" -} - -resource "coder_agent" "java" { - os = "linux" - arch = "amd64" -} - -resource "coder_agent" "ubuntu" { - os = "linux" - arch = "amd64" -} - -resource "kubernetes_pod" "main" { - count = data.coder_workspace.me.start_count - metadata { - name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}" - namespace = var.workspaces_namespace - } - spec { - container { - name = "go" - image = "mcr.microsoft.com/vscode/devcontainers/go:1" - command = ["sh", "-c", coder_agent.go.init_script] - security_context { - run_as_user = "1000" - } - env { - name = "CODER_AGENT_TOKEN" - value = coder_agent.go.token - } - } - container { - name = "java" - image = "mcr.microsoft.com/vscode/devcontainers/java" - command = ["sh", "-c", coder_agent.java.init_script] - security_context { - run_as_user = "1000" - } - env { - name = "CODER_AGENT_TOKEN" - value = coder_agent.java.token - } - } - container { - name = "ubuntu" - image = "mcr.microsoft.com/vscode/devcontainers/base:ubuntu" - command = ["sh", "-c", coder_agent.ubuntu.init_script] - security_context { - run_as_user = "1000" - } - env { - name = "CODER_AGENT_TOKEN" - value = coder_agent.ubuntu.token - } - } - } -} diff --git a/examples/templates/kubernetes-multi-service/README.md b/examples/templates/kubernetes-pod/README.md similarity index 60% rename from examples/templates/kubernetes-multi-service/README.md rename to examples/templates/kubernetes-pod/README.md index 7c70d661f7258..fa4569846b79f 100644 --- a/examples/templates/kubernetes-multi-service/README.md +++ b/examples/templates/kubernetes-pod/README.md @@ -72,3 +72,40 @@ roleRef: 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 = <