Skip to content

temp kubernetes cluster in github actions CI for both linux & windows

License

Notifications You must be signed in to change notification settings

KnicKnic/temp-kubernetes-ci

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

test

Temp Kubernetes CI

A github action to create a kubernetes cluster in your CI VM for both linux & windows. Also has cmdline to copy and paste for other CI platforms.

Usage

For linux you can reference k3s environment variables on setting additional parameters

GitHub Action

    - uses: knicknic/temp-kubernetes-ci@v1

Other CI platform

Simply copy the below code snippet to get the latest version of the code

Linux

releaseVersion=$(curl --silent "https://api.github.com/repos/knicknic/temp-kubernetes-ci/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")')
curl -sSL "https://github.com/KnicKnic/temp-kubernetes-ci/releases/download/$releaseVersion/linux.sh" | sh

Windows

$request = [System.Net.WebRequest]::Create('https://github.com/KnicKnic/temp-kubernetes-ci/releases/latest')
$response = $request.GetResponse()
$tag = $response.ResponseUri.OriginalString.split('/')[-1]
$url =  "https://github.com/KnicKnic/temp-kubernetes-ci/releases/download/$tag/windows.ps1"
$filePath = join-path $env:temp windows.ps1
Invoke-WebRequest -Uri $url -OutFile $filePath
& $filePath

Why

When dealing with kubernetes you end up wanting to test against an actual kubernetes cluster.

  1. Test your deployment files / helm charts actually deploy your app correctly
  2. Test the controller you wrote against an actual kubernetes api server

Source

file description
index.js determines what os and launches either linux.sh or windows.ps1 to install k3s
linux.sh script to install k3s on linux
windows.ps1 script to install k3s on windows

Tasks

  1. Figure out how to install k3s on linux and write a script to do so
  2. Figure out how to install k3s on windows and write a script to do so
    1. See k3s-io/k3s#1618 for some info & a branch to start from
  3. Convert script to Github Action
    1. https://docs.github.com/en/actions/creating-actions/publishing-actions-in-github-marketplace
  4. Convert script to azure devops custom task - see https://docs.microsoft.com/en-us/azure/devops/extend/develop/integrate-build-task?view=azure-devops
    1. Find out if there is a market place for custom tasks like their is for github actions
  5. Write a dynamic storage provisioner for windows folders (enables windows to fufill PVCs)
    1. take https://github.com/KnicKnic/K8s-Storage-Plugins/tree/new_new and add a flexprovisioner & flexvolume that are just windows folders
    2. take https://github.com/rancher/local-path-provisioner and get that to work with windows
      1. This will also probably require csi proxy, which we could embed into k3s or run standalone
  6. Publish docs so generic CI platforms can use
  7. Write a load balancer for windows, equivalent of https://github.com/rancher/klipper-lb
  8. Integrate linux with k3d to allow multiple linux nodes for a more realistic user scenario

Links

Developer instructions

Setup Environment

npm i -g @vercel/ncc@0.26.2
npm install

Update project

ncc build index.js