This guide walks you through the process of safely deploying applications to production environments. It covers preparation, best‑practice strategies, continuous integration pipelines, and rollback methods.
ssh
keys or service accounts.Choose the strategy that matches your risk tolerance and architecture.
# Example using AWS Elastic Beanstalk
eb create blue-env
eb create green-env
# Swap CNAME when ready
eb swap blue-env green-env
# Kubernetes canary using Argo Rollouts
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: my-app
spec:
strategy:
canary:
steps:
- setWeight: 10
- pause: {duration: 5m}
- setWeight: 30
- pause: {duration: 5m}
- setWeight: 100
# Docker Swarm rolling update
docker service update \
--image myapp:1.2.0 \
--update-parallelism 2 \
--update-delay 10s \
myapp_service
Automate builds, tests, and deployments using pipelines. Below is a GitHub Actions example for Docker deployments.
name: CI/CD Pipeline
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: myrepo/myapp:latest
- name: Deploy to Kubernetes
uses: azure/k8s-deploy@v4
with:
manifests: k8s/deployment.yaml
images: myrepo/myapp:latest
kubectl-version: 'v1.27.0'
namespace: production
In case of a failed deployment, revert to the previous stable version.
# Revert to previous image tag
docker service update \
--image myapp:1.1.0 \
myapp_service
# Rollback using rollout undo
kubectl rollout undo deployment/my-app --to-revision=2