Thursday, October 22, 2020

Ansible Vs Puppet - What is the difference between Ansible and Puppet

This is one of the common DevOps interview questions. What is the difference between Ansible and Puppet? When will you choose Ansible over Puppet?


Ansible Puppet
Introduced 2012 2005
Written in? Python Java & Ruby
Syntax Playbooks(YAML file) Domain specific language
Model Push Pull
Architecture Agent-less Client/server
Deployments Fast, simple deployments Larger, complex deployments
Commercial version Ansible Tower Puppet Enterprise
Scheduling not supported in free version Default time 30 mins in Open Source puppet

Wednesday, October 14, 2020

Install Helm 2 on Linux - Setup Helm 2 on Linux | Install Helm 2 on Ubuntu | Setup Helm 2 on Linux

What is Helm?

Helm is a package manager for Kubernetes. Helm is the K8s equivalent of yum or apt. It accomplishes the same goals as Linux system package managers like APT or YUM: managing the installation of applications and dependencies behind the scenes and hiding the complexity from the user.

Helm helps you manage Kubernetes applications. Helm Charts helps you define, install, and upgrade even the most complex Kubernetes application. Charts are easy to create, version, share, and publish.

Helm is made of two components: the CLI binary named helm that allows you to perform communication with a remote component, named tiller that lives inside your Kubernetes cluster that is responsible to perform patches and changes to resources you ask to manage.

Helm 2 can be installed by below way:

Download installables
sudo curl -LO https://git.io/get_helm.sh
provide permission
sudo chmod 700 get_helm.sh

Execute script to install
sudo ./get_helm.sh

 
Verify installation

helm version --client

 
Tiller
Tiller is the service that actually communicates with the Kubernetes API to manage our Helm packages.
 
cat <<EOF > tiller-rbac-config.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: tiller
    namespace: kube-system
EOF
 
Apply the RBAC configuration for Tiller via a kubectl command:
kubectl create -f tiller-rbac-config.yaml 

Initialize Tiller
helm init --service-account tiller

Tuesday, October 13, 2020

Install eksctl on Linux Instance | How to install eksctl in Ubuntu

eksctl is a command line tool for working with EKS clusters that automates many individual tasks.

The eksctl tool uses CloudFormation under the hood, creating one stack for the EKS master control plane and another stack for the worker nodes.

Download and extract the latest release of eksctl with the following command.

curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp

Move the extracted binary to /usr/local/bin

sudo mv /tmp/eksctl /usr/local/bin

eksctl version



Install the AWS CLI version 2 on Linux | How to Install the AWS CLI version 2 on Linux

Follow these steps from the command line to install the AWS CLI on Linux.

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" 

sudo apt install unzip

sudo unzip awscliv2.zip  

sudo ./aws/install

aws --version

it should display the below outout.



Install kubectl on Ubuntu Instance | How to install kubectl in Ubuntu

Kubernetes uses a command line utility called kubectl for communicating with the cluster API server. It is tool for controlling Kubernetes clusters. kubectl looks for a file named config in the $HOME directory.

How to install Kubectl in Ubuntu instance

Download keys from google website
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

Create the below file
sudo touch /etc/apt/sources.list.d/kubernetes.list

echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list

Update package manager
sudo apt-get update

Install
sudo apt-get install -y kubectl

Verify if kubectl got installed
kubectl version --client




Monday, October 12, 2020

Create Amazon EKS cluster by eksctl | How to create Amazon EKS cluster using EKSCTL | Create EKS Cluster in command line

What is Amazon EKS

Amazon EKS is a fully managed container orchestration service. EKS allows you to quickly deploy a production ready Kubernetes cluster in AWS, deploy and manage containerized applications more easily with a fully managed Kubernetes service. 

EKS takes care of Master node/control plane. We need to manage worker nodes.

Please watch the steps in YouTube channel:

Pre-requisites:

You can use Windows, Macbook or any Ubuntu or Red Hat EC2 instance to setup the below tools.

  • Install AWS CLI – Command line tools for working with AWS services, including Amazon EKS.

  • Install eksctl – A command line tool for working with EKS clusters that automates many individual tasks.

  • install kubectl – A command line tool for working with Kubernetes clusters. 

Create AWS Access Keys

Once you install all of the above, you need to have AWS credentials configured in your environment. The aws configure command is the fastest way to set up your AWS CLI installation for general use. 

Make sure you do not have any IAM role attached to the EC2 instance. You can remove IAM role by going into AWS console and Detach the IAM role.

aws configure 

the AWS CLI prompts you for four pieces of information: access key, secret access key, AWS Region, and output format.

Create EKS Cluster using eksctl

eksctl create cluster --name demo-eks --region us-east-2 --nodegroup-name my-nodes --node-type t3.small --managed --nodes 2 

