Welcome to Day 1 of Week 3
of #CloudNativeNewYear!
The theme for this week is Bringing Your Application to Kubernetes. Last we talked about Kubernetes Fundamentals. Today we'll explore getting an existing application running in Kubernetes with a full pipeline in GitHub Actions.
Watch the recorded demo and conversation about this week's topics.
We were live on YouTube walking through today's (and the rest of this week's) demos. Join us Friday, February 10th and bring your questions!
What We'll Coverโ
- Our Application
- Adding Some Infrastructure as Code
- Building and Publishing a Container Image
- Deploying to Kubernetes
- Summary
- Resources
Our Applicationโ
This week we'll be taking an exisiting application - something similar to a typical line of business application - and setting it up to run in Kubernetes. Over the course of the week, we'll address different concerns. Today we'll focus on updating our CI/CD process to handle standing up (or validating that we have) an Azure Kubernetes Service (AKS) environment, building and publishing container images for our web site and API server, and getting those services running in Kubernetes.
The application we'll be starting with is eShopOnWeb. This application has a web site and API which are backed by a SQL Server instance. It's built in .NET 7, so it's cross-platform.
For the enterprising among you, you may notice that there are a number of different eShopOn* variants on GitHub, including eShopOnContainers. We aren't using that example as it's more of an end state than a starting place. Afterwards, feel free to check out that example as what this solution could look like as a series of microservices.
Adding Some Infrastructure as Codeโ
Just like last week, we need to stand up an AKS environment. This week, however, rather than running commands in our own shell, we'll set up GitHub Actions to do that for us.
There is a LOT of plumbing in this section, but once it's set up, it'll make our lives a lot easier. This section ensures that we have an environment to deploy our application into configured the way we want. We can easily extend this to accomodate multiple environments or add additional microservices with minimal new effort.
Federated Identityโ
Setting up a federated identity will allow us a more securable and auditable way of accessing Azure from GitHub Actions. For more about setting up a federated identity, Microsoft Learn has the details on connecting GitHub Actions to Azure.
Here, we'll just walk through the setup of the identity and configure GitHub to use that idenity to deploy our AKS environment and interact with our Azure Container Registry.
The examples will use PowerShell, but a Bash version of the setup commands is available in the week3/day1 branch.
Prerequisitesโ
To follow along, you'll need:
- a GitHub account
- an Azure Subscription
- the Azure CLI
- and the Git CLI.
You'll need to fork the source repository under your GitHub user or organization where you can manage secrets and GitHub Actions.
It would be helpful to have the GitHub CLI, but it's not required.
Set Up Some Defaultsโ
You will need to update one or more of the variables (your user or organization, what branch you want to work off of, and possibly the Azure AD application name if there is a conflict).
# Replace the gitHubOrganizationName value
# with the user or organization you forked
# the repository under.
$githubOrganizationName = 'Azure-Samples'
$githubRepositoryName = 'eShopOnAKS'
$branchName = 'week3/day1'
$applicationName = 'cnny-week3-day1'
Create an Azure AD Applicationโ
Next, we need to create an Azure AD application.
# Create an Azure AD application
$aksDeploymentApplication = New-AzADApplication -DisplayName $applicationName
Set Up Federation for that Azure AD Applicationโ
And configure that application to allow federated credential requests from our GitHub repository for a particular branch.
# Create a federated identity credential for the application
New-AzADAppFederatedCredential `
-Name $applicationName `
-ApplicationObjectId $aksDeploymentApplication.Id `
-Issuer 'https://token.actions.githubusercontent.com' `
-Audience 'api://AzureADTokenExchange' `
-Subject "repo:$($githubOrganizationName)/$($githubRepositoryName):ref:refs/heads/$branchName"