Thursday, September 30, 2021

How to upload Docker Images into Azure Container Registry using Azure Pipelines | Automate Docker builds using Azure Pipelines | Upload Docker Image into Azure Container Registry (ACR)

We will learn how to build Docker image and upload the Docker images into Azure Container Registry(ACR) using Azure Build pipelines.

Pre-requisites:

1. ACR is setup in Azure cloud. (see below for the steps)
2. Already created Azure DevOps dashboard in 
3. Dockerfile created along with the application source code

How to Create Azure Container Registry?

First Create Resource Group

Make sure you are login to Azure portal first.

az login

Execute below command to create a resource group in Azure portal.

az group create --name myResourceGroup --location southcentralus

Run the below command to create your own private container registry using Azure Container Registry (ACR).

az acr create --resource-group myResourceGroup --name myacrrepo31 --sku Standard --location southcentralus

You can login to Azure portal to see the ACR repo.


How to create a Azure Build Pipeline

1. Login into your Azure DevOps dashboard
2. Click on Pipelines.

3. Click on New Pipeline

4. Click on use the classic editor
Enter your repo name and branch name where you have stored your source code along with Dockerfile

Click on Continue. Now choose the template by typing Docker, Select Docker container and Apply.
 

Now pipeline is created with two tasks already. Now we need to customize it.

Let's modify Build an image task. Choose azure subscription and enter Microsoft credentials and select ACR repo from the drop down


Select Push an image task and select Azure subscription and select ACR repo from the drop down


Add a task for Copying YAML file, enter the Kubernetes deployment YAML file

Add Publish artifact task


Now click Save + Queue and run to start Building the pipeline



Once the build is completed, you should be able to see the Docker images under 
Services --> Repositories


Please watch the above steps in YouTube Channel:

Tuesday, September 14, 2021

Install kubectl on Mac OS | How to install kubectl in MAC OS

Kubernetes uses a command line utility called kubectl for communicating with the cluster API server. It is tool for controlling Kubernetes clusters.  

Kubectl is installable on a variety of Linux platforms, macOS and Windows.

How to install Kubectl in MAC OS

Kubectl can be installed in Mac OS by using Homebrew:

Run the update first and install

brew update && brew install kubectl 
or 
brew install kubernetes-cli

To check the version of Kubernetes CLI

kubectl version --client

=

Install Azure CLI in Mac OS| How to setup Azure CLI in Mac OS | How to Install Azure CLI in Apple Laptop

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 in Mac OS by using Homebrew:

Run the update first

brew update && brew install azure-cli

To 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

Wednesday, September 1, 2021

How to install Terraform on Red Hat Linux | TerraForm Installation on Red Hat Linux

Terraform is an infrastructure as a code tool used for provisioning infrastructure on most of the cloud platforms. 

  • Open source
  • Can setup entire infrastructure by writing Terraform scripts/templates. 
  • Based on declarative model
  • Uses Hashi Corp Language(HCL) which is JSON format

You can watch this on YouTube channel:

Please find steps for installing Terraform On Enterprise Red Hat Linux.

Create a working directory
sudo mkdir -p /opt/terraform
cd /opt/terraform

Install wget utility
sudo yum install wget -y

Download Terraform from Hasicorp website
sudo wget https://releases.hashicorp.com/terraform/1.0.5/terraform_1.0.5_linux_amd64.zip

Install unzip utility
sudo yum install unzip -y

Unzip Terraform Zip file
sudo unzip terraform_1.0.5_linux_amd64.zip

Add terraform to PATH
sudo mv /opt/terraform/terraform /usr/bin/

terraform -version

Terraform v1.0.5
on linux_amd64

this should show version of Terraform.

Thursday, August 26, 2021

How to send approval notification from Jenkins Pipeline to Slack | Trigger Jenkins Job using Webhooks from Slack

How to integrate Slack with Jenkins using webhooks? How to send approval notification from Jenkins to Slack and approve and trigger job from Slack to Jenkins. We need to create webhooks in Slack to send messages to Slack channel.



Pre-requisites:
1. Jenkins is up and running
2. Slack account is is created and channel is created.

Steps to integrate Slack with Jenkins using Webhooks

Create Webhooks in Slack
2. Click on Create an app

3. Select from scratch


4. Name the app and choose the workspace

Now click on incoming webhooks

Enable it by clicking on


Now select the channel where you like to post messages

Now copy the Webhook url which we will be using in Jenkins pipeline:



Now go to Jenkins and create this pipeline:

import groovy.json.JsonOutput

