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:
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.