Step-by-Step Guide to Deploying a Django Application on Kuberns
This tutorial guides you through deploying a Django application on Kuberns.
Kuberns automates configuration, build, and runtime tasks, while providing flexibility through the Dashboard for advanced customization.
1. Creating a Project
All services in Kuberns are organized under a project. To deploy your Django application, start by creating a project to manage your services.
- On the Kuberns Dashboard, new users are prompted to create a project by default. If you are already working with Kuberns, click the Add New button in the top-right corner of the navbar.
- Give your project a memorable and relevant name.
- Select Backend Service as the service type to start with.
For more details on projects, refer to the Projects guide.
2. Creating a Service
Connect with GitHub
To deploy your Django application, you’ll need to connect your GitHub repository to Kuberns.
- After selecting the service type, you’ll be redirected to the "Creating a Service" page.
- If this is your first time using Kuberns, you’ll need to authorize Kuberns to access your GitHub repositories. Click Connect to GitHub and follow the prompts to authenticate.
- Once authorized, select the organization, repository, and branch containing your Django application.
This links your GitHub account to Kuberns, allowing you to choose from your repositories directly in the Dashboard.
For more details on services, refer to the Services guide.
3. Configuring Environment Variables
Environment variables are crucial for configuring your Django application (e.g., SECRET_KEY, database credentials). Kuberns allows you to set these variables directly in the Dashboard.
How to Configure Environment Variables
- Navigate to the Environment section of your service in the Kuberns Dashboard.
- Kuberns provides default environment variables necessary for your application.
- To add custom variables:
- Click Add New Environment Variable.
- Input the key-value pairs or upload .env file.
- Save the changes before deploying.
For more details on environment variables, refer to the Environments variable guide.
4. Auto-Detected Django Configuration
Kuberns AI automatically detects and configures your Django application, simplifying the deployment process.
How It Works
- Kuberns scans your repository for required files. If any are missing, the build will fail, and errors will appear in the build logs.
- It automatically detects the necessary commands to run your Django application.
- Kuberns dynamically assigns a port for your web service, so you don’t need to specify it in your code.
This automation ensures your Django application is deployed with minimal setup, following best practices for stability and performance.
5. Deploying Your Application
Deploy Your Application
- On your service page in the Kuberns Dashboard, click the Deploy button.
- Monitor the deployment process using the real-time logs provided in the Dashboard.
Post-Deployment Monitoring
- After deployment, navigate to the Activities section to view logs and monitor your application’s status.
- Use the Build History section to track build statuses and access detailed logs for debugging.
- The Activities section also logs actions by team members, ensuring transparency and collaboration.
- In the Resources Management section, track the start/stop status of your resources to manage utilization and avoid downtime.
6. Customizing Runtime Configuration
After your initial deployment, you can customize the Python runtime version if the default (selected by Kuberns AI) doesn’t meet your needs.
How to Customize the Runtime
- Navigate to the Deploy Config section in the Kuberns Dashboard.
- Locate the Runtime Configuration option.
- Select your desired Python version.
- Save the changes and redeploy your application to apply the new runtime.
If no custom runtime is specified, Kuberns will continue using the AI-selected default.
7. Adding Pre-Build and Post-Build Commands
After deployment, you can add custom pre-build and post-build commands to tailor the build process to your specific needs.
Kuberns automates these tasks by default, but custom commands provide additional flexibility.
Configuring Pre-Build Commands
- Navigate to the Deploy Config section in the Kuberns Dashboard.
- Locate the Pre-Build Scripts section.
- Add commands to execute before the build.
- Save and redeploy to apply.
Configuring Post-Build Commands
- Navigate to the Deploy Config section in the Kuberns Dashboard.
- Locate the Post-Build Scripts section.
- Add commands to execute after the build.
- Save and redeploy to apply.
If no custom commands are specified, Kuberns AI will handle these tasks automatically.
8. Managing Environments
Creating Additional Environments
To create environments for staging or testing:
- From your service dashboard, select Add New Environment.
- Choose the repository, branch, and hosting region for the new environment.
Cloning Environment Variables
- Kuberns allows you to clone environment variables from one environment to another for consistency.
- In the Environment section, select the option to clone variables from an existing environment.
For more details on managing environments, refer to the Environments guide.
Best Practices
- Leverage AI Automation: Rely on Kuberns AI for runtime and build configurations to minimize errors.
- Secure Environment Variables: Use the Dashboard to store sensitive data avoiding hardcoded values in your code.
- Monitor Logs: Regularly check the Activities and Build History sections to ensure your application runs smoothly.
- Test Before Deploying: Test custom pre-build or post-build scripts locally to avoid deployment failures.
- Static Files: Ensure your Django project is configured to handle static files.