pipeline {
    agent any
    tools {
        maven 'Maven3'
    }
    environment {
        jenkins_server_url = "http://ec2-3-129-59-179.us-east-2.compute.amazonaws.com:8090"
        notification_channel = 'aug-2021-weekday-batch'
        slack_url = 'https://hooks.slack.com/services/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'
        
    }

   stages {
       
    stage('Cloning Git') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/main']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '8b429648-98dd-446a-80c6-120f9eab44fe', url: 'https://github.com/akannan1087/myAug21WeekendRepo']]])     
            }
        }
    stage ('Build') {
      steps {
      sh 'mvn clean install -f MyWebApp/pom.xml'
      }
    }

    stage ('DEV Deploy') {
      steps {
      echo "deploying to DEV Env "
      deploy adapters: [tomcat9(credentialsId: '341bc648-7df9-4b41-b520-9872cd2d8097', path: '', url: 'http://ec2-18-222-124-177.us-east-2.compute.amazonaws.com:8080/')], contextPath: null, war: '**/*.war'
      }
    }
    stage('QA approve') {
        steps {
          notifySlack("Do you approve QA deployment? $jenkins_server_url/job/$JOB_NAME", notification_channel, [])
            input 'Do you approve QA deployment?'
            }
        }
        
    stage ('QA Deploy') {
      steps {
      echo "deploying to QA Env "
      deploy adapters: [tomcat9(credentialsId: '341bc648-7df9-4b41-b520-9872cd2d8097', path: '', url: 'http://ec2-18-222-124-177.us-east-2.compute.amazonaws.com:8080/')], contextPath: null, war: '**/*.war'
      }
    }
    
    }
}

def notifySlack(text, channel, attachments) {

    def payload = JsonOutput.toJson([text: text,
        channel: channel,
        attachments: attachments
    ])

    sh "curl -X POST --data-urlencode \'payload=${payload}\' ${slack_url}"
}


Tuesday, August 24, 2021

Automate Docker builds using Jenkins - Dockerize PHP App | Containerize PHP App | Build Docker images using Jenkins

We will learn how to automate Docker builds using Jenkins and Deploy PHP based Docker container into EKS cluster. I have already created a repo with source code + Dockerfile. The repo also have Jenkinsfile for automating the following:


- Automating builds
- Automating Docker image creation
- Automating Docker image upload into AWS ECR
- Automating Docker container Deployment into EKS Cluster



Pre-requisites:
1. Amazon EKS Cluster is setup and running. Click here to learn how to create Amazon EKS cluster.
3. Setup Jenkins slave, install docker in it.
4. Docker, Docker pipeline and Kubernetes Deploy plug-ins are installed in Jenkins
5. Create an IAM role with Administrator policy, attach to Jenkins EC2 instance


Step #1 - Create Credentials for Kubernetes Cluster
Go to your Jenkins where you have installed Docker as well. Go to credentials -->
Click on Add Credentials, use Kubernetes configuration from drop down.


execute the below command to get kubeconfig info, copy the entire content of the file:
sudo cat ~/.kube/config


Enter ID as K8S and choose enter directly and paste the above file content and save.
Step #2 - 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

Step # 3 - Create a pipeline in Jenkins, name can be anything


Step # 4 - Copy the pipeline code from below
Make sure you change red highlighted values below:
Your docker user id should be updated.
your registry credentials ID from Jenkins from step # 1 should be copied

pipeline {
    agent any 
      environment {
        registry = "acct_id.dkr.ecr.us-east-2.amazonaws.com/
your_ecr_repo"
    }

    
    stages {
        stage('Cloning Git') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '', url: 'https://bitbucket.org/ananthkannan/phprepo/']]])       
            }
        }
    
    // Building Docker images
    stage('Building image') {
      steps{
        script {
          dockerImage = docker.build registry
        }
      }
    }
    
  // Uploading Docker images into AWS ECR
    stage('Pushing to ECR') {
     steps{  
         script {
                sh 'aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin 
acct_id.dkr.ecr.us-east-2.amazonaws.com'
                sh 'docker push 
acct_id.dkr.ecr.us-east-2.amazonaws.com/your_ecr_repo:latest'
         }
        }
      }
    
      stage ('K8S Deploy') {
       
                kubernetesDeploy(
                    configs: 'phpK8SDeploy.yaml',
                    kubeconfigId: 'K8S',
                    enableConfigSubstitution: true
                    )           
                  
        }

  }
}  


Step # 5- Click on Build - Build the pipeline
Once you create the pipeline and changes values per your Docker user id and credentials ID, click on 

Step # 6 - Verify deployments to K8S

kubectl get pods


kubectl get deployments


kubectl get services

Steps # 7 - Access PHP App
Once build is successful, go to browser and enter http://public_dns_name:8086
You should see page like below:



🚀 Live AI-Enabled DevSecOps & Cloud Engineering Bootcamp – Sep 2026

Live AI-Enabled DevSecOps & Cloud Engineering Bootcamp from Coach AK - Sep 2026 Schedule