Automatic Deployment Setup¶
Overview¶
Your GitHub Actions workflow now automatically deploys to Kubernetes environments after building and pushing Docker images. This document explains the required setup and secrets.
Automatic Deployment Flow¶
Branch-to-Environment Mapping¶
mainbranch → Production environment (prodnamespace)stagingbranch → Staging environment (stagingnamespace)developbranch → Development environment (devnamespace)
What Happens Automatically¶
- Code is pushed to
main,staging, ordevelopbranch - Docker image is built and pushed to Google Artifact Registry
- Deployment is automatically restarted in the corresponding environment
- Workflow waits for rollout to complete (5 minute timeout)
- Pod status is verified and reported
Required GitHub Secrets¶
You need to configure these secrets in your GitHub repository settings:
Existing Secrets¶
GCP_SERVICE_ACCOUNT_KEY- Already configured for Docker buildsDATABASE_URL- Already configured for builds
Configuration¶
The workflow uses the following hardcoded values for the GKE cluster:
- Cluster Name:
kame-house - Cluster Region:
us-central1(regional cluster) - Project:
kame-457417
No additional secrets are required for deployment since cluster details are not sensitive.
Setup Requirements¶
Only the existing secrets are needed:
GCP_SERVICE_ACCOUNT_KEY: Already configured for Docker builds and deploymentsDATABASE_URL: Already configured for builds
Service Account Permissions¶
Ensure your service account (GCP_SERVICE_ACCOUNT_KEY) has these IAM roles:
roles/container.developer- To access GKE clustersroles/artifactregistry.writer- To push Docker images (already configured)
Workflow Behavior¶
Successful Deployment¶
- ✅ Image built and pushed
- ✅ Deployment restarted
- ✅ Rollout completed successfully
- ✅ Pod status verified
Branch Protection¶
- Only
main,staging, anddeveloptrigger deployments - Pull requests build images but don't deploy
- Other branches build images but don't deploy
Timeout and Error Handling¶
- Deployment rollout timeout: 5 minutes
- Failed deployments will fail the workflow
- Successful builds with failed deployments will show which step failed
Verification Commands¶
After setup, you can verify deployments:
# Check deployment status
kubectl rollout status deployment/portfolio -n prod
kubectl rollout status deployment/portfolio -n staging
kubectl rollout status deployment/portfolio -n dev
# View pods
kubectl get pods -n prod -l app=portfolio
kubectl get pods -n staging -l app=portfolio
kubectl get pods -n dev -l app=portfolio
Benefits¶
✅ Zero-click deployments - Push code, get deployed automatically
✅ Environment parity - Same process for all environments
✅ Fast updates - No waiting for manual deployment
✅ Visibility - Deployment status in GitHub Actions
✅ Rollback ready - Standard Kubernetes rollout capabilities
Rollback Process¶
If you need to rollback a deployment:
# Rollback to previous version
kubectl rollout undo deployment/portfolio -n prod
kubectl rollout undo deployment/portfolio -n staging
kubectl rollout undo deployment/portfolio -n dev
# Rollback to specific revision
kubectl rollout undo deployment/portfolio --to-revision=2 -n prod
Monitoring¶
- GitHub Actions will show deployment status
- Kubernetes events will be logged
- Failed deployments will fail the workflow
- Successful deployments will be confirmed in the workflow summary