Trigger a Kubernetes Deployment from a Docker Hub Push Event
Learn how to trigger a Kubernetes deployment when an image is updated
In this example, we will cover how to trigger a Kubernetes deployment from a Docker Hub Push event using a Dockerhub registry trigger.
Our example has two pipelines: one for packaging code (CI), and the second for deploying code (CD).
Prerequisites
- A Codefresh account
- A Docker Hub registry connected to your Codefresh account
- A Kubernetes cluster connected to your Codefresh account
- A service for your application deployed to your cluster
Example Project
You can see the example project on GitHub. The repository contains a simple Hello World NodeJs app as well as 2 pipelines.
Create the CI Pipeline
As mentioned before, our first pipeline will handle the CI process.
The pipeline has three stages:
- A stage for cloning
- A stage for building the image
- A stage for pushing the image to DockerHub
codefresh-CI-pipeline.yml
This pipeline does the following:
- Clones the source code through a Git clone step.
- Builds a docker image tagged with the Application version through a build step.
- Pushes the Docker image through a push step to the Docker Hub registry you have integrated with Codefresh.
Create the CD Pipeline
This pipeline contains one stage/step, for deploying.
Note that for the trigger mechanism to take place, you will need to add a Docker Hub registry trigger to the pipeline.
codefresh-CD-pipeline.yml
This pipeline does the following:
- Deploys the image to Kubernetes through a deploy step. The deploy step uses a Registry trigger to kick off the pipeline when the updated image is pushed to the registry.
Related articles
CD pipeline examples
Codefresh YAML for pipeline definitions
Creating pipelines
How Codefresh pipelines work
Triggers in pipelines