Deploying a Python App with Jenkins, Docker & Kubernetes – Full CI/CD Pipeline Explained

This article walks through a complete Jenkins pipeline that automates the deployment of a Python application using Docker and Kubernetes, with integration into AWS EKS.
The pipeline:
- Checks out code from GitHub
- Installs Python dependencies
- Builds and pushes a Docker image
- Verifies AWS CLI access
- Configures kubectl context for EKS
- Deploys to Kubernetes across dev, staging, and production environments
- Includes manual approval before production deployment
Each stage is explained below with its role in the end-to-end CI/CD process.
Full Pipeline Breakdown
pipeline
pipeline {
Begins the Jenkins declarative pipeline.
agent
agent {
label 'worker'
}
Runs the pipeline on a Jenkins agent labeled worker.
options
options {
buildDiscarder logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '',
daysToKeepStr: '7',
numToKeepStr: '2'
)
}
Controls build history retention to avoid storage overload. Keeps builds for 7 days or retains the last 2.
environment
environment {
dockercred = credentials('docker-hub')
awscred = credentials('aws-key')
}
Securely loads credentials from Jenkins for Docker Hub and AWS CLI authentication.
Pipeline Stages
Stage: Checkout
stage('Checkout') {
steps {
checkout scmGit(
branches: [[name: '*/master']],
extensions: [],
userRemoteConfigs: [[url: 'GitHub Link']]
)
}
}
Clones the application source code from the master branch of your GitHub repository.
Stage: Install Dependencies
stage('Install Dependencies') {
steps {
sh 'pip3 install -r requirements.txt'
}
}
Installs required Python packages listed in the requirements.txt file.
Stage: Docker Build & Push
stage('Docker Build & Push') {
steps {
sh 'docker -v'
sh 'docker build -t xxxx .'
sh 'echo $dockercred_PSW | docker login -u $dockercred_USR --password-stdin'
sh 'docker push xxxx:latest'
}
}
Builds a Docker image for the Python app and pushes it to Docker Hub using your credentials.
Stage: Verify AWS CLI
stage('Verify AWS CLI') {
steps {
sh 'aws --version'
sh 'aws sts get-caller-identity'
}
}
Checks the AWS CLI version and verifies access using the STS command.
Stage: Configure Kubeconfig
stage('Configure Kubeconfig') {
steps {
sh 'aws eks update-kubeconfig --region us-east-1 --name devops-working'
}
}
Configures kubectl context so it can communicate with your AWS EKS cluster.
Stage: Deploy to Dev
stage('Deploy to Dev') {
steps {
sh 'kubectl apply -f deployment-dev.yaml -n dev'
}
}
Deploys your app to the dev namespace using the deployment-dev.yaml manifest.
Stage: Deploy to Staging
stage('Deploy to Staging') {
steps {
sh 'kubectl apply -f deployment-staging.yaml -n staging'
}
}
Deploys to the staging namespace for further testing before production.
Stage: Deploy to Production
stage('Deploy to Production') {
steps {
script {
def approval = input(
id: 'prod-deploy',
message: 'Approve deployment to production?',
submitter: 'admin'
)
}
sh 'kubectl apply -f deployment-prod.yaml -n prod'
}
}
Includes a manual approval step before deploying to the production namespace. Only authorized users (like an admin) can approve.
Part of a Series
This Python pipeline is part of my language-specific CI/CD series:
- PHP – Composer, Docker, AWS, Kubernetes
- Node.js – npm, Docker, AWS, Kubernetes
- Python – this article
Each version aligns with DevOps best practices, tailored to each tech stack.
Final Thoughts
This Jenkins pipeline for Python apps automates everything from code checkout to deployment across multiple Kubernetes environments. It’s efficient, secure, and scalable—ideal for teams deploying cloud-native applications.
You can expand this pipeline further with testing, notifications, or security scanning based on your needs.
Feel free to check out the full repo here 👉 GitHub