Skip to content

Commit c54f4fc

Browse files
committed
new gke cluster
1 parent 5e00f3c commit c54f4fc

11 files changed

+228
-32
lines changed

Diff for: .github/workflows/deploy-staging.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ on:
88
- completed
99
env:
1010
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
11-
GKE_CLUSTER: p5js-web-editor-cluster
12-
GKE_ZONE: us-east1-c
11+
GKE_CLUSTER: p5-gke-cluster
12+
GKE_ZONE: us-east4
1313
DEPLOYMENT_NAME: web-editor-node
1414
IMAGE: ${{ secrets.DOCKER_USERNAME }}/p5.js-web-editor-staging
1515
jobs:

Diff for: .github/workflows/deploy.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ on:
88
- completed
99
env:
1010
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
11-
GKE_CLUSTER: p5js-web-editor-cluster
12-
GKE_ZONE: us-east1-c
11+
GKE_CLUSTER: p5-gke-cluster
12+
GKE_ZONE: us-east4
1313
DEPLOYMENT_NAME: web-editor-node
1414
IMAGE: ${{ secrets.DOCKER_USERNAME }}/p5.js-web-editor
1515
jobs:
@@ -60,6 +60,6 @@ jobs:
6060
# Deploy the Docker image to the GKE cluster
6161
- name: Deploy
6262
run: |-
63-
kubectl set image deployment/$DEPLOYMENT_NAME web-editor-app=index.docker.io/$IMAGE:$GITHUB_SHA
63+
kubectl set image deployment/$DEPLOYMENT_NAME web-editor-app=index.docker.io/$IMAGE:$GITHUB_SHA --namespace=production
6464
kubectl get services -o wide
6565

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ cert_chain.crt
1616
localhost.crt
1717
localhost.key
1818
privkey.pem
19+
terraform/.terraform/
1920

2021
storybook-static
2122
duplicates.json

Diff for: deploy.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ gcloud --quiet container clusters get-credentials $CLUSTER_NAME_PRD
2020
kubectl config view
2121
kubectl config current-context
2222

23-
kubectl set image deployment/${KUBE_DEPLOYMENT_NAME} ${KUBE_DEPLOYMENT_CONTAINER_NAME}=index.docker.io/$DOCKER_USERNAME/$DOCKER_REPOSITORY:$TRAVIS_TAG
23+
kubectl set image deployment/${KUBE_DEPLOYMENT_NAME} ${KUBE_DEPLOYMENT_CONTAINER_NAME}=index.docker.io/$DOCKER_USERNAME/$DOCKER_REPOSITORY:$TRAVIS_TAG --namespace=production

Diff for: kubernetes_app.yml

+44-26
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
1-
apiVersion: extensions/v1beta1
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: production
5+
labels:
6+
name: production
7+
---
8+
apiVersion: networking.k8s.io/v1
29
kind: Ingress
310
metadata:
4-
name: editor-ingress
11+
name: web-editor-ingress
12+
namespace: production
513
annotations:
6-
kubernetes.io/ingress.global-static-ip-name: "web-editor-ip"
14+
kubernetes.io/ingress.global-static-ip-name: "production-p5-web-editor-ip"
715
spec:
8-
backend:
9-
serviceName: web-editor-node
10-
servicePort: 8000
16+
defaultBackend:
17+
service:
18+
name: web-editor-node
19+
port:
20+
number: 8000
1121
---
12-
apiVersion: extensions/v1beta1
22+
apiVersion: networking.k8s.io/v1
1323
kind: Ingress
1424
metadata:
1525
name: preview-editor-ingress
26+
namespace: production
1627
annotations:
1728
# need to make another global static ip
18-
kubernetes.io/ingress.global-static-ip-name: "preview-editor-ip"
29+
kubernetes.io/ingress.global-static-ip-name: "production-p5-preview-editor-ip"
1930
spec:
20-
backend:
21-
serviceName: web-editor-node
22-
servicePort: 8002
31+
defaultBackend:
32+
service:
33+
name: web-editor-node
34+
port:
35+
number: 8002
2336
---
2437
apiVersion: v1
2538
kind: Service
2639
metadata:
2740
name: web-editor-node
41+
namespace: production
2842
labels:
2943
app: web-editor
3044
spec:
@@ -46,11 +60,12 @@ apiVersion: apps/v1
4660
kind: Deployment
4761
metadata:
4862
name: web-editor-node
63+
namespace: production
4964
spec:
5065
selector:
5166
matchLabels:
5267
app: web-editor
53-
replicas: 1
68+
replicas: 3
5469
template:
5570
metadata:
5671
labels:
@@ -81,9 +96,8 @@ spec:
8196
apiVersion: autoscaling/v1
8297
kind: HorizontalPodAutoscaler
8398
metadata:
84-
annotations:
8599
name: web-editor-node
86-
namespace: default
100+
namespace: production
87101
spec:
88102
maxReplicas: 6
89103
minReplicas: 2
@@ -142,29 +156,33 @@ metadata:
142156
labels:
143157
name: staging
144158
---
145-
apiVersion: extensions/v1beta1
159+
apiVersion: networking.k8s.io/v1
146160
kind: Ingress
147161
metadata:
148-
name: staging-editor-ingress
162+
name: web-editor-ingress
149163
namespace: staging
150164
annotations:
151-
kubernetes.io/ingress.global-static-ip-name: "web-editor-staging-ip"
165+
kubernetes.io/ingress.global-static-ip-name: "staging-p5-web-editor-ip"
152166
spec:
153-
backend:
154-
serviceName: web-editor-node
155-
servicePort: 8001
167+
defaultBackend:
168+
service:
169+
name: web-editor-node
170+
port:
171+
number: 8001
156172
---
157-
apiVersion: extensions/v1beta1
173+
apiVersion: networking.k8s.io/v1
158174
kind: Ingress
159175
metadata:
160-
name: staging-preview-ingress
176+
name: preview-editor-ingress
161177
namespace: staging
162178
annotations:
163-
kubernetes.io/ingress.global-static-ip-name: "preview-staging-ip"
179+
kubernetes.io/ingress.global-static-ip-name: "staging-p5-preview-editor-ip"
164180
spec:
165-
backend:
166-
serviceName: web-editor-node
167-
servicePort: 8003
181+
defaultBackend:
182+
service:
183+
name: web-editor-node
184+
port:
185+
number: 8003
168186
---
169187
apiVersion: v1
170188
kind: Service

