An Interest In:
Web News this Week
- April 29, 2024
- April 28, 2024
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
Running Kubernetes on Github Actions
This article will cover the steps to spin up a Kubernetes Cluster using Github Actions. Also will discuss the use cases and benefits of this.
Prerequisites
Understanding the Problem
Companies are increasingly using Kubernetes for Production load management. The number of Companies building Kubernetes-specific tools is putting JS frameworks to shame.
Big Companies are choosing to build custom applications and controllers rather than simply using a Helm charts.
But every software needs QA testing! And let me just put this forward owning a K8s Cluster on any provider ain't cheap.
What if I told you, there is a way to test your software changes on a Kubernetes cluster for Free ??
I ran into a similar issue on my personal project Kube-ez. The issue was to build a better CI for my project: Here. Since the project is made to interact with a Kubernetes Cluster, I needed a cluster to check the changes made.
The CI I built saves me more than 300$/year!
Well, this was all about my weekend
Built a CI for my personal project on @github Actions.
It was tricky as I wanted to test each commit inside the pod of a @kubernetesio cluster.
Let me know if I can do a better job in this CI
github.com/kitarp29/kube-10:28 AM - 19 Mar 2023
Let's get building!
These are the steps I used in my CI:
1. Build your project
Make sure the code gets compiled and doesn't run into errors in the initial setup. As bad code will eventually break pipeline. Thus better to compile and verify it early on.
Many Github Actions workflows help you build your project on the CI: Here.
2. Develop a Docker Image
Here starts the interesting part!
Now we will make sure each code change gets its own image to run on the cluster. This is tricky, as you would not want to push new tags to your Docker repository every time the workflow runs.
I suggest using Github Container Registry (ghcr) as a middle man. You can store the image of each commit without messing up your Docker Repository.
- Check out the code for each commit using: actions/checkout.
- Log into ghcr using: docker/login-action
- Build an image of the commit and push it into ghcr with the appropriate tags using: docker/build-and-push
Your code changes are now ready to run on a Cluster
Tip : You could use the
github.SHA
as the tag of the image
3. Running on the Cluster
We will be using: helm/kind-action.
This is the package that provides you with an ephemeral K8s cluster for your CI. This cluster starts and stops at the end of your Github actions workflow.
Alternate Github Actions: Kind
- Start the cluster.
- Mention the commands for setting up the Cluster (* as needed).
- Run your image on the cluster, as done Here.
- You can decalre the commands to test your changes in the yaml.
You did it!
Caution:
List of problems I see with this approach:
- You can't get a CLI connection to this cluster. Only the Kubectl commands you write in the workflow yaml execute.
- In case of infamous errors in the cluster like CrashLoopBackOff or others you can't debug in real-time.
- It restricts a lot of actions you can run on a Cluster.
You can make this Kubernetes Cluster to like your company's sandbox/staging/prod environment. Thus, each Developer can "Psuedo" run their code changes on the env without any cost.
If you liked this content you can follow me or on Twitter at kitarp29 for more!
Thanks for reading my article :)
Original Link: https://dev.to/kitarp29/running-kubernetes-on-github-actions-f2c
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To