-
Notifications
You must be signed in to change notification settings - Fork 353
/
App Dev: Deploying the Application into Kubernetes Engine - Python
143 lines (122 loc) · 4.68 KB
/
App Dev: Deploying the Application into Kubernetes Engine - Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
export ZONE=
export REGION="${ZONE%-*}"
gcloud auth list
git clone https://github.com/GoogleCloudPlatform/training-data-analyst
ln -s ~/training-data-analyst/courses/developingapps/v1.2/python/kubernetesengine ~/kubernetesengine
cd ~/kubernetesengine/start
. prepare_environment.sh
gcloud beta container --project "$DEVSHELL_PROJECT_ID" clusters create "quiz-cluster" --zone "$ZONE" --no-enable-basic-auth --cluster-version "1.27.8-gke.1067004" --release-channel "regular" --machine-type "e2-medium" --image-type "COS_CONTAINERD" --disk-type "pd-balanced" --disk-size "100" --metadata disable-legacy-endpoints=true --scopes "https://www.googleapis.com/auth/cloud-platform" --num-nodes "3" --logging=SYSTEM,WORKLOAD --monitoring=SYSTEM --enable-ip-alias --network "projects/$DEVSHELL_PROJECT_ID/global/networks/default" --subnetwork "projects/$DEVSHELL_PROJECT_ID/regions/$REGION/subnetworks/default" --no-enable-intra-node-visibility --default-max-pods-per-node "110" --security-posture=standard --workload-vulnerability-scanning=disabled --no-enable-master-authorized-networks --addons HorizontalPodAutoscaling,HttpLoadBalancing,GcePersistentDiskCsiDriver --enable-autoupgrade --enable-autorepair --max-surge-upgrade 1 --max-unavailable-upgrade 0 --binauthz-evaluation-mode=DISABLED --enable-managed-prometheus --enable-shielded-nodes --node-locations "$ZONE"
gcloud container clusters get-credentials quiz-cluster --zone "$ZONE" --project $DEVSHELL_PROJECT_ID
kubectl get pods
cat > frontend/Dockerfile <<EOF_END
FROM gcr.io/google_appengine/python
RUN virtualenv -p python3.7 /env
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
ADD . /app
CMD gunicorn -b 0.0.0.0:$PORT quiz:app
EOF_END
cat > backend/Dockerfile <<EOF_END
FROM gcr.io/google_appengine/python
RUN virtualenv -p python3.7 /env
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
ADD . /app
CMD python -m quiz.console.worker
EOF_END
gcloud builds submit -t gcr.io/$DEVSHELL_PROJECT_ID/quiz-frontend ./frontend/
gcloud builds submit -t gcr.io/$DEVSHELL_PROJECT_ID/quiz-backend ./backend/
cat > frontend-deployment.yaml <<EOF_END
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apps/v1
kind: Deployment
metadata:
name: quiz-frontend
labels:
app: quiz-app
spec:
replicas: 3
selector:
matchLabels:
app: quiz-app
tier: frontend
template:
metadata:
labels:
app: quiz-app
tier: frontend
spec:
containers:
- name: quiz-frontend
image: gcr.io/$GCLOUD_PROJECT/quiz-frontend
imagePullPolicy: Always
ports:
- name: http-server
containerPort: 8080
env:
- name: GCLOUD_PROJECT
value: $GCLOUD_PROJECT
- name: GCLOUD_BUCKET
value: $GCLOUD_BUCKET
EOF_END
cat > backend-deployment.yaml <<EOF_END
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apps/v1
kind: Deployment
metadata:
name: quiz-backend
labels:
app: quiz-app
spec:
replicas: 2
selector:
matchLabels:
app: quiz-app
tier: backend
template:
metadata:
labels:
app: quiz-app
tier: backend
spec:
containers:
- name: quiz-backend
image: gcr.io/$GCLOUD_PROJECT/quiz-backend
imagePullPolicy: Always
env:
- name: GCLOUD_PROJECT
value: $GCLOUD_PROJECT
- name: GCLOUD_BUCKET
value: $GCLOUD_BUCKET
EOF_END
kubectl create -f ./frontend-deployment.yaml
kubectl create -f ./backend-deployment.yaml
kubectl create -f ./frontend-service.yaml