Skip to content

Commit 59fae72

Browse files
committed
checkpoint-kai-1700574655
1 parent 6bbf26e commit 59fae72

File tree

8 files changed

+86
-43
lines changed

8 files changed

+86
-43
lines changed

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,44 @@ $ make upgrade
8686

8787
## Deployment
8888

89-
This deployment command assumes you are locally authenticated to both gcloud and kubectl. Directions on how to do so are out of scope for this documentation. Please consult your team's local deployment tooling and instructions!
89+
This deployment command assumes you are locally authenticated to gcloud and kubectl, and have performed all of the above installations.
90+
91+
### 1. Create a new project
92+
93+
Create a new project via https://console.cloud.google.com/, then set its name in `config.yml`
94+
95+
```yaml
96+
# config.yml
97+
project: dotted-hope-405813
98+
```
99+
100+
### 2. Create a terraform state bucket
101+
102+
Create a terraform state bucket via https://console.cloud.google.com/, then set its name in `config.yml`
103+
104+
```yaml
105+
# config.yml
106+
bucket: coilysiren-k8s-gpc-tfstate-3
107+
```
108+
109+
Then import it into terraform.
110+
111+
```bash
112+
# $SHELL
113+
cd infrastructure/foundation/
114+
terraform import google_storage_bucket.default coilysiren-k8s-gpc-tfstate-3
115+
```
116+
117+
Note that, when you deploy in the next step, you might have to modify the state bucket's region. The goal is to avoid replacing the state bucket.
118+
119+
### 3. Deploy
120+
121+
Run the deploy script
90122

91123
```bash
124+
# $SHELL
92125
source ./venv/bin/activate
93126
invoke deploy # see tasks.py for source code
94127
```
128+
129+
Note that, during the deploy process, you will likely need to enable several google APIs. Do so when prompted, then run the deploy again.

config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Personal configuration
22
name: gke-test-2
33
domain: gke-test-2.coilysiren.me
4+
zone: coilysiren.me
45
56

67
# Google Cloud Platform configuration
7-
project: root-territory-384205
8+
project: dotted-hope-405813
9+
statebucket: coilysiren-k8s-gpc-tfstate-3
810
region: us-central1
911

1012
# https://github.com/cert-manager/cert-manager/releases

infrastructure/application/main.tf

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
locals {
2-
name = yamldecode(file("../../config.yml")).name
2+
zone = yamldecode(file("../../config.yml")).zone
3+
domain = yamldecode(file("../../config.yml")).domain
34
}
45

56
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/client_config
@@ -11,17 +12,46 @@ data "kubernetes_service" "service" {
1112
}
1213
}
1314

15+
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/certificate_manager_dns_authorization
16+
resource "google_certificate_manager_dns_authorization" "default" {
17+
name = "dns-auth"
18+
domain = local.domain
19+
}
20+
1421
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone
1522
data "aws_route53_zone" "zone" {
16-
name = "coilysiren.me."
23+
name = "${local.zone}."
1724
private_zone = false
1825
}
1926

2027
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record
2128
resource "aws_route53_record" "record" {
2229
zone_id = data.aws_route53_zone.zone.zone_id
23-
name = "${local.name}.coilysiren.me."
30+
name = "${local.domain}."
2431
type = "A"
2532
ttl = "300"
2633
records = [data.kubernetes_service.service.status.0.load_balancer.0.ingress.0.ip]
2734
}
35+
36+
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record
37+
resource "aws_route53_record" "cert" {
38+
zone_id = data.aws_route53_zone.zone.zone_id
39+
name = google_certificate_manager_dns_authorization.default.dns_resource_record.0.name
40+
type = google_certificate_manager_dns_authorization.default.dns_resource_record.0.type
41+
ttl = "300"
42+
records = [google_certificate_manager_dns_authorization.default.dns_resource_record.0.data]
43+
}
44+
45+
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/certificate_manager_certificate
46+
resource "google_certificate_manager_certificate" "default" {
47+
name = "dns-cert"
48+
scope = "ALL_REGIONS"
49+
managed {
50+
domains = [
51+
google_certificate_manager_dns_authorization.default.domain,
52+
]
53+
dns_authorizations = [
54+
google_certificate_manager_dns_authorization.default.id,
55+
]
56+
}
57+
}

