Skip to content

example: Add Kubernetes multi-service #1092

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/kubernetes-multi-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: Develop multiple services in Kubernetes
description: Get started with Kubernetes development.
tags: [cloud, kubernetes]
---
78 changes: 78 additions & 0 deletions examples/kubernetes-multi-service/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
terraform {
required_providers {
coder = {
source = "coder/coder"
version = "~> 0.3.1"
}
kubernetes = {
source = "hashicorp/kubernetes"
version = "~> 2.10"
}
}
}

provider "kubernetes" {
config_path = "~/.kube/config"
}

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}"
}
spec {
container {
name = "go"
image = "mcr.microsoft.com/vscode/devcontainers/go:1"
command = ["sh", "-c", coder_agent.go.init_script]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed all of these containers bring you to strange locations when you ssh in for the first time

go: /go
java: /
ubuntu /

Should the init script always do something like cd $HOME before it starts the agent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will in my other PR now!

security_context {
run_as_user = "1000"
}
env {
name = "CODER_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_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_TOKEN"
value = coder_agent.ubuntu.token
}
}
}
}