Kubernetes & GitHub: Effortless Deployment with GitHub Actions
Published May 10 2023 09:51 AM 5,858 Views

Did you know that containerised applications are revolutionising how software is developed and deployed? With the rise of technologies like Kubernetes and GitHub Actions, developers now have powerful tools that automate the deployment, scaling, and management of applications, making development faster, more reliable and more efficient.  


Traditional software development processes can be time-consuming, error-prone, and resource-intensive, with challenges such as inconsistent deployment configurations, manual errors, and complex coordination between development and operations teams. This can result in delays, downtime, and increased costs, impacting the overall efficiency and reliability of software development.


Let’s dive in and explore how Kubernetes and GitHub Actions are changing the game for software development! 


Kubernetes provides a highly scalable and resilient framework for managing containerized applications, allowing developers to define how their applications should run, scale, and recover from failures. It abstracts the underlying infrastructure, allowing developers to deploy and manage applications consistently across various cloud providers, data centres, or on-premises environments. Kubernetes provides features such as automatic scaling, rolling updates, load balancing, and self-healing, making it a popular choice for deploying and managing modern cloud-native applications.


GitHub Actions, on the other hand, is a powerful, flexible, and automated workflow system provided by GitHub, a popular web-based hosting service for version control using Git. GitHub Actions allows developers to define custom workflows that automate various tasks, such as building, testing, and deploying applications directly from their GitHub repositories. 


GitHub Actions provides a wide range of pre-built actions and integrations with popular tools and services, making it easy to create and customize workflows for different development workflows. It also supports event-based triggers, allowing developers to define workflows that automatically run when specific events, such as a push to a repository or a pull request, occur. This enables continuous integration and continuous deployment (CI/CD) pipelines, making it seamless to automate the building, testing, and deployment of applications as part of the development workflow. 


When combined, Kubernetes and GitHub Actions provide a powerful and streamlined approach to building, testing, and deploying containerized applications in a scalable, automated, and consistent manner. Developers can leverage Kubernetes to manage the deployment and scaling of containers, while GitHub Actions can be used to automate the workflows for building, testing, and deploying containers to Kubernetes clusters, creating a seamless end-to-end CI/CD pipeline for modern software development. 


Automating cluster creation and deployment in Kubernetes can provide several benefits for modern software development practices: 

  • Consistency: Automation ensures that the creation and deployment of Kubernetes clusters are performed consistently across different environments eliminating  manual errors and reduces the risk of misconfigurations, ensuring clusters are set up consistently with the desired configuration, reducing the risk of inconsistencies that could lead to production issues. 
  • Speed and Efficiency: Automation allows for rapid and efficient creation and deployment of Kubernetes clusters 
  • Scalability: Kubernetes clusters can be scaled up or down based on demand, and automation allows for seamless scaling of clusters to accommodate varying workloads. Automation enables the dynamic provisioning of resources, such as nodes and pods, based on predefined rules or triggers, allowing for efficient resource utilization and improved scalability. 
  • Repeatability and Reproducibility: Automation enables the creation of repeatable and reproducible processes for cluster creation and deployment. Cluster configurations can be version-controlled, allowing for easy rollback or replication of clusters to different environments. 
  • Reliability and Resilience: Automation helps ensure that Kubernetes clusters are deployed in a reliable and resilient manner. Automated processes can include monitoring, error handling, and recovery mechanisms, reducing the risk of human error and improving the resilience of clusters in the face of failures or incidents. 
  • DevOps Integration: Automation of cluster creation and deployment can be integrated into a DevOps workflow, allowing for seamless integration with other development and operations processes. This enables organizations to establish a consistent and automated CI/CD pipeline, improving the overall software development lifecycle and accelerating time to market. 
  • Cost-effectiveness: Automated cluster creation and deployment can help optimize resource utilization, allowing for efficient allocation and deallocation of resources based on demand. This can result in cost savings by eliminating over-provisioning or under-utilization of resources, improving the cost-effectiveness of managing Kubernetes clusters. 

This blog post describes how we can use the AKS (Azure Kubernetes Service) Construction Helper to create a cluster and ensure additional clusters can automatically be created by running the same workflow using GitHub Actions. 


To be able to follow this guide, you will need access to the following resources: 

For this example, we will create a simple voting app which will count the number of votes for each option. In this case it will be dogs vs. cats! 


Creating the Environment 

Firstly, we have to create the environment and to do this, navigate to the voting app GitHub repo and fork the repository. This will create a copy of the repository in your own account.  




Once this has been forked, you can check to see if the repository is in your account and navigate to that repository.  

Make your way to the AKS Construction Helper to begin creating the cluster and creating the infrastructure. This resource makes it much easier to create a cluster than having to go into AKS and the azure portal and running things manually. You can use this easily by just ticking the boxes which are the most relevant to you.  




