GCP-DevOps Pipeline Continuous Integration Deployment
Tags: devops, kubernetes, cloud, googlecloud
Published: 2020-12-28 05:26:48

# 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](https://dev-to-uploads.s3.amazonaws.com/i/t7mhujlxb3ztydfm9hrw.jpg)


‣ 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](https://dev-to-uploads.s3.amazonaws.com/i/dgr5juok7xl46txrfvgw.png)

•	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 --quiet
```

```
gcloud app deploy --version=two --no-promote --quiet
```


## 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 the following Kubernetes command to deploy your application:

``` 
kubectl apply -f kubernetes-config.yaml 
```

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 
```

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

``` 
kubectl get services 
```


## 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 . 
```

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.

<BR/>
Check out my GitHub for more details:

{% github https://github.com/IamVigneshC/GCP-DevOpsPipelineContinuousIntegration-Deployment %}


__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)
```