Monday, April 26, 2021

How to create Azure Resources using Terraform in Azure Cloud | Automate Infrastructure setup using Terraform in Azure Cloud | Create Azure WebApp using Terraform

WebApp is an App service provided by Azure Cloud for hosting your application. It supports .NET, .NET core, Java, PHP,  Python, Ruby and NodeJS. It is a fully managed Platform as a Serice (PaaS) where developers can deploy mobile or web applications in Azure Cloud in matter of seconds.

With App Service, you pay for the Azure compute resources you use. The compute resources you use are determined by the App Service plan that you run your apps on. We will provision WebApp in Azure cloud using Terraform.

Hashicorp's Terraform is an open-source tool for provisioning and managing cloud infrastructure. Terraform can provision resources on any cloud platform. 

Terraform allows you to create infrastructure in configuration files(tf files) that describe the topology of cloud resources. These resources include virtual machines, storage accounts, and networking interfaces. The Terraform CLI provides a simple mechanism to deploy and version the configuration files to Azure.

Watch the steps in YouTube:

Advantages of using Terraform:

  • Reduce manual human errors while deploying and managing infrastructure.
  • Deploys the same template multiple times to create identical development, test, and production environments.
  • Reduces the cost of development and test environments by creating them on-demand.

How to Authenticate with Azure?

Terraform can authenticate with Azure in many ways, in this example we will use Azure CLI to authenticate with Azure and then we will create resources using Terraform.

Pre-requisites:

Azure CLI needs to be installed.

Terraform needs to be installed.

Logging into the Azure CLI

Login to the Azure CLI using:

az login

The above command will open the browser and will ask your Microsoft account details. Once you logged in, you can see the account info by executing below command:

az account list

Now create a directory to store Terraform files.

mkdir azure-terraform

cd azure-terraform

Let's create a terraform file to use azure provider. To configure Terraform to use the Default Subscription defined in the Azure CLI, use the below cod.

sudo vi azure.tf

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=3.38.0"
    }
  }
}

# Configure the Microsoft Azure Provider
provider "azurerm" {
  features {}
}

Now initialize the working directory

Perform the below command:

terraform init

Once directory is initialized, you can start writing code for setting up the infrastructure. 

Create WebApp(App Service) using Terraform script

sudo vi create-app-svc.tf

# Create a resource group
resource "azurerm_resource_group" "dev-rg" {
  name     = "dev-environment-rg"
  location = "South Central US"
}

# Create app service plan
resource "azurerm_app_service_plan" "service-plan" {
  name = "simple-service-plan"
  location = azurerm_resource_group.dev-rg.location
  resource_group_name = azurerm_resource_group.dev-rg.name
  kind = "Linux"
  reserved = true
  sku {
    tier = "Standard"
    size = "S1"
  }
  tags = {
    environment = "dev"
  }
}

# Create JAVA app service
resource "azurerm_app_service" "app-service" {
  name = "my-awesome-app-svc"
  location = azurerm_resource_group.dev-rg.location
  resource_group_name = azurerm_resource_group.dev-rg.name
  app_service_plan_id = azurerm_app_service_plan.service-plan.id

site_config {
    linux_fx_version = "TOMCAT|8.5-java11"
  }
tags = {
    environment = "dev"
  }
}

Now Perform the below command to validate terraform files.

terraform validate

perform plan command to see how many resources will be created.

terraform plan

terraform apply

Do you want to perform these actions?

type yes 

 
Now Login into Azure Cloud to see all the resources created.
 


Install Azure CLI in Ubuntu 18.0.4 | How to setup Azure CLI in Ubuntu 18.0.4 | How to Install Azure CLI in Ubuntu

The Azure command-line interface (Azure CLI) is a set of commands used to create and manage Azure resources. The Azure CLI is available across Azure services and is designed to get you working quickly with Azure, with an emphasis on automation. Azure CLI is Microsoft's cross-platform command-line experience for managing Azure resources.

Azure CLI can be installed by following below steps:

Run the update first
sudo apt-get update

sudo apt-get install ca-certificates curl apt-transport-https lsb-release gnupg -y

curl -sL https://packages.microsoft.com/keys/microsoft.asc |
    gpg --dearmor |
    sudo tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null


AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" |
    sudo tee /etc/apt/sources.list.d/azure-cli.list


