Skip to content

A simple Azure kubernetes service instruction to automatically publish an image to container registry and use it for k8s deployment to host a simple nginx site

Notifications You must be signed in to change notification settings

ShresthaRajat/aks-demo-nginx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 

Repository files navigation

For Creating a AKS cluster with Automatic deployments:

Requirements:

  • A valid Azure subscription
  • kubectl installed
  • azure-cli installed

Steps:

  1. Create a resource group, acr and aks:
az group create --name test-nginx --location uksouth

az acr create --resource-group test-nginx --name shrestharajat --sku Basic

az aks create --resource-group test-nginx --name nginx-cluster --node-count 1 --enable-addons monitoring
  1. Link the ACR to AKS
az aks update -n nginx-cluster -g test-nginx --attach-acr shrestharajat
  1. Push an initial image to ACR
az acr build --image nginx/testnginx:latest --registry shrestharajat --file Dockerfile .
  1. Create and setup automatic deployment via azure portal

    • Go to cluster>automatic deployments>create cluster
    • Select a github workflow name same as the deployment name
    • Select repo and branch
    • Go to Image settings after setting repo
    • Select Dockerfile
    • Select ACR and image repository image
    • Go to Deployment details
    • Select Kubernetes manifest
    • Select the deployment yml file
    • Select default namespace (Do not create a new one)
    • Review and create
    • After a while, a pull request will be created
    • Go to your github repo and accept the pull request If you do not want to use the default namespace you will need to define a new service and ingress
  2. Enable the Github action to fetch the image by setting ACR credentials on GHA secrets

    1. On the repository start page, select the Settings tab. In the menu, select Secrets.
    2. Set the following secrets: ACR_NAME = shrestharajat ACR_LOGIN = shrestharajat ACR_PASSWORD = xxxxxxxxxxxxxxxxxxxx To get these values you can use the following commands:
# ACR_NAME
az acr list --query "[?contains(resourceGroup, 'test-nginx')].loginServer" -o table

# ACR_LOGIN
az acr credential show --name shrestharajat.azurecr.io --query "username" -o table
  
# ACR_PASSWORD
az acr credential show --name shrestharajat.azurecr.io --query "passwords[0].value" -o table

Msic commands:

# set context
az aks get-credentials --resource-group test-nginx --name nginx-cluster
kubectl config view

# Get the svc and pod details
kubectl get svc
kubectl get pods -o wide

# apply the deployments locally
kubectl apply -f ./nginx-test.yml

About

A simple Azure kubernetes service instruction to automatically publish an image to container registry and use it for k8s deployment to host a simple nginx site

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published