Article

Table of Contents
Theme:
Was this article helpful?
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles.

Installing and Using GitHub Actions Runner on Vultr Kubernetes Engine

Author: Adhing'a Fredrick

Last Updated: Wed, Feb 1, 2023
Kubernetes

Introduction

GitHub Actions runner, is a CI/CD system for managing jobs in software projects hosted on GitHub. Runners can be installed in three levels: enterprise, organization, and repository.

In this tutorial, you will learn how to install and use GitHub Actions runner into Vultr Kubernetes Engine.

Prerequisites

To follow through this tutorial, you need the following:

VKE Configuration

Access your VKE configuration file by following the steps below:

  • Login to your Vultr account and navigate to Products > Kubernetes > {Your cluster}>Overview.

  • Click on the Download Configuration button to download your kubeconfig file.

    Note: Keep this configuration file for later use when setting up your GitHub runner.

Setting Up Runner Requirements

  1. Install a cert-manager in your VKE cluster using the command below:

    $ kubectl --kubeconfig={VKE_CLUSTER_CONFIG_FILE_PATH} apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.11.0/cert-manager.yaml
    
  2. Generate a Personal Access Token (PAT) for ARC for GitHub authentication.

    • Sign in to your GitHub account and navigate to the Create new Token. page.

    • Enter a Note for the token to be generated. An example can be Action-Runner

    • Select repo and workflow.

    • Customize the time you want the token to last by Adjusting the Expiration settings.

    • Click the Generate Token button to generate the token.

    • Copy and securely store the token locally for later use.

Deploy and Configure Actions Runner Controller

To configure and deploy ARC on your VKE k8s using kubectl, follow the steps below:

  1. Deploy the ARC using the command below:

    $ kubectl --kubeconfig={VKE_CLUSTER_CONFIG_FILE_PATH} create -f https://github.com/actions/actions-runner-controller/releases/download/v0.26.0/actions-runner-controller.yaml
    

    As at the time of writing this, the latest version is v0.26.0. Customize the version to your desired ARC version.

  2. Configure the Personal Access Token using the token you saved earlier in the tutorial.

    $ kubectl --kubeconfig={VKE_CLUSTER_CONFIG_FILE_PATH} create secret generic controller-manager -n actions-runner-system --from-literal=github_token=PAT_TOKEN
    

    Replace the PAT_TOKEN with your GitHub PAT token.

  3. Create a runnerdeployment.yaml file and copy the following YAML contents into it:

    apiVersion: actions.summerwind.dev/v1alpha1
    
    kind: RunnerDeployment
    
    metadata:
    
      name: example-runnerdeploy
    
    spec:
    
      replicas: 1
    
      template:
    
        spec:
    
          repository: FREDERICO23/arc-runner
    

    The runnerdeployment.yaml file is used to create a self-hosted runner and configure it to run against your GitHub repository.

    Note: Replace "FREDERICO23/arc-runner" with your repository name.

  4. Apply the runnerdeployment.yaml file to your K8s cluster as follows:

    $ kubectl --kubeconfig={VKE_CLUSTER_CONFIG_FILE_PATH} apply -f runnerdeployment.yaml
    
  5. Confirm if the installation was successful using the command below:

    $ kubectl --kubeconfig={VKE_CLUSTER_CONFIG_FILE_PATH} get runners
    

    Expected Output:

    NAME                       ENTERPRISE   ORGANIZATION   REPOSITORY               GROUP   LABELS   STATUS    MESSAGE   AGE
    
    runnerdeploy-gcvdr-bdpf5                               FREDERICO23/arc-runner                    Running             39s 
    

    Check the pods status:

    $ kubectl --kubeconfig={VKE_CLUSTER_CONFIG_FILE_PATH} get pod
    

    Expected Output:

    NAME                       READY   STATUS    RESTARTS   AGE
    
    runnerdeploy-gcvdr-bdpf5   2/2     Running   0          5m11s
    

You've finished installing GitHub Actions runner on your VKE. You can now go to your repository settings and check if the runner exists.

Using self-hosted runners in a workflow

To use the previously installed runner, you need a GitHub Actions workflow.

  1. Create a .github/workflows folder on your repo where the runner is installed. 2. Inside the folder, .github/workflows, create a hello-world.yml file and paste the following GitHub Actions Demo content in it.

    name: GitHub Actions Demo
    
    run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
    
    on: [push]
    
    jobs:
    
      Explore-GitHub-Actions:
    
        runs-on: ubuntu-latest
    
        steps:
    
          - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
    
          - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
    
          - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
    
          - name: Check out repository code
    
            uses: actions/checkout@v3
    
          - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
    
          - run: echo "🖥️ The workflow is now ready to test your code on the runner."
    
          - name: List files in the repository
    
            run: |
    
              ls ${{ github.workspace }}
    
          - run: echo "🍏 This job's status is ${{ job.status }}."
    
  2. Save and commit the file.

  3. On your repo directory, click the Actions tab. You will see the recently created Hello World workflow listed.

Conclusion

You have finished installing GitHub Action Runner in Vultr Kubernetes Engine (VKE) cluster using kubectl and learned how to use it to manage your workflows. You can now create and manage CD/CI projects using the GitHub Actions runner and VKE.

Want to contribute?

You could earn up to $600 by adding new articles.