Skip to content

Automated

Users can completely embed the "cluster import" into Rafay step into an automated pipeline. For example, a common pattern is for users to use Terraform to provision Kubernetes clusters using a Jenkins based pipeline.


Typical Automation Sequence

The illustrative image below showcases a Jenkins based "automation pipeline" that performs the following steps.

  1. Uses Terraform to provision a Kubernetes cluster based on a cluster spec from a Git repo.
  2. Creates a cluster blueprint in the Rafay Controller based on a version controlled blueprint spec from a Git repo.
  3. Imports the base cluster into the Rafay Controller
  4. Brings cluster to a state of compliance with required blueprint spec.

Automated Import Sequence

Important

Users can embed Rafay provided automation helpers with a workflow/automation platform of their choice.


Automation Helpers

Rafay provides automation helpers and examples via Rafay's Public Git Repo that customers can leverage to fast track their automation initiatives. An Illustrative Example is also available for "Imported Clusters".


Cluster Spec

The customer is expected to provide the Rafay automation helper with a "cluster spec" for the imported cluster. It is highly recommended that customers

Example 1

In the example below, the cluster will be provided a name "eks-dev" in the Rafay Controller. It will be imported into the "default project" and be provisioned with the "default" cluster blueprint.

kind: imported
name: eks-dev
region: aws/us-east-1
project: defaultproject
blueprint: default

Example 2

In the example below, the cluster will be provided a name "aks-qa" in the Rafay Controller. It will be imported into the "QA project" and be provisioned with the "qa" cluster blueprint.

kind: imported
name: aks-qa
region: aws/us-east-1
project: QA
blueprint: qa

Jenkins Pipeline Example

This is a Jenkins groovyscript example that showcases how an existing cluster can be imported into Rafay as part of a highly automated pipeline.

#!/usr/bin/env groovy

pipeline {
  agent any

  // Credentials to access the Rafay Controller
  environment {
      RAFAY_USERNAME=credentials('Rafay_Username')
      RAFAY_PASSWORD=credentials('Rafay_Password')
  }
  stages {

    // Checkout the version controlled cluster spec from your Git Repo
    stage("Checkout Repo") {
      steps {
            checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/RafaySystems/rafay-cicd-helpers']]])

      }
    }

    // Imports the Existing Cluster into Rafay with the cluster spec "imported_cluster.yaml 
    stage("Cluster Import") {
        steps {
            sh label: '', script: '''
            cd imported/scripts
            chmod +x rafay_imported_cluster.sh
            ./rafay_imported_cluster.sh -u $RAFAY_USERNAME -p $RAFAY_PASSWORD -f ../examples/imported_cluster.yaml -a
            '''
        }
    }
  }
}