Tuesday, April 27, 2021

Install Azure CLI in Ubuntu 22.0.4 | How to setup Azure CLI in Ubuntu 20.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 executing the below command:

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

Once Azure CLI is installed, you can verify it by executing below command:

az version



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

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.

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 = "=2.46.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. 

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.
 

Saturday, April 17, 2021

ERROR: Can't construct a java object for tag:yaml - Kubernetes Jenkins Deployment issue

ERROR: Can't construct a java object for tag:yaml.org,2002:io.kubernetes.client.openapi.models.V1Deployment; exception=Class not found: io.kubernetes.client.openapi.models.V1Deployment

 in 'reader', line 1, column 1:
    apiVersion: apps/v1
 

Caused by: hudson.remoting.ProxyException: org.yaml.snakeyaml.error.YAMLException: Class not found: io.kubernetes.client.openapi.models.V1Deployment at org.yaml.snakeyaml.constructor.Constructor.getClassForNode(Constructor.java:664) at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.getConstructor(Constructor.java:322) at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:331) ... 30 more

Fix/Workaround:
Try the deployment in Jenkins slave node instead of deploying from Jenkins Master.