11Steps for deploying a stateful containerized application on GKE
22----------------------------------------------------------------
3+
4+ 1) Install Docker and gcloud CLI
35Create free tier EC2 instance
46- create Ubuntu 16.04 EC2 instance (free tier). Allow ingress for port 22 from anywhere (0.0.0.0/0)
57SSH into EC2 instance
@@ -11,25 +13,49 @@ cd Containers/Kubernetes-examples/GCP/
1113./install-docker-ubuntu.sh
1214exit from EC2 instance
1315SSH back into EC2 instance
16+
17+
18+ 2) Configure authentication for gcloud CLI
1419gcloud auth login <your-gmail-address>
1520Create Project in Google Cloud Console
1621export PROJECT_ID=<Project-ID-from-previous-step>
1722export CLOUDSDK_COMPUTE_ZONE=us-central1-b
1823gcloud config set project ${PROJECT_ID}
24+
25+
26+ 3) Build and Push Application Docker container to Google Container Registry (GCR)
1927cd greetings
2028docker build -t gcr.io/${PROJECT_ID}/greetings:v1 .
2129gcloud docker -- push gcr.io/${PROJECT_ID}/greetings:v1
30+
31+
32+ 4) Create a GKE cluster
2233gcloud container clusters create --machine-type=g1-small --num-nodes=1 testcluster1
34+
35+
36+ 5) Create a Google Cloud SQL instance
2337gcloud sql instances create instance1 --tier=db-f1-micro --authorized-networks=0.0.0.0/0
24- gcloud components install kubectl
38+
39+
40+ 6) Create testdb database on the Cloud SQL instance
2541gcloud sql users set-password root % --instance instance1 --password 'testpass123!@#'
2642sudo apt-get install mysql-client
2743gcloud sql instances list
2844mysql -h <IP-address-of-SQL-Instance> --user=root --password='testpass123!@#'
2945mysql>create database testdb;
46+
47+
48+ 7) Install kubectl
49+ gcloud components install kubectl
50+
51+
52+ 8) Deploy application container
3053Edit greetings-deployment.yaml and set the environment variables
3154kubectl create -f greetings-deployment.yaml
3255kubectl expose deployments --port=80 --target-port=5000 --type=LoadBalancer greetings-deployment
56+
57+
58+ 9) Verify if relevant Kubernetes Objects have been created or not
3359kubectl get services
3460kubectl get deployments
3561kubectl get pods
@@ -38,6 +64,9 @@ kubectl describe deployments <deployment-name>
3864kubectl describe service <service-name>
3965Once you get EXTERNAL-IP of the service, open it up in browser (It may take couple of minutes for the application to respond)
4066kubectl logs <pod-name>
67+
68+
69+ 10) Clean-up steps (Do these only after your assignment has been graded)
4170kubectl delete service <service-name>
4271kubectl delete deployment <deployment-name>
4372Delete the GKE cluster from Google Cloud Console
0 commit comments