DEV Community

Vignesh C
Vignesh C

Posted on

GCP-DevOps Pipeline Continuous Integration Deployment

DevOps and CI/CD:

CI, CD and DevOps have taken over the software development world by storm. Most companies today realize that the practices of continuous integration (CI) and continuous delivery (CD) will yield tremendous benefits like increased business revenue and faster time-to-market. The demand for these skills has been steadily rising over the last few years.

There are a plethora of tools available in the CI/CD/DevOps landscape today. Implementing continuous integration, continuous delivery and continuous deployment with these tools and frameworks can help us immensely in modernizing our software development lifecycle. It catches us bugs early, improves time to market, reduces latency and increases the quality of our software products. This, in turn, reduces the overall cost for software development in startups and enterprise alike.

The demand for professionals who have experience with CI/CD/DevOps has been growing steadily over the last few years. The salaries for these skills have gone through the roof and are only bound to go up as the demand for these skills increases. Professionals with CI / CD / DevOps skill set can demand as much as $150K as their yearly compensation as per latest US job and salary surveys.

Building a DevOps Pipeline - Google Cloud Platform (GCP)

Build a continuous integration pipeline using Cloud Source Repositories, Cloud Build, build triggers, and Container Registry.

Alt Text

‣ Create a simple Python Flask web application

‣ Define a Docker Build

‣ Manage Docker Images with Cloud Build and Container Registry

‣ Automate Builds with Triggers

‣ Test the Build Changes

Deploying Apps to Google Cloud

Deploy applications to the Google Cloud services App Engine, Kubernetes Engine, and Cloud Run.

Alt Text

• Deploy to App Engine

• Deploy to Kubernetes Engine

• Deploy to Cloud Run

Deploy to App Engine

App Engine is a completely automated deployment platform. It supports many languages, including Python, Java, JavaScript, and Go. To use it, we create a configuration file and deploy applications with couple of simple commands. We create a file named app.yaml and deploy it to App Engine.

gcloud app create --region=us-central
Enter fullscreen mode Exit fullscreen mode
gcloud app deploy --version=one --quiet
Enter fullscreen mode Exit fullscreen mode
gcloud app deploy --version=two --no-promote --quiet
Enter fullscreen mode Exit fullscreen mode

Deploy to Kubernetes Engine

Kubernetes Engine allows you to create a cluster of machines and deploy any number of applications to it. Kubernetes abstracts the details of managing machines and allows you to automate the deployment of your applications with simple CLI commands. To deploy an application to Kubernetes, you first need to create the cluster. Then you need to add a configuration file for each application you will deploy to the cluster.

Add a file named kubernetes-config.yaml

https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/

To use Kubernetes Engine, you need to build a Docker image.

gcloud builds submit --tag gcr.io/$DEVSHELL_PROJECT_ID/devops-image:v0.2 . 
Enter fullscreen mode Exit fullscreen mode

Enter the following Kubernetes command to deploy your application:

kubectl apply -f kubernetes-config.yaml 
Enter fullscreen mode Exit fullscreen mode

In the configuration file, three replicas of the application were specified. Type the following command to see whether three instances have been created:

kubectl get pods 
Enter fullscreen mode Exit fullscreen mode

A load balancer was also added in the configuration file. Type the following command to see whether it was created:

kubectl get services 
Enter fullscreen mode Exit fullscreen mode

Deploy to Cloud Run

Cloud Run simplifies and automates deployments to Kubernetes. When you use Cloud Run, you don't need a configuration file. You simply choose a cluster for your application. With Cloud Run, you can use a cluster managed by Google, or you can use your own Kubernetes cluster.
To use Cloud Run, your application needs to be deployed using a Docker image and it must be stateless.

To use Cloud Run, you need to build a Docker image.

gcloud builds submit --tag gcr.io/$DEVSHELL_PROJECT_ID/cloud-run-image:v0.1 . 
Enter fullscreen mode Exit fullscreen mode
  1. When the build completes, in the GCP Navigation menu, click Cloud Run.

  2. Cloud Run is not enabled by default. Click Start using Cloud Run to enable the API.

  3. Click Create service.

  4. Accept the defaults in the Deployment platform section.

  5. Click the Select link in the Container image URL text box. In the resulting dialog, expand cloud-run-image and select the image listed. Then click Continue.

  6. Finally, click Create. When a green check appears, click on the URL that is automatically generated for the application.



Check out my GitHub for more details:

GitHub logo IamVigneshC / GCP-DevOpsPipelineContinuousIntegration-Deployment

Build a continuous integration pipeline using Cloud Source Repositories, Cloud Build, build triggers, and Container Registry. Deploy applications to the Google Cloud services App Engine, Kubernetes Engine, and Cloud Run.

Building a DevOps Pipeline - Google Cloud Platform (GCP)

Build a continuous integration pipeline using Cloud Source Repositories, Cloud Build, build triggers, and Container Registry.

Image of DevOps

‣ Create a simple Python Flask web application

‣ Define a Docker Build

‣ Manage Docker Images with Cloud Build and Container Registry

‣ Automate Builds with Triggers

‣ Test the Build Changes

Deploying Apps to Google Cloud

Deploy applications to the Google Cloud services App Engine, Kubernetes Engine, and Cloud Run.

Image of Deploy

• Deploy to App Engine

• Deploy to Kubernetes Engine

• Deploy to Cloud Run

Deploy to App Engine

App Engine is a completely automated deployment platform. It supports many languages, including Python, Java, JavaScript, and Go. To use it, we create a configuration file and deploy applications with couple of simple commands. We create a file named app.yaml and deploy it to App Engine.

gcloud app create --region=us-central

gcloud app deploy --version=one

main.py:

from flask import Flask, render_template, request

app = Flask(__name__)

@app.route("/")
def main():
    model = {"title": "Hello DevOps Fans."}
    return render_template('index.html', model=model)

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8080, debug=True, threaded=True)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)