Deploy Python App on AWS EKS Cluster Service by Jenkins Pipeline
We will create a Jenkins pipeline to deploy our python application on Aws Eks cluster with fargate profile as fargate profile is pay as you used system which means you will pay only for pods instead of ec2 instance. And we will use cert-manager for automated ssl renewal purpose along with nginx ingress controller to access via https with free lets encrypt certificate to this application.
You can use aws cert manager as well instead of cert-manager if you want to pay for ssl certificate to aws.
Now let us create pipeline. Go to Jenkins dashboard and click on New Item. Write a description if you want and choose Pipeline option and click Ok to create it. You can find my pipeline script below github url. You just need to change variables according to your design. I have used aws ecr repository to save my containers and use in eks and already have an article about how to deploy your app to ecs cluster. If you want, you can have a look at that article if you want to use ecr repository. Its url is at the end of this article. Plus if you don’t have an eks cluster with fargate profile, its article url will be down too.
https://raw.githubusercontent.com/semiharsan/devops/main/jenkinspipelineforpythonappdeploymentoneks
Go to General page of new pipeline and choose Github hook and Poll Scm to trigger pipeline automatically when someone pushed new code to application repository. Copy my pipeline script to script area and change variables according to your requirements and save it. Then just run the pipeline. As you can see in the script, pipeline will deploy app on eks and then it is gonna update the pods one by one for zero downtime purpose.
Kubernetes deployment and cert-request yaml files github url is below. You can change port number as you want.
https://raw.githubusercontent.com/semiharsan/pythondemoapp/main/awseks.yaml
https://raw.githubusercontent.com/semiharsan/pythondemoapp/main/cert-request.yaml
Pipeline deployed app to our eks cluster. Come on let’s check it out. Pods are running and ingress shows me the dns name of load balancer. I want you to know nginx ingress controller should run behind aws load balancer controller so load balancer controller will be responsible to send requests to nginx ingress and nginx ingress will be responsible for tls termination with free ssl certificate as aws load balancer controller only use aws cert manager certificates
Kubectl get pods
Kubectl get ingress
Kubectl describe ingress hellopython-ingress-app
Now go to your public dns management interface and create a cname for your host record. In my case, I use cloudflare so I will show you how to do it in cloudflare.
Dns record is ready to use. Let us check app is accessible over ssl https with curl command in linux shell and chrome browser. As you can see in below pictures, we have accessed over ssl https and certificate is created by lets encrypt using cert-manager issuer.
Come on let s update our code and see it will deploy new code automatically. I will update directly in github itself but you acan update your code as you wish. It doesn’t matter how you do because Jenkins will check code repository every one minute against new updates. So if there is a new checkin then Jenkins will start the pipeline.
Let us check our url again and see whether new welcome message is deployed.
Well done guys. Congrats !!!
We have deployed a python app on eks cluster with fargate profile along with free ssl https access. Now you will pay only for this app pod as much as you have used.
<< GO TO SETUP JENKINS ON UBUNTU LINUX SERVER >>
<< GO TO DEPLOY PYTHON APP ON AWS ECS SERVICE BY JENKINS CI/CD PIPELINE >>
<< GO TO SETUP AWS EKS CLUSTER WITH FARGATE PROFILE WITH TERRAFORM CODE >>
<< GO TO HOW TO DEPLOY PYTHON APP MAIN POST >>