Skip to content

Django application with a CI/CD setup integrated with Docker & Kubernetes. The automation pipeline uses GitHub Actions to build, test, and deploy the application, ensuring seamless integration and delivery.

License

Notifications You must be signed in to change notification settings

TalhaBruh/CI-CD-Pipeline-for-Django-App-with-Kubernetes-and-Docker

Repository files navigation

CI/CD Pipeline for Django Application with Kubernetes Deployment

This repository demonstrates a comprehensive CI/CD pipeline for a Django application using GitHub Actions and Kubernetes. It streamlines the deployment process by automating linting, testing, Docker image creation, and deployment to a Kubernetes cluster. With integrated notifications to Sentry and Slack, you can easily track errors and pipeline status in real-time.

If you find this project helpful, please give it a ⭐!

Why This Project?

This setup is designed to simplify the deployment and maintenance of Django applications. It automates repetitive tasks like code linting and testing, ensuring that code quality and functionality are maintained across all stages of development. By using GitHub Actions and Kubernetes, you can:

  • Reduce Manual Errors: Automate the entire build and deployment process, minimizing the chances of human errors.
  • Save Time: Automatically test, build, and deploy your application with minimal manual intervention.
  • Improve Code Quality: With automated linting and testing on every push, you ensure that code quality remains high.
  • Increase Reliability: Continuous deployment to Kubernetes allows you to manage application scaling and uptime more effectively.

Benefits of This Setup

  • Seamless Integration: Connects GitHub Actions, Docker, and Kubernetes in a cohesive workflow.
  • Enhanced Monitoring: Sentry integration provides real-time error tracking, while Slack notifications keep you updated on pipeline status.
  • Scalable Architecture: Kubernetes enables you to scale your Django application effortlessly as traffic increases.
  • Repeatable and Consistent Deployments: Ensure that every deployment is consistent and repeatable, reducing the "it works on my machine" issue.

Use Case in My Projects

I’ve utilized this architecture in several projects to automate the CI/CD process for deploying Django applications. This setup is ideal for teams looking to maintain a high level of code quality and ensure smooth deployments. By leveraging this pipeline, I’ve been able to focus more on feature development and less on deployment overhead, ultimately accelerating the overall development lifecycle.

Purpose and Potential Use Cases

The primary purpose of this project is to provide a robust and automated solution for deploying Django applications. It’s particularly useful for:

  • Startups: Streamline development and deployment processes with minimal DevOps overhead.
  • Large-Scale Applications: Efficiently manage deployments across multiple environments (development, staging, production).
  • Continuous Improvement Teams: Enable rapid iterations and continuous improvements with automated testing and deployment.

Features

  • Linting: Automatically checks for code linting errors on every push.
  • Testing: Runs unit tests after successful linting.
  • Docker Image Creation: Builds Docker images for the Django app, PostgreSQL, and Redis, and pushes them to GitHub Container Registry.
  • Sentry Alerts: Notifies Sentry about new releases.
  • Slack Notifications: Sends notifications to a Slack channel based on pipeline success or failure.
  • Kubernetes Deployment: Pulls images from GitHub Registry and manages deployments.

Getting Started

Prerequisites

  • Ensure you have a GitHub account and a repository set up.
  • Have access to a Kubernetes cluster.
  • Set up Sentry and Slack, and obtain the necessary API keys.

Configuration

  1. Sentry and Slack Integration:

    • Connect your Sentry account and obtain the DSN for notifications.
    • Configure Slack integration for alerts on pipeline status.
    • Update the GitHub Actions workflow file with your Sentry and Slack credentials.
  2. Kubernetes Configuration:

    • Create or update the necessary Secrets and ConfigMaps in your Kubernetes cluster:
      • Store sensitive data (like database credentials) in Secrets.
      • Use ConfigMaps for application configuration.

CI/CD Workflow

On every push to the repository:

  1. Linting: The workflow checks for linting errors.
  2. Testing: If linting passes, it runs the tests.
  3. Docker Image Creation: If tests pass, it builds Docker images for the Django app, PostgreSQL, and Redis, and pushes them to GitHub Container Registry.
  4. Sentry Notification: Sends a notification to Sentry regarding the new release.
  5. Slack Notifications: Notifies the specified Slack channel whether the pipeline succeeded or failed.

Kubernetes Deployment

The Kubernetes configuration includes:

  • Deployments:

    • Django application
    • Celery Beat (for periodic tasks)
    • Celery Worker (for background tasks)
    • Redis
    • PostgreSQL
  • Persistent Volume and Claim: Set up for static media files.

  • Services: Exposes the Django app, PostgreSQL, and Redis deployments.

Periodic Task

A Celery task runs every 4 minutes to delete data from the database that is older than 4 minutes.

Usage

  1. Clone this repository.
  2. Update the GitHub Actions workflow file with your specific Sentry and Slack configurations.
  3. Deploy the application to your Kubernetes cluster by applying the provided manifests.

Acknowledgments

  • Django for the web framework.
  • GitHub Actions for CI/CD.
  • Kubernetes for orchestration.
  • Sentry for error tracking.
  • Slack for notifications.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Django application with a CI/CD setup integrated with Docker & Kubernetes. The automation pipeline uses GitHub Actions to build, test, and deploy the application, ensuring seamless integration and delivery.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published