Cloud Agnostic Design Using Terraform, Kubernetes, Helm, and Jenkins

Achieving Scalable and Flexible Deployment Pipelines

Terraform logo Kubernetes logo Helm logo Jenkins logo

Introduction to Cloud Agnostic Design

Cloud Agnostic Architecture With Terraform

  • Abstracts away the infra setup details and provides the flexibility of choosing any cloud provider for your services.
  • Terraform logo Terraform Project Structure
    AWS
    Azure
    GCP
    Kubernetes Cluster
    Monitoring Namespace
    Prometheus
    Grafana
    Exporters
    Staging Namespace
    Awaiting Jenkins Tests
    Production Namespace
    Web App
    Worker
    MongoDB

    Jenkins Pipeline Stages

    Code Checkout
    Helm Chart Setup
    Version Management
    Docker Build & Push
    Staging Deploy
    Testing
    Approval
    Production Deploy

    Jenkins Pipeline Stages

    Code Checkout
    Helm Chart Setup
    Version Management
    Docker Build & Push
    Staging Deploy
    Testing
    Approval
    Production Deploy

    Code Checkout Stage

    Purpose: Ensure the pipeline uses the latest code version

    stage('Checkout Application') {
        steps {
            // Clone the application repository
            git url: 'https://github.com/AtakanG7/web-app', branch: 'main'
            // This step fetches the latest code from the specified Git repository
        }
    }
                

    Helm Chart Repository Setup

    Purpose: Prepare Helm charts for deployment

    stage('Clone Helm Chart Repository') {
        steps {
            // Clone the Helm chart repository
            sh "git clone ${HELM_REPO} helm-repo"
            // Add the Helm chart repository to the local Helm installation
            sh "helm repo add myrepo https://atakang7.github.io/gh-pages/docs"
            // These steps ensure that the necessary Helm charts are available for deployment
        }
    }
                

    Chart Version Management

    Purpose: Ensure correct versioning of the application

    stage('Update Chart Versions') {
        steps {
            script {
                dir('helm-repo') {
                    // Increment the version number
                    env.NEW_VERSION = incrementVersion(currentVersion)
                    // Update the Chart.yaml file with the new version
                    sh "sed -i 's/version: .*/version: ${env.NEW_VERSION}/' ${CHART_PATH}/Chart.yaml"
                    // This ensures that each deployment has a unique version number
                }
            }
        }
    }
                

    Docker Image Build and Push

    Purpose: Prepare containerized application for deployment

    stage('Build and Push Docker Image') {
        steps {
            script {
                // Build the Docker image with the new version tag
                sh "docker build -t atakan1927/web-app:${env.NEW_VERSION} ."
                // Push the newly built image to the Docker registry
                sh "docker push atakan1927/web-app:${env.NEW_VERSION}"
                // These steps create a new container image and make it available for deployment
            }
        }
    }
                

    Staging Deployment

    Purpose: Test new version in a controlled environment

                    stage('Mirror Production in Staging') {
                        steps {
                            script {
                                dir('helm-repo') {
                                    def charts = sh(script: "ls charts", returnStdout: true).trim().split()
                                    for (def chart in charts) {
            
                                        sh """
                                            helm upgrade --install ${chart}-staging charts/${chart} \
                                                --namespace staging \
                                                -f charts/${chart}/values-staging.yaml \
                                                --wait
                                        """
                                        
                                    }
                                }
                            }
                        }
                    }
                

    Testing Stage

    Purpose: Ensure application quality and functionality

    stage('Run Tests') {
        steps {
            echo "Running tests on staging environment..."
            // This is a placeholder for actual testing commands
            // In a real scenario, you would run various tests here to verify the application's functionality
        }
    }
                

    Production Approval and Deployment

    Purpose: Human validation before live deployment

    stage('Approval') {
        steps {
            // Wait for manual approval before proceeding
            input message: 'Approve deployment to production?', ok: 'Deploy'
            // This step requires human intervention to ensure that the deployment is ready for production
        }
    }
    
    stage('Deploy to Production') {
        steps {
            script {
                sh """
                    # Use Helm to upgrade or install the application in the production environment
                    helm upgrade --install ${APP_NAME} ${CHART_PATH} \
                        --namespace production \
                        -f ${CHART_PATH}/values-production.yaml \
                        --set image.tag=${env.NEW_VERSION}
                    # This command deploys the approved version to the production environment
                """
            }
        }
    }
                

    Cloud Agnostic Benefits

    Monitoring

    Conclusion

    Q&A

    Thank you for your attention!