GitHub Actions
Continuous Deployment with GitHub Actions
Create Prod Environment Secrets Environment Rules
Learn how to configure a secure, production-ready environment in GitHub with deployment protection rules, secrets, and environment variables.
In this guide you’ll cover:
- Creating the Production Environment
- Configuring Deployment Protection Rules
- Adding Repository Secrets
- Defining Environment Variables
1. Create the Production Environment
- Navigate to your repository’s Settings → Environments.
- Click New environment.
- Enter
production
as the environment name and hit Create environment.
Note
Environments let you control deployment workflows and apply protection rules per stage. For more details, see GitHub Environments.
2. Configure Deployment Protection Rules
Open the newly created production environment and apply these settings:
Rule Type | Configuration | Description |
---|---|---|
Wait timer | 1 minute | Delay before deployment begins. |
Required approvals | 1 | Minimum number of reviewers. |
Branch restrictions | main | Only workflows from main can deploy. |
a. Deployment Wait Timer
Set Wait timer to 1 minute
to introduce a brief delay before the job starts.
b. Required Reviewers
- Required approvals:
1
- Reviewers: Select up to 6 team members.
- (Optional) Disable Allow self approval to prevent deployers from approving their own workflows.
c. Branch Restrictions
Under Branch restrictions, choose only the main
branch to ensure that only the approved branch can trigger production deployments.
3. Add Secrets
Store sensitive data as encrypted secrets in the production
environment:
- In production, click New repository secret.
- Name:
KUBECONFIG
- Value: Your base64-encoded kubeconfig content.
- Click Add secret.
Warning
Never commit raw kubeconfig files or credentials to your repository. Always use secrets to keep sensitive data secure.
4. Define Environment Variables
Specify variables your deployment workflow will consume:
Variable | Value |
---|---|
namespace | production |
replicas | 5 |
Click Save changes to apply your configuration.
Validate Your Setup
To confirm your configuration, trigger a GitHub Actions workflow that targets the production
environment. Check the Environments tab in your workflow run for applied protection rules and secrets usage.
References
Watch Video
Watch video content