infrastructure/application/state.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
locals {
2+
statebucket = yamldecode(file("../../config.yml")).statebucket
3+
}
4+
15
terraform {
26
backend "gcs" {
37
bucket = "coilysiren-k8s-gpc-tfstate-0"

infrastructure/foundation/state.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
locals {
2+
statebucket = yamldecode(file("../../config.yml")).statebucket
3+
}
4+
15
terraform {
26
backend "gcs" {
3-
bucket = "coilysiren-k8s-gpc-tfstate-0"
7+
bucket = local.statebucket
48
prefix = "terraform/state"
59
}
610
}
@@ -20,7 +24,7 @@ data "google_project" "default" {}
2024
#
2125
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket
2226
resource "google_storage_bucket" "default" {
23-
name = "coilysiren-k8s-gpc-tfstate-0"
27+
name = statebucket
2428
location = "US"
2529
force_destroy = true
2630
project = data.google_project.default.project_id

infrastructure/kubconfig.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ items:
44
kind: Ingress
55
metadata:
66
annotations:
7-
cert-manager.io/issuer: letsencrypt-staging
8-
kubernetes.io/ingress.allow-http: 'true'
7+
kubernetes.io/ingress.allow-http: "true"
98
kubernetes.io/ingress.class: gce
9+
networking.gke.io/managed-certificates: dns-cert
1010
name: application
1111
spec:
1212
defaultBackend:
@@ -18,21 +18,6 @@ items:
1818
tls:
1919
- hosts:
2020
- gke-test-2.coilysiren.me
21-
secretName: tls-secret
22-
- apiVersion: cert-manager.io/v1
23-
kind: Issuer
24-
metadata:
25-
name: letsencrypt-staging
26-
spec:
27-
acme:
28-
29-
privateKeySecretRef:
30-
name: letsencrypt-staging
31-
server: https://acme-staging-v02.api.letsencrypt.org/directory
32-
solvers:
33-
- http01:
34-
ingress:
35-
name: application
3621
- apiVersion: v1
3722
kind: Service
3823
metadata:
@@ -70,10 +55,10 @@ items:
7055
app: application
7156
spec:
7257
containers:
73-
- image: us-central1-docker.pkg.dev/root-territory-384205/repository/gke-test-2:certs-8ac23d2-kai
58+
- image: us-central1-docker.pkg.dev/root-territory-384205/repository/gke-test-2:certs-6bbf26e-kai
7459
name: application
7560
ports:
7661
- containerPort: 8080
7762
kind: List
7863
metadata:
79-
resourceVersion: ''
64+
resourceVersion: ""

infrastructure/tls-secret.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

tasks.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ def domain(self) -> str:
7171
"""get the domain"""
7272
return self.config["domain"]
7373

74-
@property
75-
def cert_manager(self) -> str:
76-
"""Format a full URL to a remote cert-manager.yaml file"""
77-
return (
78-
f"https://github.com/cert-manager/cert-manager/releases/download/"
79-
f'{self.config["cert-manager-version"]}/cert-manager.yaml'
80-
)
81-
8274
@property
8375
def project(self) -> str:
8476
"""get the project id"""
@@ -197,7 +189,6 @@ def deploy(ctx: [invoke.Context, Context]):
197189
kubeconfig = ctx.update_domain(kubeconfig, ctx.domain)
198190
ctx.write_kubeconfig("infrastructure/kubconfig.yml", kubeconfig)
199191
ctx.run("kubectl apply -f infrastructure/kubconfig.yml")
200-
ctx.run(f"kubectl apply -f {ctx.cert_manager}")
201192

202193
# deploy application infrastructure
203194
ctx.run("cd infrastructure/application && terraform init")

0 commit comments

Comments
 (0)