Provision Upstream k8s
Overview¶
This is an illustative example of a Jenkins based pipeline programmatically interacting with the Rafay Controller to provision Rafay MKS Clusters on Amazon AWS.
Assumptions¶
-
You have configured credentials in Jenkins so that the pipeline can access the Rafay Controller. An illustrative example is shown below.
-
You have reviewed the documentation for Declarative Cluster Provisioning of Rafay MKS clusters.
Example Pipeline¶
Step 1: Create Jenkins Item¶
Create a new Jenkins "Item", provide a name and select "pipeline" for type. Illustrative screenshot below.
Step 2: Cluster Spec Parameter¶
Select the "This project is parameterized" option and enter "CLUSTER_METADATA". This will carry the Cluster Specs.
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 Rafay MKS (upstream k8s) cluster on AWS etc.
Step 4: Build With Parameters¶
- To execute the pipeline, click on "build with parameters"
- Provide the cluster spec in the parameters
- Click on build
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 a Rafay MKS 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_mks_cluster.sh
echo $RAFAY_USERNAME
./rafay_mks_cluster.sh -u $RAFAY_USERNAME -p $RAFAY_PASSWORD -f cluster_metadata.yaml
'''
}
}
}
}