https://github.com/spicysomtam/jenkins-deploy-eks-via-terraform
Jenkins文件用于创建EKS。如何在同一Jenkins作业中自动将工作节点添加到集群中
stage('Terraform init and Plan eks') {
if (params.action == 'create') {
dir("infra/terraform/eks") {
script {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',credentialsId: awsCredentialsId,accessKeyVariable: 'AWS_accESS_KEY_ID',secretKeyVariable: 'AWS_SECRET_accESS_KEY']]) {
sh """
export TF_CLI_ARGS_init='-backend-config="bucket=${awsS3}"'
terraform init -reconfigure
terraform workspace new ${plan} || true
terraform workspace select ${plan}
terraform plan -out=${plan} -var-file=${WORKSPACE}/environments/tf.tfvars
terraform apply ${plan}
terraform output config_map_aws_auth > ./config_map_aws_auth.yaml
"""
}
}
}
}
}
stage('add worker nodes'){
def k8sImage = docker.image('pahud/eks-kubectl-docker')
k8sImage.inside('-u 0:0') {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',credentialsId: eksCredentialsId,secretKeyVariable: 'AWS_SECRET_accESS_KEY']]) {
sh 'AWS_accESS_KEY_ID=${AWS_accESS_KEY_ID} AWS_SECRET_accESS_KEY=${AWS_SECRET_accESS_KEY} AWS_DEFAULT_REGION=us-west-2 CLUSTER_NAME=my-eksctl'
sh 'aws eks --region us-west-2 update-kubeconfig --name my-eksctl'
sh 'kubectl apply -f config_map_aws_auth.yaml'
}
}
}
如何存储terraform输出config_map_aws_auth> ./config_map_aws_auth.yaml
以便在下一步中可以像这样运行kubectl命令 sh'kubectl apply -f config_map_aws_auth.yaml'