Deployment and configuration in GCP


What is meant by Deployment in software development ?


Deployment includes process , required infrastructure (either hardware or software) and activities required for availability of software for the top user of that software application , a number of the common activities are patches, updates and performance monitoring. Working methodology of software teams has heavily innovated over the decades enabling them faster connectivity over the globe and faster and frequent deployment process. Large a part of the contribution to the present innovation is completed by cloud computing.

There are many cloud computing service providers within the market but in this blog we are going to talk about the deployment using Google cloud platform (GCP) , but before that we look at what exactly is deployment in cloud computing ?



Deployments in Cloud Computing


Cloud deployments are basically a combination of PaaS,SaaS ,IaaS which can be used to achieve activities/processes  required in  deployment of software production. In the context of cloud computing deployment is the instance of a group/set  of resources which are defined as a configuration. We need to give valid configuration in order to create deployment. A deployment  can have a number of resources such as  storage ,compute power, databases, softwares and many similar services provided by GCP.


In this blog we will discuss three main ways of deployment in GCP which are Deployment manager , Kubernetes engine and App engine.



Deployment Manager  :

 

Imagine a scenario when your application deployment requires multiple resources like n- number of VMs, n-number of storage buckets and BigQuery databases and many more it will be very hard to go and manually configure them even if you are using command line or any api. So accordingly it affects the deployment of practical situations in IT companies as the complexity of deployment increases. So here comes the Deployment managers for help.


It is  basically Like a to-do list for a deployment manager. We have to write what configuration we want and by giving a single  command it will create all resources for application. Here we write down a configuration in templates which can be reused again and again by changing some configurations like region or instance type or cpu cores etc. 


Configuration defines all resources for a single deployment. We write this configuration file in YAML format which consists of resources we want to create and their respective properties.now will talk about how to configure in YAML file.


Configuration :

Configuration file starts with   resources: (mandatory )section followed by its list of resources  which we want to create. Each resource must contain there sections :

  •  name  - A user defined character string to uniquely identify this resource such as my-first-vm, project-data-disk, the-first--network.

  •  type  - type of the resource like  compute.v1.instance, compute.v1.disk. and many more you can find those here supported resource types

  •  properties  - The parameters for this resource type. They must match the properties for the type such as zone: asia-east1-a, boot: true.

You can more know about how to make YAML files and other template formats   here 

 

Example configuration file : 


resources:

- name: the-first-vm

  type: compute.v1.instance

  properties:

    zone: us-central1-a

    machineType: https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/f1-micro

    disks:

    - deviceName: boot

      type: PERSISTENT

      boot: true

      autoDelete: true

      initializeParams:

        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20150423

    networkInterfaces:

    - network: https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default

      accessConfigs:

      - name: External NAT

        type: ONE_TO_ONE_NAT



Till now we have looked at creation of a YAML file template so now it’s time for creating a deployment .


We can create deployment using command line as well as api but in this blog we will look at how to create it using command line.


Command for creating deployment 


gcloud deployment-manager deployments create my-first-deployment \  --config vm.yaml


gcloud :   command line tool


my-first-deployment  :  name of your deployment 


--config : this flag sets the configuration file to be use for deployment 


After creation of deployment we can go and manually check if all required resources are formed or not. Other way to this is using describe your deployment command which is as follows: 


gcloud deployment-manager deployments describe my-first-deployment    where  after describe  we have to specify name of our deployment 


Till now we have looked uptill how to create deployment but  along with that we can update , delete and add labels(which are very useful for billing purposes ) to existing deployments. But we will look at those things in a separate blog about deployment manager, for now we will stick to the topic of this blog and move to the next way for deployments .



Google Kubernetes Engine (GKE)  :

 

Kuberentes, also known as K8s, is an open source system for automated deployment, rating, and content management applications.

Collects the containers that make the app into logical units for easy management and discovery. Launching a production load on Google Kubernetes builds over 15 years of experience, combined with the best minds with their ideas and practices of the community.


Prominent notables for Kuberentes are:-



Planet Scale

Designed on the same principles that allows Google to run billions of containers a week, Kubernetes can scale without increasing your ops team.






Never outgrow

Whether testing locally or running a global enterprise, Kubernetes flexibility grows with you to deliver your applications consistently and easily no matter how complex your need is.




 

Run K8s Anywhere

Kubernetes is open source giving you the freedom to take advantage of on-premises, hybrid, or public cloud infrastructure, letting you effortlessly move workloads to where it matters to you.




          Kubernetes Features


Automated Rollouts & Rollbacks