Diff for: terraform/.terraform.lock.hcl

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: terraform/README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#### Running Terraform
2+
3+
1. Auth with GCP by running:
4+
```
5+
$ gcloud auth application-default login
6+
```
7+
8+
2. If it's your first time running the terraform you will need to init to download the module code:
9+
```
10+
$ terraform init
11+
```
12+
13+
3. Run plan to see the changes terraform will make:
14+
```
15+
$ terraform plan
16+
```
17+
18+
4. Run apply if the changes look correct and terraform will prompt you to confirm the changes:
19+
```
20+
$ terraform apply
21+
```
22+
23+
#### Using Kubectl (or other clients) to interact with the cluster
24+
25+
##### New cluster
26+
1. Auth with GCP by running:
27+
```
28+
$ gcloud auth login
29+
```
30+
31+
2. Set the project as the default:
32+
```
33+
$ gcloud config set project p5js-web-editor-project
34+
```
35+
36+
3. Download the kubeconfig from gcloud by running the following command:
37+
```
38+
gcloud container clusters get-credentials p5-gke-cluster --zone us-east4
39+
```
40+
41+
4. Run kubectl commands as normal:
42+
```
43+
$ kubectl get pods
44+
```
45+
46+
##### Legacy cluster
47+
1. Auth with GCP by running:
48+
```
49+
$ gcloud auth login
50+
```
51+
52+
2. Set the project as the default:
53+
```
54+
$ gcloud config set project p5js-web-editor-project
55+
```
56+
57+
3. Download the kubeconfig from gcloud by running the following command:
58+
```
59+
$ gcloud container clusters get-credentials p5js-web-editor-cluster --zone us-east1-c
60+
```
61+
62+
4. Run kubectl commands as normal:
63+
```
64+
$ kubectl get pods
65+
```

Diff for: terraform/backend.tf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
terraform {
2+
backend "gcs" {
3+
bucket = "p5js-terraform-state"
4+
prefix = "terraform/state"
5+
}
6+
}

Diff for: terraform/main.tf

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
provider "google" {
2+
project = var.project
3+
region = var.region
4+
}
5+
6+
resource "google_container_cluster" "primary" {
7+
name = "p5-gke-cluster"
8+
location = var.region
9+
network = google_compute_network.p5.name
10+
subnetwork = google_compute_subnetwork.p5.name
11+
min_master_version = var.gke_version
12+
13+
release_channel {
14+
channel = "UNSPECIFIED"
15+
}
16+
17+
# We can't create a cluster with no node pool defined, but we want to only use
18+
# separately managed node pools. So we create the smallest possible default
19+
# node pool and immediately delete it.
20+
remove_default_node_pool = true
21+
initial_node_count = 1
22+
}
23+
24+
resource "google_container_node_pool" "primary" {
25+
name = "primary-pool"
26+
location = var.region
27+
cluster = google_container_cluster.primary.name
28+
version = var.gke_version
29+
node_count = 1
30+
31+
node_config {
32+
disk_size_gb = 100
33+
machine_type = "n1-standard-1"
34+
}
35+
36+
autoscaling {
37+
min_node_count = 1
38+
max_node_count = 10
39+
}
40+
41+
management {
42+
auto_repair = true
43+
auto_upgrade = false
44+
}
45+
}

Diff for: terraform/variables.tf

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
variable "project" {
2+
type = string
3+
default = "p5js-web-editor-project"
4+
}
5+
6+
variable "region" {
7+
type = string
8+
default = "us-east4"
9+
}
10+
11+
variable "gke_version" {
12+
type = string
13+
default = "1.22.8-gke.200"
14+
}

Diff for: terraform/vpc.tf

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
resource "google_compute_network" "p5" {
2+
name = "${var.project}-vpc"
3+
auto_create_subnetworks = false
4+
}
5+
6+
resource "google_compute_subnetwork" "p5" {
7+
name = "${var.project}-subnet"
8+
network = google_compute_network.p5.name
9+
ip_cidr_range = "10.10.0.0/24"
10+
region = var.region
11+
}
12+
13+
resource "google_compute_global_address" "production_p5_web_editor_ip" {
14+
name = "production-p5-web-editor-ip"
15+
}
16+
17+
resource "google_compute_global_address" "production_p5_preview_editor_ip" {
18+
name = "production-p5-preview-editor-ip"
19+
}
20+
21+
resource "google_compute_global_address" "staging_p5_web_editor_ip" {
22+
name = "staging-p5-web-editor-ip"
23+
}
24+
25+
resource "google_compute_global_address" "staging_p5_preview_editor_ip" {
26+
name = "staging-p5-preview-editor-ip"
27+
}

0 commit comments

Comments
 (0)