π Blog Post: Python App SDLC in Rancher Kubernetes with Docker on WSL Ubuntu
π Objective:
In this post, Iβll outline the Software Development Life Cycle (SDLC) for a Python application to be deployed in a Rancher Kubernetes environment, utilizing Docker in the background. The development setup runs on Windows Server, with WSL configured as Ubuntu. Our key goal is to track updates in the application and deploy different versions seamlessly. Let's dive into the technical breakdown! π§βπ»
π‘ What I Want to Achieve:
The primary objective is to create a streamlined process where developers can:
-
Develop and update the Python application.
-
Build Docker images within a WSL Ubuntu environment.
-
Deploy these Docker containers in a Rancher-managed Kubernetes cluster.
-
Monitor the deployment progress and roll out different versions effortlessly.
With this setup, the goal is to ensure that versioning, deployment, and updates are fully integrated into the CI/CD pipeline, making the development process efficient and scalable.
π οΈ Step 1: Python Application Development in WSL Ubuntu
Weβll begin by setting up the Python app in WSL Ubuntu. This allows us to benefit from Linux-like environments, even on Windows servers.
Key tools involved:
-
Python for development π
-
Docker for containerization π³
-
WSL Ubuntu for a Unix-like dev environment βοΈ
π³ Step 2: Docker Containerization
Once the app is ready, weβll create a Dockerfile to containerize it. Docker allows us to package the application along with all dependencies, ensuring consistency across development, testing, and production environments.
Dockerfile Example
FROM python:3.9-slim
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
π Step 3: Rancher Kubernetes Deployment
In this step, we will focus on deploying your Docker image to a Kubernetes cluster managed by Rancher. Rancher simplifies the orchestration and management of Kubernetes clusters, making it easier to manage deployments and application versions across multiple environments. Here's how we will achieve that:
1. Push Docker Image to Container Registry
Before deploying the application, you need to push your Docker image to a container registry (e.g., Docker Hub, Google Container Registry, AWS ECR). The registry acts as a central repository where Kubernetes can pull the image when deploying it to the cluster.
Steps:
- Build the Docker Image (if not already built):
docker build -t your-docker-username/your-app:latest .
- Login to Docker Hub (or the relevant container registry):
docker login
- Push the Docker Image to Docker Hub (or your chosen registry):
docker push your-docker-username/your-app:latest
Make sure to replace your-docker-username and your-app with your actual Docker Hub username and the application name.
2. Access Rancher UI
-
Open the Rancher UI in your web browser. Rancher provides a user-friendly interface to manage Kubernetes clusters.
-
Ensure that your Kubernetes cluster is already set up in Rancher and is running smoothly. If you havenβt set it up yet, Rancher allows you to create a new cluster or import an existing one.
3. Create a New Project or Namespace in Rancher
-
Navigate to your Kubernetes cluster in Rancher.
-
Create a new project or namespace within the cluster to deploy your application. This helps in organizing and isolating workloads in your cluster.
4. Deploy Docker Image into the Kubernetes Cluster
Using Rancher Workloads Interface:
Rancher provides a simple way to deploy workloads (applications) in the Kubernetes cluster through its UI.
-
Go to the Workloads section in the Rancher UI.
-
Click on Deploy to start deploying your application.
Fill in the following details:
-
Name: Provide a name for your workload.
-
Docker Image: Enter the full path to your Docker image, e.g.,
your-docker-username/your-app:latest. -
Replicas: Choose how many replicas (instances) of your application you want to run.
-
Ports: If your application exposes any ports (e.g., port 80 for a web app), define them here.
-
Environment Variables and Secrets: Add any required environment variables or secrets needed by your application.
Advanced Configuration:
You can also configure resource limits, volumes, and scheduling policies for your application under advanced options if needed.
5. Expose the Application (Optional)
Once the workload is deployed, you can expose the application to external users by creating a Service or Ingress in Rancher.
-
Service: Defines how to access your application within the cluster. For example, a
NodePortorLoadBalancerservice can expose the application to external traffic. -
Ingress: Provides an HTTP/HTTPS endpoint for your application, allowing it to be accessible via a domain name.
You can create a new service by navigating to the Workloads > Service Discovery section and setting the type to NodePort or LoadBalancer.
6. Monitor and Manage the Application
Rancher provides an overview of the workload's health, status, and logs. You can monitor the performance, scale the replicas, or roll back to previous versions directly from the Rancher UI.
-
Logs: View the application logs to ensure it's running correctly.
-
Scaling: Easily scale the application up or down by adjusting the number of replicas.
-
Rolling Updates: Deploy new versions of your application with zero downtime using rolling updates. Rancher handles the deployment strategy for you.
π§βπ» Key Results:
-
π Deploy new versions of the Python app quickly in Rancher Kubernetes.
-
π Monitor updates and track deployments through Rancherβs intuitive dashboard.
-
βοΈ Ensure smooth container orchestration using Docker and Kubernetes.
-
ποΈ Maintain version control and deployment integrity across environments.
Hereβs a screenshot of the Rancher dashboard showing a successful deployment pause:
π Connect with me:
Stay connected if you want to follow along with similar content and updates!
Thatβs it for now! Looking forward to hearing your thoughts and questions about the SDLC process for Python apps on Rancher Kubernetes!
Imported from rifaterdemsahin.com Β· 2024