Developed a containerized service which publishes a data as a message to pub sub and then push the container image to GCR and deploy service using GKE
http://34.94.209.219/
- You're new to Google Cloud, create an account.
- The Google Cloud Console, on the project selector page, select or create a Google Cloud project (capstone1-project).
- Create a bucket named currency-bucket-egen.
- Enable the Artifact Registry, Cloud Build, Cloud Function and Google Kubernetes Engine APIs.
- Install and initialize cloud SDK
- Go to the Pub/Sub topics page in the Cloud Console.
- Click Create a topic named currency.
- Create a subscription
- Leave the delivery type as Pull.
- Create a cloud function, name the cloud function as loadStorage using US-west2 region and pubsub as a trigger.
- upload main.py and entry point as currency and then deploy it.
- install all the files required in requirements.txt
- GetDataToPub.py is responsible to get data from the API and publish it to the Pub and from there cloud function will sense the event and trigger the subscription. and the data will get to the bucket.
On the cloudshell- gcloud components install kubectl create a directory on cloud shell editor (egen-capstone) cd into the directory you just created.
app.py has a restful api which works with the http and whenever that link is hit the GetDataToPub.py is triggred and then the data is stored to the Google cloud bucket.
- To containerize the sample app, create a new file named Dockerfile in the same directory as the source files.
- Add a .dockerignore file to ensure that local files don't affect the container build process (hidden file).
- you will get the Dockerfile from this repository.
gcloud artifacts repositories create capstone-repo \
--project=capstone1-project-326220 \
--repository-format=docker \
--location=us-west2 \
--description="Docker repository for captone project"
gcloud builds submit \
--tag us-west2-docker.pkg.dev/capstone1-project-326220/capstone-repo/egen-capstone
gcloud container clusters create egen-cluster \
--zone us-west2
kubectl get nodes
To deploy your app to the GKE cluster you created, you need two Kubernetes objects.
A Deployment - to define your app. A Service - to define how to access your app.
- Copy the deployment.yaml file in the same directory as your other files.
- Deploy the resource to the cluster:
kubectl apply -f deployment.yaml
- Track the deployment:
kubectl get deployments
- Copy the file service.yaml in the same directory as your other source files.
- Create the Hello World Service:
kubectl apply -f service.yaml
- Get the external IP address of the Service:
kubectl get services
- View a deployed app: http://<external_ip>