Skip to content
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

docs(k8s): update terraform-gke example for Bonsai #4000

Merged
merged 5 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 5 additions & 15 deletions examples/terraform-gke/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,18 @@ The Terraform stack needs some input values from you. You can provide those in a

```tfvars
# terraform.tfvars
gcp_region = "europe-west1"°
gcp_project_id = "my-test-project"
region = "europe-west1"°
project_id = "my-test-project"
```

**B)** Configure the variables directly in the project `garden.yml` (see the `terraform` provider section).

### Step 4 - Initialize the cluster
### Step 4 - Deploy your stack

Install the cluster-wide services Garden needs by running:
Finally, build and deploy your GKE cluster and services to the new cluster:

```sh
garden plugins kubernetes cluster-init
```

This will take a while because the cluster needs to be provisioned, and some services installed when it's ready.

### Step 5 - Deploy your services

Finally, to build and deploy your services to your new GKE cluster, run:

```sh
garden deploy
garden deploy -l2 #the -l2 flag is optional, but recommended to observe the progress of the Terraform deployment
```

And that's it!
Expand Down
27 changes: 16 additions & 11 deletions examples/terraform-gke/backend/garden.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
kind: Module
kind: Build
name: backend
type: container

---

kind: Deploy
name: backend
build: backend
description: Backend service container
type: container
services:
- name: backend
ports:
- name: http
containerPort: 8080
# Maps service:80 -> container:8080
servicePort: 80
ingresses:
- path: /hello-backend
port: http
spec:
ports:
- name: http
containerPort: 8080
servicePort: 80
ingresses:
- path: /hello-backend
port: http
64 changes: 40 additions & 24 deletions examples/terraform-gke/frontend/garden.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
kind: Module
kind: Build
name: frontend
type: container

---
kind: Deploy
name: frontend
build: frontend
description: Frontend service container
type: container
services:
- name: frontend
ports:
- name: http
containerPort: 8080
healthCheck:
httpGet:
path: /hello-frontend
port: http
ingresses:
- path: /hello-frontend
port: http
- path: /call-backend
port: http
dependencies:
- backend
tests:
- name: unit
args: [npm, test]
- name: integ
args: [npm, run, integ]
dependencies:
- frontend
spec:
ports:
- name: http
containerPort: 8080
healthCheck:
httpGet:
path: /hello-frontend
port: http
ingresses:
- path: /hello-frontend
port: http
- path: /call-backend
port: http
dependencies:
- deploy.backend

---
kind: Test
name: frontend-unit
build: frontend
type: container
spec:
args: [npm, test]

---
kind: Test
name: frontend-integ
build: frontend
type: container
spec:
args: [npm, run, integ]
dependencies:
- deploy.backend
46 changes: 33 additions & 13 deletions examples/terraform-gke/garden.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
kind: Project
name: terraform-gke

environments:
- name: dev
defaultNamespace: ${project.name}-${variables.userId}
- name: prod
defaultNamespace: ${project.name}
production: true

variables:
# change these values to your own
username: worldofgeese
gcpProjectId: devrel-348008
gcpRegion: europe-north1
registryHostname: docker.io
registryNamespace: worldofgeese
terraformInitRoot: "./terraform/"
userId: ${local.username}
providers:
- name: terraform
# This must be set to indicate that there is a stack in the project root.
initRoot: "."
# This must be set to indicate that there is a stack in the terraform project folder.
initRoot: "${var.terraformInitRoot}"
autoApply: true
# You can either uncomment and replace these with your own values, or provide the values in a
# terraform.tfvars file in the project root.
# variables:
# gcp_project_id: garden-gke-tf-${var.userId}
# gcp_region: europe-west1
allowDestroy: true
# You can either uncomment and replace these with your own values, or provide the values in a
# terraform.tfvars file in the project root.
variables:
project_id: ${var.gcpProjectId}
region: ${var.gcpRegion}

- name: kubernetes
kubeconfig: ${providers.terraform.outputs.kubeconfig_path}
context: gke
defaultHostname: terraform-gke-${var.userId}.dev-2.sys.garden
buildMode: kaniko
kubeconfig: ${var.terraformInitRoot}/${providers.terraform.outputs.kubeconfig_path}
context: ${providers.terraform.outputs.cluster_name}
# any hostname that points to your cluster's ingress controller
defaultHostname: ${var.userId}-gke.dev-1.sys.garden
# Replace the below values as appropriate
deploymentRegistry:
hostname: eu.gcr.io # <- set this according to the region your cluster runs in
namespace: garden-ci # <- set this to the project ID of the target cluster
imagePullSecrets:
# Make sure this matches the name and namespace of the imagePullSecret you've created
# to authenticate with your registry (if needed)
- name: gcr-config
namespace: default
hostname: ${variables.registryHostname}
namespace: ${variables.registryNamespace}
162 changes: 0 additions & 162 deletions examples/terraform-gke/gke.tf

This file was deleted.

Loading