Infrastructure as Code (IaC) - GCP Deployment Manager

Infrastructure as Code (IaC) is the management of infrastructure (computing networks, virtual machines, the configuration of services, and connection topology) in a descriptive model, using version used in DevOps for source code. Infrastructure as Code evolved to solve the problem of environmental challenges and drift in the release trains/pipelines.

It is important and inevitable to make infrastructure configuration replicable, scalable, and easy to review, by describing it using code. Infrastructure as code comes from the realization of the fact that infrastructure is also “software”, which is particularly true for hybrid and public clouds.

Some of the tools that help you to achieve are Ansible, Terraform and from public cloud offerings, AWS – Amazon Cloud Formation, Azure – Azure Resource Manager & Google Cloud – Deployment Manager. It can provide us a way to define cloud resources using declarative language (ex:- Yaml) managed through the git repository and can be used as templates to avoid duplication and leverage it during deployments.

Below we will focus on using Google Cloud Deployment Manager to automate the configuration of GCP resources.  We will deploy a Kubernetes cluster and a simple application running on it, created automatically.  We will include below resources Kubernetes cluster (GKE), Kubernetes deployment and service & Kubernetes ingress definition.

  1. Get your GCP Account setup and billing is activate
  2. Use “gcloud” command-line tool to set project ID

Your Cloud Platform project in this session is set to devops-learning-217917.
Use “gcloud config set project [PROJECT_ID]” to change to a different project.
<username>@cloudshell:~ (devops-learning-217917)$

3. git clone https://github.com/vbalaji123/samplerepo.git

4. cd “gcp-infra-as-code” directory &  Create a kubernates cluster “example-cluster”

<username>@cloudshell:~/gcp-infra-as-code (devops-learning-217917)$ gcloud deployment-manager deployments create example-cluster –config cluster-3/example-cluster.yaml

The fingerprint of the deployment is o2iwicMF6g6PQqOLzTS_xw==
Waiting for create [operation-1567497490522-591a1731be262-bb3f83a6-e7319fec]…done.
Create operation operation-1567497490522-591a1731be262-bb3f83a6-e7319fec completed successfully.
NAME TYPE STATE ERRORS INTENT
example-cluster container.v1.cluster COMPLETED [] example-cluster-type deploymentmanager.v2beta.typeProvider COMPLETED [] example-cluster-type-apps deploymentmanager.v2beta.typeProvider COMPLETED [] example-cluster-type-rbac deploymentmanager.v2beta.typeProvider COMPLETED [] example-cluster-type-v1beta1-extensions deploymentmanager.v2beta.typeProvider COMPLETED []

$ gcloud deployment-manager types list | grep example
example-cluster-type
example-cluster-type-apps
example-cluster-type-rbac
example-cluster-type-v1beta1-extensions

 

5. Update the deployment manager with example-hello-world configuration using example.yaml file with 3 kubernates resources 

<username>@cloudshell:~/gcp-infra-as-code (devops-learning-217917)$ gcloud deployment-manager deployments update example-hello-world –config hello-world-1/example.yaml

The fingerprint of the deployment is eUWx46c8DB2dtYXTTtZ9Bw==
Waiting for update [operation-1567497946365-591a18e477fd6-32f79595-66554a4d]…done.
Update operation operation-1567497946365-591a18e477fd6-32f79595-66554a4d completed successfully.
NAME TYPE STATE ERRORS INTENT
example-hello-world devops-learning-217917/example-cluster-type-apps:/apis/apps/v1/namespaces/{namespace}/deployments COMPLETED [] example-hello-world-ingress devops-learning-217917/example-cluster-type-v1beta1-extensions:/apis/extensions/v1beta1/namespaces/{namespace}/ingres COMPLETED [] ses
example-hello-world-svc devops-learning-217917/example-cluster-type:/api/v1/namespaces/{namespace}/services COMPLETED []

6. Below command will get the example-cluster cluster already created 

<username>@cloudshell:~/gcp-infra-as-code (devops-learning-217917)$ gcloud container clusters list
NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS
example-cluster europe-west1-b 1.12.8-gke.10 35.195.132.197 n1-standard-1 1.12.8-gke.10 2 RUNNING

7. GCP will assign automatically an ephemeral static IP address to access your application. 
<username>@cloudshell:~/gcp-infra-as-code (devops-learning-217917)$ gcloud container clusters get-credentials example-cluster –zone europe-west1-b
Fetching cluster endpoint and auth data.
kubeconfig entry generated for example-cluster.

<username>@cloudshell:~/gcp-infra-as-code (devops-learning-217917)$ kubectl get pod
NAME READY STATUS RESTARTS AGE
example-hello-world-6bc9c5db55-5rf5q 1/1 Running 0 3m58s
example-hello-world-6bc9c5db55-x2hdz 1/1 Running 0 3m58s

<username>@cloudshell:~/gcp-infra-as-code (devops-learning-217917)$ kubectl get ingress -o wide
NAME HOSTS ADDRESS PORTS AGE
example-hello-world * 35.190.23.215 80 4m57s

http://35.190.23.215 (To access the application hosted on Kubernates cluster in GCP deployment manager)

 

About Nimesa

Nimesa is enterprise-class Application-Aware data protection, cost management & copy data management solution for applications running on AWS. It uses native AWS capabilities like EBS snapshots capabilities to automatically protect the environment. It provides simple policy-based lifecycle management of snapshots and clones of EC2 instances.

To know more of how to protect your environment using Nimesa refer to the previous blog

Try Nimesa for free