sudo apt-get update
sudo apt-get install azure-cli


Check the version of Azure CLI
az version

Run the Azure CLI with the az command. To sign in, use the az login command.

az login

Saturday, April 24, 2021

DevOps BootCamp by Coach AK on AWS and Azure Cloud Computing Online Classes | Jan/Feb 2024 Schedule

The DevOps requirements in the IT market space is expected to grow by 35% by 2024. Getting a DevOps education now is a great investment into your future, which will pay off very fast!

You are in the right place to kick start your career in DevOps. DevOps is one of the top and hot IT skills right now. Currently almost all the employers are struggling to get right resources in their teams who can do the DevOps and automation work..You could be that person by attending this coaching program.


DevOps Coaching schedule Jan/Feb 2024 (promotions are available, pls contact Coach AK)
DateTimeTypeWhen?
Jan 30th6:00 to 8:00 PM CSTWeekdaysTuesdays/Thursdays    
Feb 03rd11:35 AM CST to 1:35 PM CST on Saturdays
02:00 PM CST to 04:00 PM CST on Sundays    
WeekendsSat/Sundays

DevOps Coaching Highlights:
Comprehensive hands on knowledge on Git, Jenkins, Maven, SonarQube, Nexus, Terraform, Ansible, Docker, Kubernetes, Helm, Prometheus, Docker registry, Helm, AWS and Azure cloud platform.

To join DevOps Coaching classes, please contact Coach AK below:
Contact no# : +1(469)733-5248
WhatsApp #: +1 (469)733-5248
Email id: devops.coaching@gmail.com
Contact: Coach AK

Saturday, April 17, 2021

How to setup Kubernetes Cluster in Ubuntu using Kubeadm | Install Kubernetes Cluster in Ubuntu | Setup Master Node and worker Node in Ubuntu EC2

Kubernetes  is an open source container platform that eliminates many of the manual processes involved in deploying and scaling containerized applications. We will learn how to setup Kubernetes Cluster in Ubuntu 18.0.4. You can setup Kubernetes Cluster in many ways. One of the ways is to use Kubeadm.

Kubeadm is a tool built to provide kubeadm init and kubeadm join as best-practice “fast paths” for creating Kubernetes clusters.

Watch the steps in YouTube video:


Prerequisites:

1. Ubuntu instance with 4 GB RAM - Master Node - (with ports open to all traffic)
2. Ubuntu instance with at least 2 GB RAM - Worker Node - (with ports open to all traffic)

Kubernetes Setup using Kubeadm

###Start - Execute the below commands in both Master/worker nodes##########

Login to both instances execute the below commands:
sudo apt-get update -y  && sudo apt-get install apt-transport-https -y

Change to root user
sudo su -
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF


sudo apt-get update


#Disable swap memory for better performance
swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

Enable IP tables
#We need to enable IT tables for pod to pod communication.
modprobe br_netfilter
sysctl -p
sudo sysctl net.bridge.bridge-nf-call-iptables=1

Install Docker on both Master and Worker nodes
apt-get install docker.io -y

Add ubuntu user to Docker group
usermod -aG docker ubuntu
systemctl restart docker
systemctl enable docker.service

Type exit to come out of root user.
Install Kubernetes Modules
sudo apt-get install -y kubelet kubeadm kubectl kubernetes-cni

sudo systemctl daemon-reload
sudo systemctl start kubelet
sudo systemctl enable kubelet.service
sudo systemctl status docker

#End - Execute the above commands in both Master/worker nodes##########

Initialize Kubeadm on Master Node(only on Master Node)

#Execute the below command as root user to initialize Kubernetes Master node.
sudo su -
kubeadm init

Make sure you see the above message to confirm master node is up.

#Now type exit to exit from root user and execute below commands as normal user

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Installing the Weave Net Add-On
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
It make take a few mins to execute the above command and show show the below message.

Now execute the below command to see the pods.

kubectl get pods  --all-namespaces


Now login to Worker Node

Join worker node to Master Node
The below command will join worker node to master node, execute this a normal user by putting sudo before:

sudo kubeadm join <master_node_ip>:6443 --token xrvked.s0n9771cd9x8a9oc \
    --discovery-token-ca-cert-hash sha256:288084720b5aad132787665cb73b9c530763cd1cba10e12574b4e97452137b4a