Kubernetes continuously updates changes to your application or configuration, while monitoring app life to ensure that it does not kill all of your instances at once. If anything goes wrong, Kubernetes will reverse the change. Take advantage of the growing environment for shipping solutions.


Service Topology

Delivery of service traffic based on collection topology


Batch Execution

In addition to services, Kubernetes can manage your batch and CI luggage, placing failed containers, if required.


Horizontal scaling

Scale your application with a simple command, with a UI, or automatically based on the CPU usage.


Service discovery and Load Balancing

There is no need to change your application to use the default access to the app. Kubernetes gives Pods their IP addresses and one DNS name for the Pods collection, and can upload-balance to all of them.


Storage Orchestration

Automatically install your favorite storage system, either from local storage, a public cloud provider such as GCP or AWS, or a network storage system such as NFS, SCSI, Gluster, Ceph, Cinder, or Flocker.


Automatic bin packing

It automatically places the containers according to their resource requirements and other issues, while not compromising availability. Combine critical load with great effort to further use and save more resources.


IPv4 / IPv6 dual-stack

Allocating IPv4 and IPv6 addresses to Pods and Services in the clusters.


Seal-Healing

It restores containers that fail, modifies and rearranges containers when nodes die, kills containers that do not respond to user-defined health tests, and does not advertise to customers until they are ready to serve.




Deployment and Configuration

Let's start by submitting a simple web server program that contains content to the Google Kubernetes Engine (GKE) collection.

First, the following steps are required to enable the Kubernetes Engine API: -

  1. Visit the Kubernetes Engine page on the Google Cloud Console.

  2. Create or select a project.

  3. Expect API and related services to be enabled (This may take several minutes)

  4. Make sure payment is enabled for your Cloud project.


Choosing a shell

To complete this, you can either use Cloud Shell or your local shell.

Cloud Shell a shell environment for managing the resources hosted on Google Cloud. Cloud Shell comes pre-installed with the gcloud command-line tool and kubectl command-line tool. The gcloud tool has the primary command-line interface for Google Cloud, and kubectl provides the primary command-line interface for running commands for Kubernetes clusters.

If you choose to use your local shell, you should install the gcloud tool and kubectl tool in your area.

  • Perform the following steps, To launch Google cloud:

  1. Go to Google Cloud Console.

  2. From the upper-right corner of the console, click the Activate Cloud Shell button:

A frame lower on the console is opened inside the Cloud Shell session. We use this shell to run gcloud and kubectl commands.

  • Perform the following steps, to install Cloud SDK:

  1. Install Cloud SDK, which includes the gcloud command line tool.

  2. After installing the Cloud SDK, install the kubectl command line tool using the following command: - gcloud components install kubectl

Configuring default settings for the gcloud tool

Use the gcloud tool to set up two default settings: your default project and compute zone.

The project has a project ID, which is an unique identifier. When you start creating a project, you can use the automatically generated project ID or you can create your own.

Your computer is a region in which your collections and resources are located. For example, us-west1-a is a place in the us-west region.

Setting up these default settings makes it easy to use gcloud commands, because gcloud requires you to specify a project and calculate where you want to work. We can  specify these settings or override those default settings with flags, such as - project, --zone, and cluster, in our gcloud commands.

When you create GKE resources after setting up your default project and compute zone, resources are tailored to that project and location.

Setting a default project

Run the command, replacing project-id with your project ID:

gcloud config set project project-id

Setting a default compute zone

Run the command, replacing compute-zone with your following compute zone, such as us-west1-a:

gcloud config set compute/zone compute-zone

 

Creating a GKE cluster

The collection consists of at least one aircraft control system and several operational equipment called nodes. Nodes are computer-generated (VM) machine systems that use the Kubernetes processes needed to make them part of a cluster. You move applications to groups, and then applications run on nodes.

The following command creates one node set. Your collection name should be Replaced with this collection name:

gcloud container clusters create cluster-name --num-nodes=1

Get authentication credentials for the cluster

You need to get authentication credentials to interact with the cluster, after creating your cluster:

gcloud container clusters get-credentials cluster-name

Deploying an application to the cluster

Now that you've created the collection, you can post a program with it in it. In this quick time, you can add an example of our web application, hello app.

GKE uses Kubernetes' resources to create and manage your collection resources. Kubernetes offers a deployment feature for installing countless applications such as web servers. Service items define rules and measure the accessibility of your system from the Internet.

Creating the Deployment

Run the following command, To run hello-app in your cluster:

kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0

This following Kubernetes command, kubectl create deployment, creates a Deployment named hello-server. The hello-app container image is run by The Deployment's Pod.

