- Notifications
You must be signed in to change notification settings - Fork928
chore: k8s example persistence & coder images#3619
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
Merged
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
101 changes: 0 additions & 101 deletionsexamples/templates/kubernetes-multi-service/main.tf
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
37 changes: 37 additions & 0 deletions...plates/kubernetes-multi-service/README.md → examples/templates/kubernetes-pod/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
118 changes: 118 additions & 0 deletionsexamples/templates/kubernetes-pod/main.tf
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,118 @@ | ||
terraform { | ||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
version = "0.4.9" | ||
} | ||
kubernetes = { | ||
source = "hashicorp/kubernetes" | ||
version = "~> 2.12.1" | ||
} | ||
} | ||
} | ||
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 "coder_namespace" { | ||
type = string | ||
sensitive = true | ||
description = "The namespace to create workspaces in (must exist prior to creating workspaces)" | ||
default = "coder-namespace" | ||
} | ||
variable "disk_size" { | ||
type = number | ||
description = "Disk size (__ GB)" | ||
default = 10 | ||
} | ||
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" "main" { | ||
os = "linux" | ||
arch = "amd64" | ||
startup_script = <<EOT | ||
#!/bin/bash | ||
# 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" | ||
relative_path = true | ||
} | ||
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.coder_namespace | ||
} | ||
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-directory" | ||
} | ||
} | ||
volume { | ||
name = "home-directory" | ||
persistent_volume_claim { | ||
claim_name = kubernetes_persistent_volume_claim.home-directory.metadata.0.name | ||
} | ||
} | ||
} | ||
} | ||
resource "kubernetes_persistent_volume_claim" "home-directory" { | ||
metadata { | ||
name = "home-coder-java-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}" | ||
namespace = var.coder_namespace | ||
} | ||
spec { | ||
access_modes = ["ReadWriteOnce"] | ||
resources { | ||
requests = { | ||
storage = "${var.disk_size}Gi" | ||
} | ||
} | ||
} | ||
} |
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.