Showing posts with label Shell Script. Show all posts
Showing posts with label Shell Script. Show all posts

Tuesday, April 25, 2023

Shell Script for creating AKS Cluster and Azure Container Registry | Setup ACR and AKS Cluster in Azure Cloud using Azure CLI and Script

#!/bin/sh

# This is the shell script for creating AKS cluster, ACR Repo and a namespace


#Create Resource Group

AKS_RESOURCE_GROUP=aks-rg

AKS_REGION=centralus

# Set Cluster Name

AKS_CLUSTER=aks-cluster

# set ACR name

ACR_NAME=myacrrepo531


echo $AKS_RESOURCE_GROUP, $AKS_REGION, $AKS_CLUSTER, $ACR_NAME


# Create Resource Group

az group create --location ${AKS_REGION} --name ${AKS_RESOURCE_GROUP}


# Create AKS cluster with two worker nodes

az aks create --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_CLUSTER} --node-count 2 --generate-ssh-keys


# Create Azure Container Registry

az acr create --resource-group ${AKS_RESOURCE_GROUP} \

                     --name ${ACR_NAME} \

                     --sku Standard \

                     --location ${AKS_REGION}

#Providing required permission for downloading Docker image from ACR into AKS Cluster

az aks update -n ${AKS_CLUSTER} -g ${AKS_RESOURCE_GROUP} --attach-acr ${ACR_NAME}

# Configure Kube Credentials

az aks get-credentials --name ${AKS_CLUSTER}  --resource-group ${AKS_RESOURCE_GROUP}


# Create a namespace in AKS cluster for Helm deployment

kubectl create namespace helm-deployment

Wednesday, April 12, 2023

Shell Script for creating AKS Cluster with Monitoring enabled | Setup monitoring on AKS Cluster and Log Analytics Workspace

#!/bin/sh

# This is the shell script for creating AKS cluster with Monitoring enabled. you can Monitor AKS cluster using Grafana or Azure Monitor


#Create Resource Group

AKS_RESOURCE_GROUP=aks-rg

AKS_REGION=centralus

# Set Cluster Name

AKS_CLUSTER=aks-cluster


echo $AKS_RESOURCE_GROUP, $AKS_REGION, $AKS_CLUSTER


# Create Resource Group

az group create --location ${AKS_REGION} --name ${AKS_RESOURCE_GROUP}


# Create Log Analytics Workspace and store the ID in a variable

AKS_MONITORING_LOG_ANALYTICS_WORKSPACE_ID=$(az monitor log-analytics workspace create --resource-group ${AKS_RESOURCE_GROUP} \

--workspace-name aks-workspace \

--query id \

        -o tsv)

echo $AKS_MONITORING_LOG_ANALYTICS_WORKSPACE_ID


# Create AKS cluster with monitoring enabled and pass on log analytics workspace ID

az aks create --resource-group ${AKS_RESOURCE_GROUP} \

              --name ${AKS_CLUSTER} \

              --node-count 2 \

              --enable-addons monitoring \

              --workspace-resource-id ${AKS_MONITORING_LOG_ANALYTICS_WORKSPACE_ID} \


# Configure Kube Credentials

az aks get-credentials --name ${AKS_CLUSTER}  --resource-group ${AKS_RESOURCE_GROUP}


# Create service principal with monitoring reader role

az ad sp create-for-rbac --role="Log Analytics Reader" --scopes="$(az group show --name ${AKS_RESOURCE_GROUP} --query id --output tsv)"

Friday, May 20, 2022

Automate EKS Cluster using Bootstrap Script | Bootstrap script for setting up Jenkins, Docker and EKS Cluster in AWS cloud

Pre-requisites:

You need to create an IAM role with Administrator Access policy and attach that IAM role to EC2 instance while you provision.

Click on Advanced Details and under user data:

Script for setting up Jenkins, Docker and setting EKS cluster using eksctl command:

#!/bin/bash

# Shell script for installing Java,  Maven, Jenkins, EKS Cluster in Ubuntu EC2 instance

# Command for installing Java 11

sudo apt-get update

sudo apt-get install default-jdk -y

# Command for installing maven

sudo apt-get install maven -y

# Script for Jenkins installation

#Add Repository key to the system

curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null

Append debian package repo address to the system

echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null

sudo apt-get update

# Install Jenkins

sudo apt-get install jenkins -y

echo "Jenkins installed successfully.."

#Install Docker

sudo apt-get update

#Install the below packages

sudo apt install gnupg2 pass -y

#Install docker

sudo apt install docker.io -y

#Add Ubuntu user to Docker group

sudo usermod -aG docker $USER

# start Docker

sudo systemctl start docker

sudo systemctl enable docker

sudo systemctl status docker

sudo usermod -a -G docker jenkins

sudo service jenkins restart

#Reload system daemon files

sudo systemctl daemon-reload

#Restart Docker service as well

sudo service docker stop

sudo service docker start

# Install AWS CLI

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

#Install eksctl on Linux

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 Kubectl

sudo curl --silent --location -o /usr/local/bin/kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.22.6/2022-03-09/bin/linux/amd64/kubectl

sudo chmod +x /usr/local/bin/kubectl

kubectl version --short --client

# Install Helm

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3

sudo chmod 700 get_helm.sh

sudo ./get_helm.sh

helm version --client

sudo su - jenkins

#Create EKS cluster using eksctl command

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

Master DevSecOps and Multi Cloud Computing Course by Coach AK | DevSecOps and Cloud Computing Online Classes | Sep 2025 Schedule

  Master DevSecOps and cloud Computing Bootcamp Schedule for Sep 2025 Are you ready to  supercharge your career  in  DevSecOps ? Whether you...