DeployJob is a GitHub Actions job that handles deployment of applications to a Kubernetes cluster. It synthesizes cdk8s manifests and applies them using kubectl, with built-in branch protection.
Overview
TheDeployJob automates the deployment process by:
- Synthesizing cdk8s Kubernetes manifests from TypeScript definitions
- Connecting to an AWS EKS cluster
- Applying manifests with certificate components first
- Deploying the application with pruning enabled
master branch to prevent accidental production deploys from feature branches.
Constructor
Parameters
The cdkactions Workflow instance to add the deploy job to.
Optional configuration for the deploy job.
The Git SHA or tag to use for the deployment. This is passed to the cdk8s synth process as the
GIT_SHA environment variable.The branch that deployments are limited to. Deployments will only run when this branch is pushed.
Optional overrides for the job configuration. Commonly used to set the
needs property to create job dependencies.Basic Usage
Add a deploy job to a workflow:Advanced Usage
Deploy After Build Jobs
Most commonly, the deploy job should wait for build and publish jobs to complete:Custom Branch
Deploy from a different default branch:Custom Deploy Tag
Use a custom tag instead of the Git SHA:Complete Example
Full workflow with build and deploy:Deployment Process
The job executes two main steps:1. Synthesize Manifests
The first step:- Changes to the
k8sdirectory - Installs dependencies with
yarn install --frozen-lockfile - Extracts the repository name from
${{ github.repository }} - Runs
yarn buildto synthesize cdk8s manifests - Outputs the release name for use in deployment
GIT_SHA- The deploy tag (defaults to current commit SHA)REPOSITORY- The GitHub repository nameAWS_ACCOUNT_ID- The AWS account ID (from secrets)
2. Deploy to Kubernetes
The second step:- Updates kubeconfig to connect to the EKS production cluster
- Applies certificate resources first:
kubectl apply -f k8s/dist/ -l app.kubernetes.io/component=certificate - Deploys application with pruning:
kubectl apply -f k8s/dist/ --prune -l app.kubernetes.io/part-of=$RELEASE_NAME
AWS_ACCOUNT_ID- AWS account containing the EKS clusterGH_AWS_ACCESS_KEY_ID- AWS access key for GitHub ActionsGH_AWS_SECRET_ACCESS_KEY- AWS secret key for GitHub Actions
Branch Protection
The job includes a conditional that prevents deployment from non-default branches:Required Setup
For theDeployJob to work, your repository must have:
- A
k8s/directory with cdk8s TypeScript definitions - A
k8s/package.jsonwith abuildscript that runs cdk8s synth - GitHub secrets configured:
AWS_ACCOUNT_IDGH_AWS_ACCESS_KEY_IDGH_AWS_SECRET_ACCESS_KEY
- Appropriate IAM permissions for the GitHub Actions role to access EKS
See Also
- LabsApplicationStack - Complete CI/CD stack including deployment
- DjangoProject - Build Django images to deploy
- ReactProject - Build React images to deploy