In this command:

  • --image specifies a particular container image to deploy. The command pulls the example image from a Container Registry bucket, gcr.io/google-samples/hello-app. :1.0 indicates the specific image version to pull. The latest version is used, if we don't specify the version.

Exposing the Deployment

After installing the app, you need to launch it online so users can access it. You can disclose your application by creating the Service, the Kubernetes program which discloses your application to external traffic.

Run the following kubectl expose command, To expose your application:

kubectl expose deployment hello-server --type LoadBalancer \

   --port 80 --target-port 8080

Passing the --type LoadBalancer flag creates a Compute Engine load balancer for the container. The --port flag initializes public port 80 to the internet and the --target-port flag routes the traffic to port 8080 of the application.

Load balancers are billed per Compute Engine's load balancer pricing.

Inspecting and viewing the application

  1. Inspect the running Pods by using kubectl get pods:

kubectl get pods

  1. You should see one hello-server Pod running on your cluster.

  2. Inspect the hello-server Service by using kubectl get service:

kubectl get service hello-server

  1. From this command's output, copy the Service's external IP address from the EXTERNAL-IP column.

  2. View the application from your web browser by using the external IP address with the exposed port:

  3. http://external-ip/

Congratulations!! You have just submitted and deployed a web application containing contents to GKE.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this quickstart, follow these steps.

  1. Delete the application's Service by running kubectl delete:

kubectl delete service hello-server

  1. This command deletes the Compute Engine load balancer that you created when you exposed the Deployment.

  2. Delete your respective cluster by running gcloud container clusters delete:

gcloud container clusters delete cluster-name


App engine :

App Engine is a totally  managed and serverless platform for the purpose of  developing and hosting web applications at level or scale. In this you can choose from many popular languages like Go,PHP,Java,Python etc.,ibraries, and frameworks to develop your applications. Simply,  it provides a platform for developers to build scalable applications on the Google cloud platform based on some demand. Google App Engine, It is a platform as a Service model in cloud computing.

The App Engine requires that applications to be written in python or java, use the  Google query language and store data in Google Big Table, the  Non-compliant applications require modification to use the App Engine. Google App Engine come up with more infrastructure than other flexible hosting services such as Amazon Elastic Compute Cloud (EC2) etc. Usage of resource is free for certain amount in google app engine then users exceeding the per-day usage rates for CPU resources, number of API requests, concurrent requests can pay for more of these resources, resources, storage.

Now let’s speak  about How do I use Google App Engine?

**Google cloud platform-GCP**

A. Creating a GCP project-

  • To use Google's tools for your own website or an application, first you must to create a new project on GCP. and yes for this you must have a Google account.
  • Go to the App Engine dashboard on the Google Cloud Platform (GCP)Console and press the Create button.
  • If you have not created a project before, you'll need to select whether you want to receive email updates or not, agree to the Terms of Service, and then you should be able to continue.
  • Here enter a name for your project also edit your project ID and please note it down. For this blog , the following Name and ID are used:
  • Project Name: GAE Sample Site   (GAE is google app engine)
  • Project ID: gaesamplesite
  • Click the Create button to create your project

B. Creating an application-

  • Each Cloud Platform project can contain one App Engine application. You'll need a sample application to publish. 
  • Have a look at your application's structure — the website or application folder contains your website or application content and .yaml is your application configuration file.
  • Your content of website must go inside the folder of website and its main page must be called by index.html, but apart from that you may take anything.
  • The .yaml file is a configuration file that tells App Engine how to map URLs to your static files.
  •  You don't need to edit it.

C. Publishing your application-

  • Now that You've got your project made and  app files collected together, let's publish it.
  • Open Google Cloud Shell.
  • Drag and drop the app folder into the left pane of the code editor.
  • To select your project run the following in the command line :
  • -> "gcloud config set project gaesamplesite"
  • To go to your app's directory, Then run the following command :
  • -> "cd YourAppNAme"
  • You are now ready to deploy your application on App Engine:
  • ->" gcloud app deploy"
  • To choose the region where you want your application located, Enter a number .
  • -> Enter Y to confirm.
  • Now navigate your browser to your-project-id.appspot.com to visit your website online. Example, for the project ID "gaesamplesite",  navigate this gaesamplesite.appspot.com. on browser.

Major Features of Google App Engine in Cloud Computing: Collection of Development Languages and Tools.

Collection of Development Languages and Tools.

Fully Managed.

Pay-as-you-Go.

Effective Diagnostic Services.


Comments

Post a Comment