6. Deployment, smoke tests and rollback
6.1 D01 · Staging preflight and server-side dry-run
Linux Bash · Script fragment. Requires an intentional staging kubeconfig, namespace staging and manifest directory k8s/. The service account must have appropriate rights for server-side validation of the resources in that directory.
set -euo pipefail
kubectl config current-context
kubectl auth can-i patch deployment/health-api -n staging --quiet
kubectl --namespace staging apply --dry-run=server --filename k8s/Verify. Correct an invalid manifest or missing permission, then rerun. A successful dry-run leaves live Deployment state unchanged.
6.2 D02 · Manually deploy an approved immutable image
GitHub Actions · Full workflow. Create a staging environment with rules available on your plan and a protected deployment branch. Put the probe-compatible Deployment health-api with container app in namespace staging first. Configure STAGING_IMAGE_REPOSITORY (for example ghcr.io/owner/service) and KUBE_CONFIG_B64 as an environment variable and environment secret, respectively. Use a restricted staging kubeconfig that can get, watch and patch the Deployment. Choose a reviewed kubectl version compatible with the cluster and set STAGING_KUBECTL_VERSION. The runner needs network access to the Kubernetes API. Configure registry pull credentials in the cluster for private packages.
name: Deploy approved digest to staging
on:
workflow_dispatch:
inputs:
digest:
description: Approved image digest from the trusted publish run
required: true
type: string
permissions: {}
jobs:
deploy:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 10
environment: staging
concurrency:
group: staging-health-api
cancel-in-progress: false
steps:
- uses: azure/setup-kubectl@v4
with:
version: ${{ vars.STAGING_KUBECTL_VERSION }}
- name: Deploy and wait
env:
IMAGE_REPOSITORY: ${{ vars.STAGING_IMAGE_REPOSITORY }}
IMAGE_DIGEST: ${{ inputs.digest }}
KUBE_CONFIG_B64: ${{ secrets.KUBE_CONFIG_B64 }}
shell: bash
run: |
set -euo pipefail
: "${IMAGE_REPOSITORY:?configure STAGING_IMAGE_REPOSITORY}"
: "${KUBE_CONFIG_B64:?configure KUBE_CONFIG_B64}"
if [[ ! "$IMAGE_DIGEST" =~ ^sha256:[a-f0-9]{64}$ ]]; then
echo "Expected a sha256 image digest" >&2
exit 1
fi
umask 077
config=$(mktemp)
trap 'rm -f -- "$config"' EXIT
printf '%s' "$KUBE_CONFIG_B64" | base64 --decode > "$config"
kubectl --kubeconfig "$config" --namespace staging set image \
deployment/health-api app="$IMAGE_REPOSITORY@$IMAGE_DIGEST"
kubectl --kubeconfig "$config" --namespace staging rollout status \
deployment/health-api --timeout=180sVerify. Compare the requested digest to the publish run and the live Deployment. A valid digest string identifies content. Verify its publisher with S04 or check the approved build record before approving the run. Use short-lived cluster credentials where available.
6.3 D03 · Serialize a staging deployment
GitHub Actions · Job-level fragment. Use the same group for every job in this repository that modifies this staging workload.
concurrency:
group: staging-health-api
cancel-in-progress: falseVerify. Dispatch two staging deployments. By default GitHub keeps at most one running and one pending in a group, so a newer queued run can replace an older pending run. This does not coordinate deployments made from another repository or directly with kubectl.
6.4 D04 · Smoke-test the deployed Service
Linux Bash · Script fragment. Run after rollout from a runner that can reach the application. Set STAGING_URL to a stable staging route.
set -euo pipefail
: "${STAGING_URL:?set STAGING_URL to the approved staging URL}"
base_url="${STAGING_URL%/}"
curl --fail --silent --show-error \
--connect-timeout 3 --max-time 10 --retry 3 --retry-delay 1 \
"$base_url/readyz" | python3 -c \
'import json, sys; assert json.load(sys.stdin)["ready"] is True'Verify. Point this only at the intended lab endpoint. A response with the wrong JSON fails even when its HTTP status is 200.
6.5 D05 · Restore a known-good digest
Linux Bash · Script fragment. Requires the same staging cluster and deploy privileges as D02. Set PREVIOUS_IMAGE to the full image reference from your previous verified deployment.
set -euo pipefail
: "${PREVIOUS_IMAGE:?set the last verified image reference}"
[[ "$PREVIOUS_IMAGE" =~ @sha256:[a-f0-9]{64}$ ]]
kubectl -n staging set image deployment/health-api app="$PREVIOUS_IMAGE"
kubectl -n staging rollout status deployment/health-api --timeout=180s
kubectl -n staging get deployment health-api \
-o 'jsonpath={.spec.template.spec.containers[?(@.name=="app")].image}{"\n"}'Verify. Compare the deployed reference to PREVIOUS_IMAGE and rerun D04. If reverting the whole pod template is intended, inspect kubectl rollout history first and select a specific revision with kubectl rollout undo --to-revision. Database changes may need a separate recovery plan.
6.6 D06 · Validate a GitOps image promotion in a pull request
Linux Bash · Script fragment. Requires a staging Kustomize overlay, matching image name and an installed kustomize binary. Set APPROVED_DIGEST in the trusted operator shell. A reviewer merges the resulting manifest change into the branch Argo CD watches.
set -euo pipefail
[[ "${APPROVED_DIGEST:-}" =~ ^sha256:[a-f0-9]{64}$ ]]
cd deploy/overlays/staging
kustomize edit set image "ghcr.io/example/health-api@${APPROVED_DIGEST}"
kustomize build . >/dev/null
git diff -- kustomization.yamlVerify. Confirm the patch changes only the intended image reference. After merge, compare Argo CD's target revision, application health and pod image, then run D04. Use a revert PR to restore a prior GitOps state.
Reference · GitHub deployment environments, Deployment rollouts, Kustomize.