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 learn how to deploy a Docker container (NGINX) to an Azure Kubernetes Service (AKS) cluster using GitHub Actions with the Actions Runner Controller (ARC). The workflow will automatically run on an arc-runner-set
self-hosted runner deployed in AKS.
Duration: 20-30 minutes
Before starting this lab, ensure you have:
.github/workflows
directory. If the folder does not exist, create it.k8s-arc-runner-nginx.yml
and add the following content:name: K8s ARC Runner NGINX
on:
push:
paths:
- '.github/workflows/k8s-arc-runner-nginx.yml'
workflow_dispatch:
jobs:
run:
runs-on: arc-runner-set
steps:
# Step 1: Checkout the code to get any necessary configuration files
- name: Checkout code
uses: actions/checkout@v4.1.7
# Step 2: Set up kubectl
- name: Set up kubectl
uses: azure/setup-kubectl@v3
with:
kubectl-version: 'v1.25.0'
# Step 3: Configure kubectl to connect to AKS
- name: Configure kubectl
uses: azure/aks-set-context@v1
with:
resource-group: 'arc-lab-rg'
cluster-name: 'arc-lab-cluster'
creds: $
# Step 4: Deploy an existing Docker image (e.g., nginx) to AKS
- name: Deploy NGINX to AKS
run: |
kubectl create deployment nginx-deployment --image=nginx:latest
kubectl expose deployment nginx-deployment --port=80 --target-port=80 --type=LoadBalancer
kubectl rollout status deployment/nginx-deployment
# Step 5: Verify that the deployment was successful by checking the pods and service
- name: Verify Deployment
run: |
kubectl get pods
kubectl get services
kubectl describe deployment nginx-deployment
# Optional: Clean up the deployment after the demo
# - name: Clean up deployment
# run: |
# kubectl delete deployment nginx-deployment
# kubectl delete service nginx-deployment
AZURE_SERVICE_PRINCIPAL
: The JSON output from the Azure CLI command you ran to create the Service Principal (or manually add these fields as separate secrets).The azure/aks-set-context@v1
action will automatically configure kubectl
using the Azure Service Principal credentials and your AKS details.
Ensure you have provided the correct resource-group
and cluster-name
values in the workflow file, replacing aks-rg
and aks
with your actual Azure resource group and AKS cluster name.
kubectl create deployment
command is used to create an NGINX deployment in the AKS cluster using the latest NGINX Docker image.kubectl expose deployment
command is used to expose the NGINX deployment on port 80 as a LoadBalancer service.kubectl rollout status
command waits for the deployment to be successfully rolled out.After the deployment, the workflow will run the following commands to verify the NGINX deployment:
kubectl get pods
: To list all pods and their status.kubectl get services
: To check if the LoadBalancer service has been created successfully.kubectl describe deployment nginx-deployment
: To get detailed information about the deployment.These commands will allow you to monitor the status of the NGINX deployment.
After the demo, you can remove the NGINX deployment and associated service using the following commands in the workflow:
- name: Clean up deployment
run: |
kubectl delete deployment nginx-deployment
kubectl delete service nginx-deployment
This step is commented out by default, but you can uncomment it if you want to clean up the resources after the demo.
In this lab, you deployed an NGINX container to an Azure Kubernetes Service (AKS) cluster using GitHub Actions with the Actions Runner Controller (ARC). You:
kubectl
to interact with AKS using an Azure Service Principal.You also learned how to monitor and clean up the deployed resources in AKS.