🐍
Dockerfile

Jenkins → EKS Python Deploy

Jenkins pipeline that updates kubeconfig and deploys a Python app to Amazon EKS

📋Configuration Files

Jenkinsfile

Deploy Python survey app to EKS — update kubeconfig, kubectl apply, reveal ELB URL

yaml
1pipeline {
2 agent any
3
4 parameters {
5 string(name: 'DEPLOYMENT', defaultValue: 'production')
6 }
7
8 stages {
9 stage('Update Kubeconfig') {
10 steps {
11 withCredentials([[
12 $class: 'AmazonWebServicesCredentialsBinding',
13 credentialsId: "aws-credentials",
14 accessKeyVariable: 'AWS_ACCESS_KEY_ID',
15 secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
16 ]]) {
17 sh """
18 aws eks update-kubeconfig --name python-cluster --region us-east-1
19 kubectl get nodes
20 """
21 }
22 }
23 }
24
25 stage('Deploy App') {
26 steps {
27 withCredentials([[
28 $class: 'AmazonWebServicesCredentialsBinding',
29 credentialsId: "aws-credentials",
30 accessKeyVariable: 'AWS_ACCESS_KEY_ID',
31 secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
32 ]]) {
33 sh """
34 kubectl create namespace python-app --dry-run=client -o yaml | kubectl apply -f -
35 kubectl -n python-app apply -f k8s/deployment.yaml
36 kubectl -n python-app apply -f k8s/services.yaml
37 kubectl -n python-app rollout status deployment/survey-app-deploy
38 """
39 }
40 }
41 }
42
43 stage('Reveal APP URL') {
44 steps {
45 withCredentials([[
46 $class: 'AmazonWebServicesCredentialsBinding',
47 credentialsId: "aws-credentials",
48 accessKeyVariable: 'AWS_ACCESS_KEY_ID',
49 secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
50 ]]) {
51 sh "kubectl -n python-app get svc"
52 }
53 }
54 }
55 }
56}

k8s/deployment.yaml

yaml
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: survey-app-deploy
5 namespace: python-app
6 labels:
7 app: survey-app
8spec:
9 selector:
10 matchLabels:
11 app: survey-app
12 replicas: 2
13 template:
14 metadata:
15 labels:
16 app: survey-app
17 spec:
18 containers:
19 - name: survey-app
20 image: your-registry/survey-app:latest
21 ports:
22 - containerPort: 8000
23 resources:
24 requests:
25 memory: "128Mi"
26 cpu: "100m"
27 limits:
28 memory: "256Mi"
29 cpu: "250m"

k8s/services.yaml

yaml
1apiVersion: v1
2kind: Service
3metadata:
4 name: survey-app-service
5 namespace: python-app
6spec:
7 type: LoadBalancer
8 selector:
9 app: survey-app
10 ports:
11 - port: 80
12 targetPort: 8000
13 protocol: TCP

Jenkins pipeline: minimal vs production

What to add before production merge

AspectMinimalProduction
CredentialsAWS keys in Jenkins credentials storeIAM role via EC2 instance profile or OIDC — rotate keys out
Agentsshared executor on masterdedicated agents / K8s plugin pods with resource limits
Deploykubectl apply on every buildmain branch only; PR builds test-only; manual prod gate
Scanbuild + push onlyTrivy/Snyk stage before push to prod registry
Secretskubeconfig file credentialshort-lived tokens; separate creds per env
Auditnonebuild logs retained; Job DSL in git; no click-ops on controller
📄

Step 01

Use the Pipeline

(01)Add Jenkins credentials and run

Linux
1# Jenkins → Manage Credentials → AWS credentials (ID: aws-credentials)
2# Create EKS cluster named python-cluster
3# Add Jenkinsfile to repo; create Pipeline job
4# Push image to ECR/Docker Hub, update deployment.yaml image