/
Guide to Start and Stop Sunbird Ed environments

Guide to Start and Stop Sunbird Ed environments

 

We have created jenkins jobs to start and stop the env which includes Kubernetes (AKS) cluster and Virtual machines in Azure

To start the environment, first start the virtual machines and then start AKS as databases need to be available for the application to start running otherwise it will end up with too many pod restarts

To stop the environment, stop the AKS cluster first and then stop the virtual machines where non-containerised workloads are runnning.

How it works:

We have created the service principle in azure which has access to start and stop the resources. Created Jenkins pipelines which leverages az cli commands to stop and start the resources using the service principle

You need to create job under OpsAdminstration Folder inside Jenkins(also you can create anywhere according to your usecase)

Jenkins pipeline to stop azure VM’s :

 

pipeline { agent any environment { SP_CRED = credentials('stag_az_sp') // Azure SP credentials TENANT_ID = "" // Azure Tenant ID to login RG = "" // Azure Resource Group AZURE_CONFIG_DIR = "/var/lib/jenkins/Azure/Staging" // Azure config dir to store session } stages { stage('Stop Azure VMs') { steps { script { sh 'az login --service-principal -u ${SP_CRED_USR} -p ${SP_CRED_PSW} --tenant ${TENANT_ID}' //sh "/usr/bin/az vm list -g $RG --query '[].id' -o tsv" sh 'az vm deallocate --ids $(az vm list -g $RG --query "[].id" -o tsv)' } echo "All VMs in $RG have been stopped." echo "logging out" sh 'az logout' } } } }

 

Jenkins pipeline to stop AKS cluster:

pipeline {     agent any     environment {         SP_CRED = credentials('dev_az_sp')              // Azure SP credentials         TENANT_ID = ""  // Azure Tenant ID to login         RG = ""    // Azure Resource Group                                    AZURE_CONFIG_DIR = "/var/lib/jenkins/Azure/Dev" // Azure config dir to store session                                  }        stages {         stage('Start Azure AKS') {             steps {                 script {                     def AKS_CLUSTER = [ 'dev-k8s']                     sh 'az login --service-principal -u ${SP_CRED_USR} -p ${SP_CRED_PSW} --tenant ${TENANT_ID}'                     for (def aksName in AKS_CLUSTER) {                     sh "az aks stop --name ${aksName} --resource-group ${RG}"                     echo "$aksName is being stopped"                     }                     echo "logging out"                     sh 'az logout'                 }             }         }     } }

Jenkins pipeline to start AKS cluster:

pipeline {     agent any     environment {         SP_CRED = credentials('dev_az_sp')              // Azure SP credentials         TENANT_ID = "4836227a-1ace-434f-b54c-8a7a14a0b449"  // Azure Tenant ID to login         RG = "sunbird-devnew-env"    // Azure Resource Group                                    AZURE_CONFIG_DIR = "/var/lib/jenkins/Azure/Dev" // Azure config dir to store session                                 }          stages {         stage('Start Azure AKS') {             steps {                 script {                     def AKS_CLUSTER = ['dev-k8s'] // k8s Cluster Name which needs to start                     sh 'az login --service-principal -u ${SP_CRED_USR} -p ${SP_CRED_PSW} --tenant ${TENANT_ID}'                     for (def aksName in AKS_CLUSTER) {                     sh "az aks start --name $aksName --resource-group ${RG}"                     echo "$aksName is being started"                     }                     echo "logging out"                     sh 'az logout'                 }             }         }     } }

 

Jenkins pipeline to start VM’s in a resource group:

 

You can schedule these jobs as a cron from jenkins job configuration

Path for these Jenkins Jobs are under OpsAdministration/dev(your env name)/Core/

Screen Shots for setting up job

 

 

 

 

 

 

 

 

 

Related content

Jenkins jobs to auto stop / start azure infra:
Jenkins jobs to auto stop / start azure infra:
More like this
Kubernetes on Sunbird
Kubernetes on Sunbird
More like this
Core Services
Core Services
More like this
Core
Core
More like this
Build and Deploy
Build and Deploy
More like this
Test Release Installation of Sunbird
Test Release Installation of Sunbird
More like this