Staging
Staging
A test environment before production. Configured to resemble the real environment.
Staging
A test environment before production. Configured to resemble the real environment.
Staging is a test environment where final verification is performed before deploying to the production environment. By configuring it as identically to actual production as possible, problems can be found and fixed before deployment.
A staging environment should use the same infrastructure configuration as production (server specs, network, security settings), a similar data volume, and the same deployment pipeline. Manual testing by the QA team, integration tests, performance tests, security scans, and more are performed in this environment. The goal is to build confidence that "if it succeeded in staging, it will succeed in production too."
# base/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-server
spec:
selector:
matchLabels:
app: api-server
template:
metadata:
labels:
app: api-server
spec:
containers:
- name: api
image: myapp/api-server
ports:
- containerPort: 8080
envFrom:
- configMapRef:
name: app-config
- secretRef:
name: app-secrets
---
# overlays/staging/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: staging
resources:
- ../../base
replicas:
- name: api-server
count: 2 # νλ‘λμ
λ³΄λ€ μ μ λ ν리카
configMapGenerator:
- name: app-config
literals:
- ENV=staging
- LOG_LEVEL=debug
- DB_HOST=staging-db.internal
- FEATURE_NEW_UI=true # μ€ν
μ΄μ§μμ λ¨Όμ ν
μ€νΈ
images:
- name: myapp/api-server
newTag: staging-latest
# .github/workflows/staging-deploy.yaml
name: Deploy to Staging
on:
push:
branches: [develop]
pull_request:
types: [labeled]
jobs:
deploy-staging:
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'deploy-staging')
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
- name: Build and Push Image
run: |
docker build -t ${{ vars.REGISTRY }}/api-server:staging-${{ github.sha }} .
docker push ${{ vars.REGISTRY }}/api-server:staging-${{ github.sha }}
- name: Deploy to Staging
run: |
kubectl config use-context staging-cluster
cd k8s/overlays/staging
kustomize edit set image myapp/api-server=${{ vars.REGISTRY }}/api-server:staging-${{ github.sha }}
kustomize build | kubectl apply -f -
kubectl rollout status deployment/api-server -n staging --timeout=5m
- name: Run Smoke Tests
run: |
sleep 30 # μμ ν λκΈ°
curl -f https://staging.myapp.com/health
npm run test:smoke -- --env=staging
- name: Notify on Slack
if: always()
uses: slackapi/slack-github-action@v1
with:
payload: |
{
"text": "Staging λ°°ν¬ ${{ job.status }}: ${{ github.sha }}"
}
#!/bin/bash
# staging-data-sync.sh - νλ‘λμ
λ°μ΄ν° μ΅λͺ
ν ν μ€ν
μ΄μ§μΌλ‘ 볡μ
set -e
PROD_DB="prod-db.internal"
STAGING_DB="staging-db.internal"
BACKUP_FILE="/tmp/staging_data_$(date +%Y%m%d).sql"
echo "=== νλ‘λμ
λ°μ΄ν° λ€ν ==="
pg_dump -h $PROD_DB -U readonly \
--exclude-table=audit_logs \
--exclude-table=sessions \
myapp > $BACKUP_FILE
echo "=== λ―Όκ° λ°μ΄ν° μ΅λͺ
ν ==="
# μ΄λ©μΌ μ΅λͺ
ν
sed -i "s/[a-zA-Z0-9._%+-]*@[a-zA-Z0-9.-]*\.[a-zA-Z]*/user_XXX@example.com/g" $BACKUP_FILE
# μ νλ²νΈ λ§μ€νΉ
sed -i "s/010-[0-9]\{4\}-[0-9]\{4\}/010-XXXX-XXXX/g" $BACKUP_FILE
echo "=== μ€ν
μ΄μ§ DB 볡μ ==="
psql -h $STAGING_DB -U admin myapp < $BACKUP_FILE
echo "=== μ 리 ==="
rm $BACKUP_FILE
echo "μ€ν
μ΄μ§ λ°μ΄ν° λκΈ°ν μλ£"