Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 3, 2023 11:58 pm GMT

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

  • Basic understanding of Kubernetes : Here
  • Basics of Github Actions : Here

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!

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.

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!

image

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

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To