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:

  1. Creating the Production Environment
  2. Configuring Deployment Protection Rules
  3. Adding Repository Secrets
  4. Defining Environment Variables

1. Create the Production Environment

  1. Navigate to your repository’s SettingsEnvironments.
  2. Click New environment.
  3. 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 TypeConfigurationDescription
Wait timer1 minuteDelay before deployment begins.
Required approvals1Minimum number of reviewers.
Branch restrictionsmainOnly 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:

  1. In production, click New repository secret.
  2. Name: KUBECONFIG
  3. Value: Your base64-encoded kubeconfig content.
  4. 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:

VariableValue
namespaceproduction
replicas5

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

Previous
Modify Dev Deployment Job to use Environment tags