In this lab you’ll perform the following:
Download sample app from GitHub
Deploy to App Engine
Deploy to Kubernetes
Deploy to Cloud Run
# Make local folder
mkdir gcp-course
cd gcp-course
# Clone repo and access folder
git clone https://GitHub.com/GoogleCloudPlatform/training-data-analyst.git
cd training-data-analyst/courses/design-process/deploying-apps-to-gcp
# Build image from app and run locally/cloud console for preview
docker build -t test-python .
docker run --rm -p 8080:8080 test-python
# Create app.yaml with…
runtime: python39
# Deploy to first revision to App Engine
gcloud app create --region=your-region
gcloud app deploy --version=one --quiet
# Modify for App Engine and deploy, but do not promote just yet (for testing)
# Hello App Engine
gcloud app deploy --version=two --no-promote --quiet
# Manually adjust Splilt Traffic in App Engine > Versioning
# Create Kubernetes Cluster manually
# Use Console to generate console connect command and connect
# Test connection with kubectl command
kubectl get nodes
# Modify function in main.py. The “title” needs to be updated
@app.route("/")
def main():
model = {"title" "Hello Kubernetes Engine"}
return render_template('index.html', model=model)
# Create kubernetes-config.yaml for deployment to Cloud Run
cat > role-definition.yaml <<EOF_END
apiVersion: apps/v1
kind: Deployment
metadata:
name: devops-deployment
labels:
app: devops
tier: frontend
spec:
replicas: 3
selector:
matchLabels:
app: devops
tier: frontend
template:
metadata:
labels:
app: devops
tier: frontend
spec:
containers:
- name: devops-demo
image: <YOUR IMAGE PATH HERE>
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: devops-deployment-lb
labels:
app: devops
tier: frontend-lb
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: devops
tier: frontend
EOF_END
* remember to return to this file and update the image path
# Create Artifact Registry repo
gcloud artifacts repositories create devops-demo \
--repository-format=docker \
--location=us-east4
# Allow Docker to auth into repo
gcloud auth configure-docker us-east4-docker.pkg.dev
# Use Cloud Build to create image and store in repo
gcloud builds submit --tag us-east4-docker.pkg.dev/$DEVSHELL_PROJECT_ID/devops-demo/devops-image:v0.2 .
# Get image from the build and add it to your deployment file
# Deploy to kubernetes
kubectl apply -f kubernetes-config.yaml
# Check Kubernetes statuses
kubectl get pods
kubectl get svc