Last active
April 3, 2023 12:59
-
-
Save parjun8840/8937c3df81ef4c6687b82e2d1715f703 to your computer and use it in GitHub Desktop.
Scaling EKS cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def roleArn = "arn:aws:iam:123467890:role/jenkins-iam" | |
def profile = "--profile devops" | |
//In Terraform I prefer using argumnet "ignore_changes" inside "lifecycle" block for the NodeGroup | |
//and manage the Nodes count independentely to control the cost & easy operations | |
pipeline{ | |
agent { | |
kubernetes { | |
yaml ''' | |
apiVersion: v1 | |
kind: Pod | |
spec: | |
containers: | |
- name: awscli | |
image: amazon/aws-cli:latest | |
command: | |
- cat | |
tty: true | |
''' | |
} | |
} | |
parameters { | |
choice(name: "REGION_NAME", choices: ["us-east-1", "us-east-2"], description: "Choose the region") | |
text(name: "COMMENT", defaultValue: "Please write comment & reference Ticket number") | |
choice(name: "CLUSTER_NAME", choices: ["prod-primary", "prod-secondary"], description: "Choose the cluster) | |
choice(name: "NODEGROUP_NAME", choices: ["prod-primary-fe", "prod-secondary-fe"], description: "Choose the NodeGroup") | |
string(name: "DESIRED_SIZE",defaultValue: "0", trim: true, description: "Please enter integer value" ) | |
} | |
stages { | |
stage("Input validation") { | |
script { | |
if (env.DESIRED_SIZE.isInteger()){ | |
int value = env.DESIRED_SIZE as Integer | |
try{ | |
if (value > 10 || value < 0){ | |
throw new Exception("error") | |
} | |
} | |
catch (Exception ignore){ | |
echo "Error: Node count is either too High or Invalid." | |
currentBuild.result = 'ABORTED' | |
error("Aborting the build. Please check with the relavant team") | |
} | |
} | |
else{ | |
currentBuild.result = 'ABORTED' | |
error("Aborting the build. Please provide Integer number for Node size") | |
} | |
} | |
} | |
stage('Checking number of nodes') { | |
steps { | |
container('awscli') { | |
sh "aws ${profile} configure set role_arn ${roleArn} && aws ${profile} configure set credential_source Ec2InstanceMetadata" | |
sh "aws eks ${profile} describe-nodegroup --cluster-name $params.CLUSTER_NAME --nodegroup-name $params.NODEGROUP_NAME --region $params.REGION_NAME" | |
sh "aws eks ${profile} update-nodegroup-config --scaling-config minSize=$params.DESIRED_SIZE,maxSize=$params.DESIRED_SIZE,desiredSize=$params.DESIRED_SIZE --cluster-name $params.CLUSTER_NAME --nodegroup-name $params.NODEGROUP_NAME --region $params.REGION_NAME" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment