We will learn how to automate Docker builds using Jenkins and Deploy PHP based Docker container into EKS cluster. I have already created a repo with source code + Dockerfile. The repo also have Jenkinsfile for automating the following:
- Automating builds
- Automating Docker image creation
- Automating Docker image upload into AWS ECR
- Automating Docker container Deployment into EKS Cluster
Pre-requisites:
4. Docker, Docker pipeline and Kubernetes Deploy plug-ins are installed in Jenkins
By default, clusterrolebinding has system:anonymous set which blocks the cluster access. Execute the following command to set a clusterrole as cluster-admin which will give you the required access.
Step # 4 - Copy the pipeline code from below
Make sure you change red highlighted values below:
Your docker user id should be updated.
your registry credentials ID from Jenkins from step # 1 should be copied
pipeline {
agent any
environment {
registry = "acct_id.dkr.ecr.us-east-2.amazonaws.com/your_ecr_repo"
}
stages {
stage('Cloning Git') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '', url: 'https://bitbucket.org/ananthkannan/phprepo/']]])
}
}
// Building Docker images
stage('Building image') {
steps{
script {
dockerImage = docker.build registry
}
}
}
steps{
script {
sh 'aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin acct_id.dkr.ecr.us-east-2.amazonaws.com'
sh 'docker push acct_id.dkr.ecr.us-east-2.amazonaws.com/your_ecr_repo:latest'
}
}
}
kubernetesDeploy(
configs: 'phpK8SDeploy.yaml',
kubeconfigId: 'K8S',
enableConfigSubstitution: true
)
}
}
}
No comments:
Post a Comment