Continuous Integration for Static Site with Kubernetes
I always wanted to work with Kubernetes but the subject comes with steep
learning curve. Especially for someone who does not work directly with software
infrastructure on day-to-day basis. The best way to learn is to actually use it
in actual setting. This is my first attempt to use Kubernetes to serve a
content on the Internet.
What: Non-Fictitious CI/CD with Kubernetes
My plan is to setup a working and simple Continuous Integration and Continuous
Deployment (CI/CD) workflow that integrates with Kubernetes cluster. What can
be simpler than deploying a static site. I might as well I start a new blog
site. This blog site is the result of CI workflow that I’ll be describing
How: Services that Build and Deploy This Blog to Kubernetes Cluster
Services involved in this CI:
GitHub Action. Workflow orchestration tool that executes steps in CI.
Github Package Registry. Docker image registry provided by Github.
Kubernetes cluster. At the point of writing this post I’m running my cluster on AWS with spot instances provisioned by kops. Still evaluating if this is the cheapest method for running Kubernetes cluster. (This is for future blog post)
Below are the high level steps:
Make changes to my blog repository.
Push to origin with tag (i.e v1.0.0). Pushing to master without tag will not trigger the build which allow me to push my changes to master multiple times without triggering the deployment step.
GitHub Action will do its magic to checkout, build and push newly created image to Kubernetes cluster.
Below is the GitHub Action yml file which wires everthing together.
Github Action Yaml Breakdown
Trigger this Github Action workflow if the push to origin includes tag starting with v. For example v1.0.0.
Standard steps to checkout and retrieve cache (if there is any).
Generate the static site via Jekyll command. I use Docker image to skip Jekyll setup steps.
Build new Docker image for this blog. $IMAGE_NAME value is blog.
Login to Github Package Registry. This is required before pushing the image to the registry.
Push the Docker image registry as docker.pkg.github.com/taufek/blog/blog:1.0.0.