Select the Simplest bare-bones cluster and a simple cluster with no additional access limitations.  




Scroll down to fine tune the cluster with specific requirements we need. In the deploy section choose a cluster name and resource group. This can be anything that is memorable and unique to your project. Select the location that is closest to you. For the voting app we need to setup an Azure Container Registry (ACR) which is a pre-requisite on the vote app material learning path. 




Go to the Addon Details tap to configure the ACR which you have just selected in the previous step. Select Yes, setup Azure Container Registry ‘’Basic’’ & authorise AKS to pull images.  




Change the networking details and select custom networking on the networking details tab.  




Select create NSGs for each subnet on the same tab. 


Go back to the deploy tab and as we are using GitHub Actions for this, go to the GitHub Actions tab. Copy and paste the URL to your GitHub repository that we forked in the beginning and paste it in the text box. For the repo branch, make sure this matches the name of the branch in your repo. 






All those selections you just made are now set in the script below. The code will call the AKS construction reusable workflow and using workflow dispatch means it is manually triggered. This includes the name of the resource group, resource name and the template params relate to those changes we made. Copy and paste this code in the Azure Portal Cloud Shell. 




Scroll down and you can see some more code which will call the AKS Construction reusable workflow. Copy the code and navigate to your GitHub repo. Create a new workflow by clicking add file and create new file. Label it .github/workflows. Paste the code in a new workflow and label it newcluster.yml   






To create multiple clusters without having to go back to the AKS Construction Helper every time, you can add additional lines of code. Lines 7-15 allow you to enter the name of a resource group and cluster each time you run the workflow. You can also have a default name for version control. Make sure to also change the reg, resourceName and templateParams to have inputs so you can continuously create clusters.  


As you created your own ACR in the above steps, you now need to update the code to reflect your ACR for the azure-vote-front image. Navigate to the Azure portal. Find your resource group and click container registry. Here you can find the name of your container registry. Copy this and paste it in the section as shown.  




Creating the Secrets 

GitHub secrets are encrypted variables that you can create in a repo to store sensitive information such as access token and azure credentials. You will have to create these for this example.


You need to create a service principal to access your resource group. Fill in the gaps with your details and copy and paste this command into the Azure portal CLI: 


az ad sp create-for-rbac --name "<INSERT GLOBALLY UNIQUE NAME>" --role contributor --scope /subscriptions/<INSERT SUBSCRIPTION ID>/resourceGroups/<INSERT RESOURCE GROUP NAME> --sdk-auth 


  • Replace <INSERT GLOBALLY UNIQUE NAME> with any name that is unique to you  
  • Replace <INSERT SUBSCRIPTION ID> with the subscription ID of your Azure account  
  • Replace <INSERT RESOURCE GROUP NAME> with the name of the resource group where your ACR is located 

Follow the steps on the Vote App Material to successfully create and assign the secrets. 


Deploying the App 

Create a new workflow in the .github/workflows folder and appropriately name the file. Something like votingappdeploy.yml will work. Remember to end the name with .yml 


Copy and paste the actions file from the Vote App Material into the new workflow you created. 







Save the workflow and it's now time to run the workflows! Go to Actions and run each workflow by clicking run workflow.  


You have now successfully created the infrastructure and deployed an app into the environment. Now it's time to check the front end of the application.


To access the external IP where you can see the front end of your application, navigate to the Azure portal > your resource group > your cluster > services and ingresses on the left navigation and the external IP given to your azure-vote-front is where you can see your app. Click on the IP address to open a new tab or copy and paste it in the address bar.  



 Your cats vs. dogs voting app should look like this.  





After completing all the steps, you should now be comfortable with GitHub Actions, using the AKS Construction Helper and creating secrets. You can also now effortlessly create multiple clusters using the AKS Construction helper. However, if you do find yourself experiencing errors along the way, there are a few adjustments you can make to the code which you can find in the troubleshooting section of this blog! 



You may come across a few errors if you are using some of these services for the first time. Here are a few ways you can resolve the errors if they occur.  

  • If you have not made use of your subscription much, then you will need to run the following command in the Azure CLI to access your resources: 
    • az provider register --namespace Microsoft.OperationsManagement  
  • If you are getting errors associated with authenticating a login to AKS, try this: 
  • If you are having issues with role assignments, you may need to update this in the Azure portal. 
    • Navigate to the portal and find your cluster  
    • Select role assignments > add role assignment > Azure Kubernetes RBAC Cluster Admin > select members > type your Microsoft alias > review and assign 
    • Navigate back to GitHub and re-run your workflow 
Version history
Last update:
‎May 10 2023 09:51 AM
Updated by: