Master GitHub Actions with hands-on labs and exercises. Learn how to automate workflows, run tests, deploy applications, and more using GitHub's powerful automation platform. This repository has everything you need to get started with continuous integration and continuous deployment.
In this lab, you will set up the Azure Kubernetes Service (AKS) cluster and install the required tools to deploy GitHub Actions Runner Controller (ARC). You will also set up the necessary environment for GitHub Actions to run workflows using the self-hosted runner.
Duration: 90-120 minutes
Before starting this lab, ensure that you have:
You can follow the documentation to install the required CLI tools:
In this step, you will set up the AKS cluster and install the required CLI tools.
Make sure the following tools are installed:
Azure CLI
az version
kubectl
kubectl
using the Azure CLI:
az aks install-cli
kubectl version --client
Helm
helm version
Log in to Azure CLI:
az login
This will open a browser window to authenticate your account.
Create a Resource Group:
az group create --name arc-lab-rg --location uksouth
Create the AKS Cluster: Create an AKS cluster with 2 nodes and SSH keys:
az aks create \
--resource-group arc-lab-rg \
--name arc-lab-cluster \
--node-count 2 \
--generate-ssh-keys
Get the AKS Credentials:
Fetch the credentials to interact with the AKS cluster using kubectl
:
az aks get-credentials --resource-group arc-lab-rg --name arc-lab-cluster
Verify the Cluster: Ensure your cluster is accessible:
kubectl get nodes
You should see a list of the nodes in your AKS cluster.
Create a Namespace for ARC: Create a dedicated namespace for Actions Runner Controller:
kubectl create namespace arc-runners
Optional: If you later decide to set up custom cert-manager (for TLS certificates), follow the instructions below. This step is optional for now and can be skipped for most users.
At this stage, you should have:
Azure CLI
, kubectl
, Helm
).arc-runners
namespace created for deploying ARC.You’re now ready to move on to the next step of deploying the Actions Runner Controller (ARC).
In this step, we will install the GitHub Actions Runner Controller (ARC) into your AKS cluster using Helm. The ARC will manage self-hosted runners that can be used by your GitHub workflows.
Install the Actions Runner Controller:
First, install the Actions Runner Controller in the arc-systems
namespace by running the following Helm command:
NAMESPACE="arc-systems"
helm install arc \
--namespace "${NAMESPACE}" \
--create-namespace \
oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller
helm install
command will install the Actions Runner Controller into your AKS cluster.Configure the GitHub Runner:
After the installation, you need to configure the runner set with your GitHub repository. You will set the repository URL and the GitHub Personal Access Token (PAT) that the ARC will use to authenticate with your GitHub account.
Run the following command to configure the ARC:
INSTALLATION_NAME="arc-runner-set"
NAMESPACE="arc-runners"
GITHUB_CONFIG_URL="https://github.com/prasadhonrao/github-actions-workshop"
GITHUB_PAT="your_personal_access_token_here"
helm upgrade "${INSTALLATION_NAME}" \
--namespace "${NAMESPACE}" \
--create-namespace \
--set githubConfigUrl="${GITHUB_CONFIG_URL}" \
--set githubConfigSecret.github_token="${GITHUB_PAT}" \
oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set
githubConfigUrl
: This is the URL to your GitHub repository where you want to set up the runner.githubConfigSecret.github_token
: This is the Personal Access Token (PAT) that will authenticate the ARC with GitHub and give it the necessary permissions to manage self-hosted runners for your repository.Create the GitHub Token Secret:
If you haven’t already created a Kubernetes secret for your GitHub PAT, do so by running:
kubectl create secret generic github-token \
--namespace=arc-runners \
--from-literal=github_token='your_personal_access_token_here'
arc-runners
namespace, storing the GitHub token which is used by the Actions Runner Controller for authentication.After installing and configuring the GitHub Actions Runner Controller (ARC), you can monitor the status of the runners and verify that the controller is managing them properly. This step ensures that the ARC is correctly creating and scaling runner containers based on your GitHub workflows.
Check the Status of the Pods:
To verify that the Actions Runner Controller is running correctly, use the following command to check the status of the pods in the arc-runners
namespace:
kubectl get pods -n arc-runners
arc-runners
namespace, which includes the controller’s pods and the self-hosted runner pods.arc-runner-set-*
indicating the runner set.Check the Logs of the Actions Runner Controller:
To get more detailed information about the actions and potential issues with the runner controller, check the logs of the ARC pod. First, identify the pod name:
kubectl get pods -n arc-systems
Then, fetch the logs for the pod with the following command:
kubectl logs -n arc-systems <arc-controller-pod-name>
Monitor the Runner Pod Creation:
Once your GitHub workflow triggers the runner to start, the ARC should dynamically create a runner pod. To monitor this, watch the pod creation events in the arc-runners
namespace:
kubectl get pods -n arc-runners --watch
arc-runner-set-<random_id>
.Verify Runner Registration on GitHub:
To confirm that the runner is properly registered with GitHub and can be used by workflows, visit the Settings of your GitHub repository.
Inspect the Runner’s Resource Usage:
As workflows run, it’s important to monitor the resource usage of the runner pods. You can check this by running:
kubectl top pod -n arc-runners
arc-runners
namespace.This step ensures that your Actions Runner Controller is properly managing the lifecycle of self-hosted runners and that they are being used as expected within your GitHub workflows.
Now that the Actions Runner Controller (ARC) is installed and your self-hosted runner is properly configured, it’s time to trigger a GitHub workflow that will utilize this runner. This step will guide you through the process of using the runner for your workflows.
Create a GitHub Actions Workflow:
You need to create a workflow that specifies your self-hosted runner as the execution environment for the job. In your GitHub repository, navigate to the .github/workflows
directory and create a new YAML file (e.g., k8s-arc-runner.yml
).
Here’s a sample workflow file that you can use:
name: K8s ARC Runner
on:
push:
paths:
- '.github/workflows/k8s-arc-runner.yml'
workflow_dispatch:
jobs:
run:
runs-on: arc-runner-set
steps:
- run: echo "🎉 This job uses runner scale set runners!"
runs-on: [arc-runner-set]
line, which specifies that the job should run on the self-hosted runner set managed by the ARC.Commit and Push the Workflow:
After creating the workflow file, commit and push the changes to the repository.
git add .github/workflows/k8s-arc-runner.yml
git commit -m "Add workflow to use self-hosted runner"
git push origin main
push
event on the main
branch.Monitor the Workflow Run:
After pushing the changes, go to the Actions tab in your GitHub repository.
main
branch.Verify the Self-Hosted Runner Usage:
Inside the logs of the workflow, check for the section that shows which runner was used to execute the job.
Running on runner-abc123 in the Arc cluster.
This indicates that the job is using the runner hosted in your AKS cluster.
Verify the Pod Creation in AKS:
While the workflow is running, go back to your terminal and check the arc-runners
namespace for the newly created runner pod:
kubectl get pods -n arc-runners
arc-runner-set-xxxx
).Check the Workflow Completion:
Once the workflow completes, go back to the Actions tab on GitHub and check the status of the workflow run.
This step verifies that your self-hosted runner is correctly integrated into your GitHub Actions workflows, and that the Actions Runner Controller is managing the runner pods in your AKS cluster as expected.
After the workflow completes, it’s essential to review the logs to ensure everything executed as expected. This step will guide you through checking the workflow logs in GitHub Actions and also inspecting the runner details to confirm the process is running smoothly.
Navigate to the Actions Tab:
Go to the Actions tab in your GitHub repository. This tab shows a list of all the workflows that have been triggered in your repository.
Select the Latest Workflow Run:
Review the Workflow Run Summary:
In the workflow run details, you will see a summary of the jobs, steps, and status. Each job (e.g., build
) will have a green checkmark if it succeeded, or a red X if it failed.
Examine the Job Logs:
build
) to expand the details and see logs for each step.Example of a successful log for the runner could be:
Running on runner-abc123 in the Arc cluster.
This confirms that the workflow ran on your self-hosted runner.
Verify the Runner Usage:
The logs will also confirm which runner was used to execute the job. Look for a log entry similar to the following:
Run on self-hosted runner: arc-runner-set-xyz123
This shows that the workflow ran on the self-hosted runner in your AKS cluster managed by the Actions Runner Controller.
Monitor the Runner Pod Lifecycle:
You can also verify the lifecycle of the runner pod that executed the job. In the arc-runners namespace, check for the pod that was created during the workflow:
kubectl get pods -n arc-runners
The pod associated with the workflow run should appear, and after the workflow completes successfully, the pod will likely be deleted automatically.
Inspect the Runner Pod Logs (Optional):
If you need to investigate further, you can also inspect the logs of the specific pod that was used to execute the job:
First, identify the name of the runner pod:
kubectl get pods -n arc-runners
Then, view the logs of the specific pod:
kubectl logs <pod-name> -n arc-runners
This will display the logs for the pod where the workflow ran, which can help diagnose any issues with the runner or the execution environment.
By reviewing the workflow logs and checking the runner pod details, you ensure that your self-hosted runners are being used correctly and that there are no issues with your GitHub Actions workflows.
In this step, you will learn how to monitor the job execution of your GitHub Actions workflows directly within the Azure Portal, where your AKS (Azure Kubernetes Service) cluster is running. By using the Azure Portal, you can get insights into the performance and health of your runner pods and ensure that everything is functioning as expected.
Access the Azure Portal:
View AKS Cluster Monitoring:
In the AKS cluster dashboard:
The Insights section is especially helpful because it provides a detailed view of your cluster’s performance, node status, and pod health.
Note: Ensure that you have enabled Azure Monitor for containers when setting up your AKS cluster, as this feature provides visibility into the metrics and logs for your containerized workloads.
View Container Insights:
arc-runners
namespace.
arc-runner-set-<random-id>
, where the arc-runner-set
corresponds to the self-hosted runners.Use Logs for Troubleshooting:
To monitor logs for your GitHub Actions runner pods, you can query the container logs associated with your runner pods.
Example query to view logs from the runner pods:
ContainerLog
| where ClusterName == "<your-aks-cluster-name>" and ContainerID contains "arc-runner-set"
| sort by TimeGenerated desc
Monitor Pod Status and Health:
Monitor Resource Usage:
Set Up Alerts (Optional):
By monitoring the jobs in the Azure Portal, you ensure the health of your GitHub Actions runner pods and the performance of your workflows. The Azure Monitor and Container Insights features provide powerful tools to track metrics, resource usage, and logs related to your AKS-based self-hosted runners.
While setting up GitHub Actions with self-hosted runners in AKS, you may encounter a few common issues. Here are some troubleshooting tips for resolving them:
Symptoms:
failed to get runner registration token on refresh: github api error: StatusCode 403
Solution:
repo
(Full control of private repositories)workflow
(To manage GitHub Actions workflows)read:org
(To access organizational data)Symptoms:
Solution:
kubectl get pods -n <namespace>
to verify the pod status.If the controller is running, check the logs for any errors:
kubectl logs <controller-pod-name> -n <namespace>
Symptoms:
oci://ghcr.io/actions/actions-runner
).Solution:
Symptoms:
Solution:
Verify that the runner pods in the AKS cluster are running. You can check the pods with:
kubectl get pods -n <namespace>
Symptoms:
Solution:
minReplicas
and maxReplicas
settings are appropriate for the expected workload.In this lab, you successfully set up GitHub Actions with self-hosted runners on Azure Kubernetes Service (AKS) using the Actions Runner Controller. The key steps involved:
By leveraging AKS to run GitHub Actions workflows, you can automate your CI/CD pipelines at scale, taking advantage of Kubernetes’ powerful scaling capabilities. You can now efficiently run and manage workflows on your own infrastructure while maintaining the flexibility to scale resources as needed.