In this unit, you’ll complete the following tasks: Create a GitHub Action to implement a deployment pipeline Increment the coupon service version in the Helm chart, Verify that the changes were deployed to the AKS cluster, Roll back a deployment
Create the deployment action
Create a GitHub Action for cloud deployment(vps promo) of the coupon service with the following steps:
- Select the Actions tab again, select the New workflow button, and select the set up a workflow yourself link.
- Replace the YAML in the editor with the following YAML:
name: eShop deploy on: push: paths: - 'deploy/k8s/helm-simple/coupon/*' branches: [ main ] jobs: deploy-to-aks: runs-on: ubuntu-latest steps: - name: Azure Kubernetes set context uses: Azure/aks-set-context@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} resource-group: 'eshop-learn-rg' cluster-name: 'eshop-learn-aks' - name: Get code from the repository uses: actions/checkout@v1 with: ref: main - name: Helm tool installer uses: Azure/setup-helm@v1 - name: Azure Login uses: Azure/[email protected] with: creds: ${{ secrets.AZURE_CREDENTIALS }} - name: Deploy run: > helm upgrade --install eshoplearn-coupon --namespace=default --set registry=${{ secrets.REGISTRY_LOGIN_SERVER }} --set imagePullPolicy=Always --set host=${{ secrets.IP_ADDRESS }} --set protocol=http './deploy/k8s/helm-simple/coupon'
The preceding YAML defines a GitHub Action that:
- Is triggered when a commit is pushed to the coupon service’s Helm chart in the
main
branch. - Has one job, named
deploy-to-aks
, that deploys new images. The job runs in anubuntu-latest
runner and has five steps:Azure Kubernetes set context
sets the AKS credentials in the runner’s .kube/config file.Get code from the repository
checks out the code from the repository.Helm tool installer
installs Helm, an open-source package manager for Kubernetes.Azure Login
logs in to Azure using the service principal credentials.Deploy
executes thehelm upgrade
command, passing the ACR instance name as theregistry
parameter. This parameter tells Helm to use your ACR instance rather than the public container registry.
- Is triggered when a commit is pushed to the coupon service’s Helm chart in the
- Replace the default workflow file name of main.yml with deploy.yml.
- Commit the deploy.yml workflow file directly to the
main
branch.
These two GitHub Action definitions are stored in the repository’s .github/workflows directory. To make changes, update the appropriate file locally and push to the main
branch. Alternatively, create a pull request (PR). If you create a PR, the Action is triggered when merging to main
.
Trigger a deployment
To trigger a deployment, you’ll increment the appVersion
in the coupon service’s Helm chart. Helm charts are used to define the service specification in a YAML template format.
- From the Code tab, edit the deploy/k8s/helm-simple/coupon/Chart.yaml file by clicking the edit icon. Update the
appVersion
property value to1.1.0
:apiVersion: v2 name: coupon # YAML omitted for brevity # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. appVersion: 1.1.0
It’s important that you update the app version in the Helm chart. This change causes the pod to be replaced when the chart is deployed to AKS with
helm upgrade
. - Commit and push this change to the
main
branch.The deployment workflow is triggered automatically. The app is deployed after a few minutes.
More Article : Best web hosting Reddit
Monitor the deployment
- Select the Actions tab in your repository to monitor the deployment’s progress.
- Select the most recent workflow run listed for the eShop deploy workflow. The commit message used in the previous step becomes the run’s name.
- Select the deploy-to-aks task:
In the preceding image, you can see details of the
deploy-to-aks
job for this particular workflow run. TheSet up job
andComplete job
steps are listed. In between those two steps are the custom steps defined within thedeploy-to-aks
job. - Select the Actions tab again. You’ll see a variation of the following screen when the deployment completes:
- Back in the command shell, run the following command to monitor the coupon service pods in your AKS cluster:
kubectl get pods --selector service=coupon --watch
In the preceding command:
- The
--selector
flag filters the list to only pods for the coupon service. For this reason, pods for other services in the cluster aren’t displayed. - The
--watch
flag instructskubectl
to watch for changes. When a change is detected, an additional table row is appended to the command shell output. The status of the existing and newly deployed pods is displayed in real time.
A variation of the following output appears:
NAME READY STATUS RESTARTS AGE coupon-5b9597995-7s4hh 1/1 Running 1 31m coupon-74fd48bbd-rqgfd 0/1 ContainerCreating 0 22s
In the preceding output, notice that a new
coupon
pod was created. While the old pod is still running and when the new pod is ready, the old one is terminated. This process makes the transition to the new version as smooth as possible. - The
- Once the new pod’s Ready status displays
1/1
, press Ctrl+C to stopkubectl
‘s watch mode. - Run the following command to check the coupon service deployment history:
helm history eshoplearn-coupon
The history shows the new coupon service version has been deployed.
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION 1 Thu Sep 10 19:19:31 2020 superseded coupon-0.1.0 1.0.0 Install complete 2 Thu Sep 10 19:51:10 2020 deployed coupon-0.1.0 1.1.0 Upgrade complete
Read more: WordPress hosting 2022 reddit
Verify the deployment
Complete the following steps to verify your change is deployed:
- Run the following command in the command shell:
cat ~/clouddrive/aspnet-learn-temp/deployment-urls.txt
- Select the Web SPA application URL to launch the app.
- Log in from the LOGIN page.
- Add your favorite products to the shopping bag by selecting the images.
- Select the shopping bag icon in the upper right, and select CHECKOUT.
- Enter the code DISC-5 in the HAVE A DISCOUNT CODE? text box for a five USD discount, and select APPLY.
- Select PLACE ORDER to complete the purchase.
- Back in the command shell, select the Centralized logging URL.
- In the Seq logs search text box, enter Applying coupon DISC-5 and press Enter.The logs are filtered to display the following entry:
Roll back the deployment
During production issues, one common mitigation is to revert a deployment to a known good deployment. Use the following command to roll back from version 1.1.0 to 1.0.0.
helm rollback eshoplearn-coupon
The deployment history confirms that everything is back to normal:
Rollback was a success! Happy Helming!
Note: In a real-life scenario, you’ll have multiple environments to which the build’s artifacts can be deployed. For example, you might have development, testing, and staging environments. The deployment workflows can be triggered by events like merging PRs. Quality or approval gates, such as a stakeholder’s PR approval, can be added to prevent unexpected deployments to production.
In this unit, you created a GitHub Action to deploy the coupon service to AKS. To test the deployment workflow, you incremented the coupon service version in its Helm chart. Upon completion of the deployment workflow run, you searched the Seq logs to confirm the discount code redemption message was present. Finally, you reverted the coupon service in AKS to version 1.0.0.
Happy deploying!