Skip to content

Commit 572fae8

Browse files
jsimonwebcrwilcox
andauthored
Update Cloud SQL sample apps with Kubernetes Engine yaml files. (GoogleCloudPlatform#7015)
* Update Cloud SQL sample apps w/ Kubernetes Engine. * Address review comments. * Add license. Co-authored-by: Christopher Wilcox
1 parent 94ed3b4 commit 572fae8

File tree

6 files changed

+260
-0
lines changed

6 files changed

+260
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START cloud_sql_mysql_sqlalchemy_gke_quickstart_deployment]
16+
apiVersion: apps/v1
17+
kind: Deployment
18+
metadata:
19+
name: gke-cloud-sql-quickstart
20+
spec:
21+
selector:
22+
matchLabels:
23+
app: gke-cloud-sql-app
24+
template:
25+
metadata:
26+
labels:
27+
app: gke-cloud-sql-app
28+
spec:
29+
serviceAccountName:
30+
containers:
31+
- name: gke-cloud-sql-app
32+
# Replace with your Artifact Registry location (e.g., us-central1).
33+
# Replace with your project ID.
34+
image: -docker.pkg.dev//gke-cloud-sql-repo/gke-sql:latest
35+
# This app listens on port 8080 for web traffic by default.
36+
ports:
37+
- containerPort: 8080
38+
env:
39+
- name: PORT
40+
value: "8080"
41+
- name: DB_HOST
42+
value: "127.0.0.1"
43+
- name: DB_PORT
44+
value: "3306"
45+
- name: DB_USER
46+
valueFrom:
47+
secretKeyRef:
48+
name:
49+
key: username
50+
- name: DB_PASS
51+
valueFrom:
52+
secretKeyRef:
53+
name:
54+
key: password
55+
- name: DB_NAME
56+
valueFrom:
57+
secretKeyRef:
58+
name:
59+
key: database
60+
- name: cloud-sql-proxy
61+
# This uses the latest version of the Cloud SQL proxy
62+
# It is recommended to use a specific version for production environments.
63+
# See: https://github.com/GoogleCloudPlatform/cloudsql-proxy
64+
image: gcr.io/cloudsql-docker/gce-proxy:latest
65+
command:
66+
- "/cloud_sql_proxy"
67+
68+
# If connecting from a VPC-native GKE cluster, you can use the
69+
# following flag to have the proxy connect over private IP
70+
# - "-ip_address_types=PRIVATE"
71+
72+
# tcp should be set to the port the proxy should listen on
73+
# and should match the DB_PORT value set above.
74+
# Defaults: MySQL: 3306, Postgres: 5432, SQLServer: 1433
75+
- "-instances==tcp:3306"
76+
securityContext:
77+
# The default Cloud SQL proxy image runs as the
78+
# "nonroot" user and group (uid: 65532) by default.
79+
runAsNonRoot: true
80+
# [END cloud_sql_mysql_sqlalchemy_gke_quickstart_deployment]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START cloud_sql_mysql_sqlalchemy_gke_quickstart_sa]
16+
apiVersion: v1
17+
kind: ServiceAccount
18+
metadata:
19+
name: # TODO(developer): replace this value.
20+
# [END cloud_sql_mysql_sqlalchemy_gke_quickstart_sa]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START cloud_sql_mysql_sqlalchemy_gke_quickstart_service]
16+
# The service provides a load-balancing proxy over the gke-cloud-sql-app
17+
# pods. By specifying the type as a 'LoadBalancer', Kubernetes Engine will
18+
# create an external HTTP load balancer.
19+
apiVersion: v1
20+
kind: Service
21+
metadata:
22+
name: gke-cloud-sql-app
23+
spec:
24+
type: LoadBalancer
25+
selector:
26+
app: gke-cloud-sql-app
27+
ports:
28+
- port: 80
29+
targetPort: 8080
30+
# [END cloud_sql_mysql_sqlalchemy_gke_quickstart_service]
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START cloud_sql_postgres_sqlalchemy_gke_quickstart_deployment]
16+
apiVersion: apps/v1
17+
kind: Deployment
18+
metadata:
19+
name: gke-cloud-sql-quickstart
20+
spec:
21+
selector:
22+
matchLabels:
23+
app: gke-cloud-sql-app
24+
template:
25+
metadata:
26+
labels:
27+
app: gke-cloud-sql-app
28+
spec:
29+
serviceAccountName:
30+
containers:
31+
- name: gke-cloud-sql-app
32+
# Replace with your Artifact Registry location (e.g., us-central1).
33+
# Replace with your project ID.
34+
image: -docker.pkg.dev//gke-cloud-sql-repo/gke-sql:latest
35+
# This app listens on port 8080 for web traffic by default.
36+
ports:
37+
- containerPort: 8080
38+
env:
39+
- name: PORT
40+
value: "8080"
41+
- name: DB_HOST
42+
value: "127.0.0.1"
43+
- name: DB_PORT
44+
value: "5432"
45+
- name: DB_USER
46+
valueFrom:
47+
secretKeyRef:
48+
name:
49+
key: username
50+
- name: DB_PASS
51+
valueFrom:
52+
secretKeyRef:
53+
name:
54+
key: password
55+
- name: DB_NAME
56+
valueFrom:
57+
secretKeyRef:
58+
name:
59+
key: database
60+
- name: cloud-sql-proxy
61+
# This uses the latest version of the Cloud SQL proxy
62+
# It is recommended to use a specific version for production environments.
63+
# See: https://github.com/GoogleCloudPlatform/cloudsql-proxy
64+
image: gcr.io/cloudsql-docker/gce-proxy:latest
65+
command:
66+
- "/cloud_sql_proxy"
67+
68+
# If connecting from a VPC-native GKE cluster, you can use the
69+
# following flag to have the proxy connect over private IP
70+
# - "-ip_address_types=PRIVATE"
71+
72+
# tcp should be set to the port the proxy should listen on
73+
# and should match the DB_PORT value set above.
74+
# Defaults: MySQL: 3306, Postgres: 5432, SQLServer: 1433
75+
- "-instances==tcp:5432"
76+
securityContext:
77+
# The default Cloud SQL proxy image runs as the
78+
# "nonroot" user and group (uid: 65532) by default.
79+
runAsNonRoot: true
80+
# [END cloud_sql_postgres_sqlalchemy_gke_quickstart_deployment]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START cloud_sql_postgres_sqlalchemy_gke_quickstart_sa]
16+
apiVersion: v1
17+
kind: ServiceAccount
18+
metadata:
19+
name: # TODO(developer): replace this value
20+
# [END cloud_sql_postgres_sqlalchemy_gke_quickstart_sa]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START cloud_sql_postgres_sqlalchemy_gke_quickstart_service]
16+
# The service provides a load-balancing proxy over the gke-cloud-sql-app
17+
# pods. By specifying the type as a 'LoadBalancer', Kubernetes Engine will
18+
# create an external HTTP load balancer.
19+
apiVersion: v1
20+
kind: Service
21+
metadata:
22+
name: gke-cloud-sql-app
23+
spec:
24+
type: LoadBalancer
25+
selector:
26+
app: gke-cloud-sql-app
27+
ports:
28+
- port: 80
29+
targetPort: 8080
30+
# [END cloud_sql_postgres_sqlalchemy_gke_quickstart_service]

0 commit comments

Comments
 (0)