the above command should create a EKS cluster in AWS, it might take 15 to 20 mins. The eksctl tool uses CloudFormation under the hood, creating one stack for the EKS master control plane and another stack for the worker nodes. 

eksctl get cluster --name demo-eks --region us-east-2 

This should confirm that EKS cluster is up and running.

Connect to EKS cluster

kubectl get nodes

kubectl get ns

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

kubectl create deployment nginx --image=nginx


View Deployments
kubectl get deployments

Delete EKS Cluster using eksctl

eksctl delete cluster --name demo-eks --region us-east-2 

the above command should delete the EKS cluster in AWS, it might take a few mins to clean up the cluster.

Errors during Cluster creation
If you are having issues when creating a cluster, try to delete the cluster by executing the below command and re-create it.

eksctl delete cluster --name demo-eks --region us-east-2 


or login to AWS console --> AWS Cloudformation --> delete the stack manually.

you can also delete the cluster under AWS console --> Elastic Kubernetes Service --> Clusters
Click on Delete cluster

Saturday, October 10, 2020

Jenkins Pipelines - Pipeline as a code - Difference between Scripted and Declartive Pipelines

Jenkins is an Open source, Java-based automation tool. This tool automates the Software Integration and delivery process called Continuous Integration and Continuous Delivery.

Jenkins support various source code management, build, and delivery tools. Jenkins is #1 Continuous integration tool, especially new features like Jenkins Pipelines (Scripted and Declarative Pipeline) makes the delivery process very easy and help Team to adopt DevOps easily.


Jenkins pipeline

- Pipelines are better than freestyle jobs, you can write a lot of complex tasks using pipelines when compared to Freestyle jobs.
- You can see how long each stage takes time to execute so you have more control compared to freestyle.
- Pipeline is groovy based script that have set of plug-ins integrated for automating the builds, deployment and test execution.
- Pipeline defines your entire build process, which typically includes stages for building an application, testing it and then delivering it.
- You can use snippet generator to generate pipeline code for the stages you don't know how to write groovy code.
- Pipelines are two types - Scripted pipeline and Declarative pipeline

Jenkins Pipeline execution engine supports two DSL syntaxes: Scripted Pipeline and Declarative Pipeline.

Type of Jenkins Pipelines
  1. Scripted pipeline
  2. Declarative pipeline
 Scripted pipeline

- Scripted pipeline is traditional way of writing pipeline using groovy scripting in Jenkins UI.
- stricter groovy syntax
- each stage can not be executed in parallel in multiple build agents(Slaves) that easily.
- Code is defined within a node block

// Scripted pipeline
node {
  stage('Build') {
       echo 'Building....'
  }
  stage('Test') {
      echo 'Building....'
  }
  stage('Deploy') {
      echo 'Deploying....'
  }
}


Declarative Pipeline (Jenkinsfile)

- New feature added to Jenkins where you create a Jenkinsfile and check in as part of SCM such as Git.
- simpler groovy syntax
- Code is defined within a 'pipeline' block
- each stage can be executed in parallel in multiple build agents(Slaves)

// Declarative pipeline
pipeline {
  agent { label 'slave-node' }
  stages {
    stage('checkout') {
      steps {
        git 'https://bitbucket.org/myrepo''
      }
    }
    stage('build') {
      tools {
        gradle 'Maven3'
      }
      steps {
        sh 'mvn clean test'
      }
    }
  }
}

Tuesday, October 6, 2020

How to migrate apps from bitbucket to azure cloud using Azure DevOps pipelines | How to build pipelines in Azure DevOps to migrate Java Apps to Azure Cloud

Building pipelines in Azure DevOps is really easy, you can migrate your web applications from any where into Azure Cloud by using Azure pipelines.

We are going to migrate Java Web App that was setup in BitBucket into Azure Cloud. Since it is a Java WebApp, we need to create a WebApp in Azure Cloud. 

WebApp is a Platform as a service capability provided by Azure to deploy any kind of apps including Web apps, APIs, mobile apps.

How are we going to do?

1. Create a Webapp in Azure Cloud.
2. Create Azure pipeline in Azure DevOps
3. configure pipeline to check out code from BitBucket and deploy into Azure Cloud on WebApps
4. Run the apps

You need to create WebApp in Azure Cloud. WebApp is an App service (Platform as a Service) provided by Azure Cloud to migrate any web applications.

Once you sign in to Azure Portal, you need to create an app service which is a WebApp.

Step # 1-  Creating a WebApp in Azure Portal

1. Now login to https://portal.azure.com
2. Click on App services


3.Click on + Add or click on Create app service(Web App)


Click on Web App. Choose your Azure subscription, usually Pay as you Go or Free trial subscription
Create a new resource group(for first time if you are creating an appservice, otherwise you can use existing group)


