Skip to content

Provision Amazon EKS

Overview

This is an illustrative example of a Jenkins based pipeline programmatically interacting with Rafay to automate the provisioning of Amazon EKS Clusters based on a declarative cluster specification.


Assumptions

  • You have configured credentials in Jenkins so that the pipeline can securely access the Rafay Controller.
  • You have reviewed the Declarative Cluster Provisioning workflows for Amazon EKS

Jenkins Credentials


Example Pipeline

Step 1: Create Jenkins Item

Create a new Jenkins "Item", provide a name and select "pipeline" for type. Illustrative screenshot below.

Create New Item


Step 2: Cluster Spec Parameter

Select the "This project is parameterized" option and enter "CLUSTER_METADATA". This will carry the Cluster Specs.

Enable Parameter


Step 3: Pipeline

Copy the Rafay provided Groovy Script into the pipeline. This takes the cluster specification provided as a "metadata file" in YAML format.

Once the pipeline is executed, Jenkins will communicate securely with the Rafay Controller which in turn will take the provided cluster specs and provision an Amazon EKS in the specified region.

Pipeline


Step 4: Build With Parameters

  • To execute the pipeline, click on "build with parameters"
  • Provide the cluster spec in the parameters
  • Click on build

Build with Parameters


Jenkins Groovy Script

This is an illustrative Groovy Script that you can adapt and use with your Jenkins environment.

  • 1st Stage: Checks out code from your Git Repo
  • 2nd Stage: Takes the user provided "cluster spec" as a parameter and creates a cluster spec YAML file
  • 3rd Stage: Requests the Rafay Controller to provision an Amazon EKS Cluster with the cluster spec
#!/usr/bin/env groovy

pipeline {
  agent any
  environment {
      RAFAY_USERNAME=credentials('demo-rafay-username')
      RAFAY_PASSWORD=credentials('demo-rafay-password')
  }
  stages {
    stage("Checkout Repo") {
      steps {
            checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'git-lanntn0', url: 'https://github.com/lanntn0/ci-cd-helpers']]])

      }
    }
    stage('File Param WA') {
      steps {
          writeFile file: 'cluster_metadata.yaml', text: params.CLUSTER_METADATA
      }
    }
    stage("Cluster Provision") {
        steps {
            sh label: '', script: '''
            chmod +x rafay_eks_provision.sh
            echo $RAFAY_USERNAME
            ./rafay_eks_provision.sh -u $RAFAY_USERNAME -p $RAFAY_PASSWORD -f cluster_metadata.yaml
            '''
        }
    }
  }
}