Go to Master and type the below command
kubectl get nodes
the above command should display both Master and worker nodes.


It means Kubernetes Cluster - both Master and worker nodes are setup successfully and up and running!!!

Deploy Nginx on a Kubernetes Cluster
Let us run some apps to make sure they are deployed to Kuberneter cluster. We will do this in master node. The below command will create deployment:

kubectl create deployment nginx --image=nginx

View Deployments
kubectl get deployments

Create as a service 
kubectl create service nodeport nginx --tcp=80:80

kubectl get svc
run the above command to see a summary of the service and the ports exposed.

Now go Master or worker node, enter public dns and access it with port exposed
You should see the welcome page!

Thursday, April 15, 2021

ERROR: java.lang.RuntimeException: io.kubernetes.client.openapi.ApiException | Kubernetes Deployment Error

Kubernetes Deployment Error from Jenkins to EKS Cluster. When ever you deploy to Kubernetes from Jenkins, you may have the below error.

ERROR: java.lang.RuntimeException: io.kubernetes.client.openapi.ApiException: hudson.remoting.ProxyException: java.lang.RuntimeException: io.kubernetes.client.openapi.ApiException:

Fix - Set a clusterrole as cluster-admin

By default, clusterrolebinding has system:anonymous set which blocks the cluster access. Execute the following command to set a clusterrole as cluster-admin which will give you the required access.

kubectl create clusterrolebinding cluster-system-anonymous --clusterrole=cluster-admin --user=system:anonymous


Thursday, April 1, 2021

How to enable webhooks for multibranch pipeline in Jenkins | Create webhooks for multibranch pipeline in Jenkins

How to kick start multibranch pipeline in Jenkins pipeline automatically every time you make a code change in your SCM?

Pre-requisites:

We need to install multibranch scan webhook trigger plug-in

Go to Jenkins, Manage Jenkins. Manage plug-ins.

search by  multibranch scan

Once plug-in is installed, let's create a hook.

Please watch the above steps in YouTube channel:

Steps:

Go to Jenkins, click on your existing multibranch pipeline job. Click on configure.

After installing the plug-ins, click on scan multibranch pipeline trigger section. click on scan by webhook. and enter token info.

Copy Jenkins url for configuring webhooks. click on ?

Now create a webhook in GitHub

Go to your git repo, click on settings, Webhooks.enter jenkins url

JENKINS_URL/multibranch-webhook-trigger/invoke?token=myToken123

Click on update webhook. make sure it has configured correctly.

Now if you make a code change, it should trigger multi branch pipeline job.


How to create another branch from Main branch using command line

 Go to your EC2 instance or where ever your code exists in local repository. login to your instance and go to your repo.

cd reponame

Now let's create a new branch called develop from main branch.

git checkout -b develop

Now you can see how many branches are created locally.

git branch

git push --set-upstream origin develop


That is how you create a new branch from command line and push that branch into Remote repo.

How to create Multibranch pipeline in Jenkins | Multibranch pipeline tutorial

Let us learn how to create multi branch pipeline using Jenkins.

What is Multi-branch pipeline?

 - Automatically create new pipelines for every Git branch in source version control.

- Enables different pipeline implementation for every branch. for e.g let us say you want to have CICD pipeline for master branch and only CI pipeline for develop branch.

- an automatically discover new branches in the source control (GitHub or any SCM) and automatically create a pipeline for that branch.

Watch the steps in YouTube:

Create Jenkinsfile first

Please follow the link above to understand how to create Declarative pipeline - Jenkinsfile.

How to create multibranch pipeline?

 Go to Jenkins. Create a new Item. give a name like myMultiBranchPipelineJob

Click ok

Click branch source,  Add source, Add git.

Give your repo URL which has Jenkinsfile already.


Give your Git repo url, credentials. select credentials from the drop down.

Click apply and Save.

Now the pipeline job will automatically scan and creates pipeline per branch.

DevSecOps Bootcamp Dec 2024 Schedule | DevSecOps & AWS Azure Cloud Coaching by Coach AK | DevSecOps and Cloud Computing Online Classes

Lot of new topics covered like GitHub Actions, GitHub Advanced Security, Helm, Prometheus and Grafana..) The DevOps requirements in the IT m...