Enter App service name(it should be unique)
Publish as Code
Run time stack as Java 17
Java Web Server stack --> Tomcat 10.0
Operating System as Linux
Region as Central US or where ever you are based at
Enter LinuxPlan name
Choose SKU and size as given below:
Choose DEV/Test and use 1 GB or 1.75 GB memory



Click on Apply
Now click on Apply & Create
This will take bit time to create the app service.

Once WebApp is created, go resources, click on WebApp name and click on the URL.



You should see the app service home page some thing like below:



Since our WebApp is up and running, now we can start creating pipelines to migrate to Azure cloud.

2. Creating pipelines in Azure Devops

1. Now go to your visual studio project page --> https://dev.azure.com/
Select the Project dashboard you already created.

Click on Pipelines, Builds.


2. Click on New pipeline and click on use the classic editor to create a pipeline without YAML

3. Select source repository as BitBucket cloud and click use user name and password to continue

4. Enter bitbucket user name and password and click on authorize.

Choose your repo by click on ... dots. click continue

5. Since our application is Java stack, type Java and Choose Azure WebApp for Java



6. Modify maven goal as clean install and also choose POM.xml by clicking on three dots ...choose pom.xml




7. Leave the value as it is for Copy Files to staging folder

8. Leave the value as it is for Publish Artifact: Drop 
9. Click on Stop Azure WebApp step, Enter Azure WebApp details - where  you would like to deploy your app in Azure. Select Free trial subscription from the drop down. Click on Authorize button.
Make sure you disable popup blocker.


10. Do the same in Deploy Azure WebApp & Start Azure WebApp steps.

Enable Webhooks in Pipeline

11. Click on Triggers and then enable check box for Continuous Integration

12. Now click on Save and Queue

13. If your configurations are correct, you should be able to see the build success and able to access in the Azure. Click on Pipelines and pipeline name

Now you will see that Azure DevOps would have started build.

14. Make sure build is success, it should have all green like below.




After successful build, you can check the output by accessing the URL of WebApp:


https://myAzureWebAppUrl

You can watch the above steps in action in YouTube video:

Clean-up Resources:
After successfully finishing the labs, make sure to delete all the resources created in Azure portal to avoid charges from Microsoft.

Select the resource group in Azure portal, delete the resource group. This will ensure that all the resources will be deleted under the resource group.


Friday, October 2, 2020

Migrate WebApp from GitHub to Azure Cloud | Build Pipelines in Azure DevOps to migrate WebApp from GitHub to Azure Cloud

Azure DevOps (previously known as VSTS) is Microsoft's cloud based offering for any technology stack, any platform to turn idea into a product. You can migrate any applications into Azure by building pipelines in Azure Devops.

Click here to learn about Azure DevOps offerings. 

Building pipelines in Azure DevOps is really easy, you can migrate your web application code from any where into Azure Cloud by using Azure pipelines.

 
Creating WebApp in Azure Cloud

You need to create WebApp in Azure Cloud. WebApp is an App service (mostly Platform as a Service) provide by Azure Cloud to migrate any web applications.

Click here to learn how to create WebApp in Azure Portal.

Creating Azure pipelines in Azure DevOps

1. Now go to your visual studio project page --> https://dev.azure.com/
Select the Project dashboard you already created.

Click on Pipelines, Builds.


2. Click on New pipeline and click on use the classic editor to create a pipeline without YAML

3. Select source repository as GitHub and click Authorize using OAuth

4. Now click on Authorize Azure Pipelines, enter GitHub password if it asks.
5. Now you should be able to select repositories by clicking ... dots

6. Since our application is Java stack, type Java and Choose Azure WebApp for Java


7. Click on pipeline name and re-name per your naming standard

8. Modify maven goal as clean install and also choose POM.xml by clicking on three dots ...



9. Leave the value as it is for Copy Files to staging folder

10. Leave the value as it is for Publish Artifact: Drop 
11. Click on Stop Azure WebApp step, Enter Azure WebApp details - where  you would like to deploy your app in Azure. Select Free trial subscription from the drop down.


12. Do the same in Deploy Azure WebApp & Start Azure WebApp steps.

Enable Webhooks in Pipeline

11. Click on Triggers and then enable check box for Continuous Integration

12. Now click on Save and Queue

13. If your configurations are correct, you should be able to see the build success and able to access in the Azure. Click on Pipelines and pipeline name

Now you will see that Azure DevOps would have started build.


14. Make sure build is success, it should have all green like below.


  After successful build, you can check the output by accessing below URL:

https://myAzureWebAppUrl/MyWebApp


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

  (Lot of new topics covered like GitHub Actions, Helm, Prometheus and Grafana..) The DevOps requirements in the IT market space is expected...