Continuing from the previous post. Next, we want to setup the CD(Continuous Deployment) pipeline for our blog.
Workflow
-
User commits a blog post to github.
-
Github CI triggers, which builds and pushes the custom container image to container registry. Image is tagged with the latest git sha checksum.
-
GitHub Actions [CD] triggers image update on the deployment. This CD can be integrated either as a separate job or just another step in the same CI pipeline.
Assumptions
- Kubernetes cluster is already deployed. May be i'll cover the actual installation steps in another blog post.
- Blog is actually deployed on the kubernetes cluster.
- CI part is already completed i.e images are automatically being build and pushed via CI. If you haven't done that already check the previous blog post How to build CI pipeline for Hugo with GitHub Actions
Configure continuous deployment steps in the CI pipeline
To keep it simple, add the following 2 steps to the CI pipeline.
# .github/workflows/build.yaml
# append the lines below to the CI pipeline.
- name: Deploy to cluster
uses: myrotvorets/[email protected]
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
with:
args: set image --record deploy/<deployment-name> <container-name>=<container-registry>/<registry-name>/<image-name>:${{ github.sha }}
- name: Verify deployment
uses: myrotvorets/[email protected]
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
with:
args: rollout status deploy/<deployment-name>
Explanation of the actions configured above:
- I"m using
kubectl-actions
from github marketplace. it'll provide the kubectl command to interact with kubernetes cluster.- Base64 encoded config file for the kubernetes cluster is added as a github secret key
KUBE_CONFIG_DATA
to the repo.- Update the deployment image.
- Verify the deployment status.