Achraf Ben Alaya
No Result
View All Result
  • Home
  • News
  • Blog
    • blazor
    • c#
    • Cloud
      • Azure
    • docker
    • sql
    • xamarin
    • Dapr
    • Tricks, Tips and Fixes
    • General Tips & Fix
  • AI
  • Cloud
  • Motivation
  • Courses
  • About
    • Resume
    • Privacy Policy
SUBSCRIBE
  • Home
  • News
  • Blog
    • blazor
    • c#
    • Cloud
      • Azure
    • docker
    • sql
    • xamarin
    • Dapr
    • Tricks, Tips and Fixes
    • General Tips & Fix
  • AI
  • Cloud
  • Motivation
  • Courses
  • About
    • Resume
    • Privacy Policy
No Result
View All Result
Achraf Ben Alaya
No Result
View All Result
ADVERTISEMENT
Home Blog Cloud Azure

From Docker Hub, switch to Azure Container Registry & AKS

achraf by achraf
January 16, 2023
in Azure, Blog
4 min read
1
0
SHARES
510
VIEWS
Share on FacebookShare on Twitter

We previously looked at how to configure an ingress controller for the Azure Kubernetes Service (AKS) using TLS/SSL. In this section, we’ll look at how to construct an Azure container registry using Terraform and how to utilize it in our deployment. We’ll also look at some of the benefits of an acr :

– Ability to find, pull, and push Docker images
– Integration with other Azure services
– Built-in security features
– Role-based access control
– Image signing

This article is a part of a series:

  1. Part 1 : How to setup nginx reverse proxy for aspnet core apps with and without Docker compose
  2. Part 2 :How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service
  3. Part 3 : How to configure an ingress controller using TLS/SSL for the Azure Kubernetes Service (AKS)
  4. Part 4 : switch to Azure Container Registry from Docker Hub
  5. Part 5: Using Azure DevOps, Automate Your CI/CD Pipeline and Your Deployments
  6. Part 6 : Using Github, Automate Your CI/CD Pipeline and Your Deployments
  7. Part 7 : Possible methods to reduce your costs

    Part 1 : Creating Azure container registry (ACR)

    The first step is to set up the Azure container registry and ensure that it is connected to our Kubernetes cluster.

    Terrafrom Block to create the acr :

    resource "azurerm_container_registry" "acr001" {
      name                = "containerRegistryachraf"
      resource_group_name = azurerm_resource_group.rg.name
      location            = azurerm_resource_group.rg.location
      sku                 = "Standard"
    }
    
    
    resource "azurerm_role_assignment" "roleforaks" {
      principal_id                     = azurerm_kubernetes_cluster.cluster.kubelet_identity[0].object_id
      role_definition_name             = "AcrPull"
      scope                            = azurerm_container_registry.acr001.id
      skip_service_principal_aad_check = true
    }

    Now that we have added this block to our infrastructure, acr will be ready to use, but first we must deploy an application to our repository. To do this, we will take the same dotnet application and simply add the word “acr” to the index page.

    Part 2 : Deploying to ACR

    Install Docker first, then create a fresh copy of our application to test out the Azure Container Registry.

    To access your container registry, use the following command:

    docker login containerregistryname.azurecr.io.

    Next, let’s tag and push our image:

    docker tag hello-world containerregistryname.azurecr.io/hello-world 
    docker push containerregistryname.azurecr.io/hello-world

    once we deployed our application it will look like the below image inside ACR :

    Part 3: Create our deployment and updating our ingress

    In this part, we are creating a new deployment as we are adding a new application  :

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: backend-restapp-acr
      namespace: ingress 
      labels:
        app: backend-restapp-acr
        tier: backend 
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: backend-restapp-acr
      template:
        metadata:
          labels:
            app: backend-restapp-acr
            tier: backend 
        spec: 
          containers:
            - name: backend-restapp-acr
              image: containerregistryachraf.azurecr.io/hello-world:latest
              ports:
                - containerPort: 5000        
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: my-backend-serviceacr ## VERY VERY IMPORTANT - NGINX PROXYPASS needs this name
      labels:
        app: backend-restapp-acr
        tier: backend   
    spec:
      selector:
        app: backend-restapp-acr
      ports:
        - name: http
          port: 5000 # ClusterIP Service Port
          targetPort: 5000 # Container Port
      type: ClusterIP    
    

    using the following commands, you can deploy our application:

    kubectl apply -f 01-backend-acr-deployment.yml

    Great , now if we try to check our services using :

    kubectl get services --namespace ingress

    we will get a new service in our list :
    Also , if we check our deployements :

    kubectl get deployments --namespace ingress

    Now let’s update our ingress with our new app :

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: webapp-ingress
      namespace: ingress
      annotations:
        nginx.ingress.kubernetes.io/ssl-redirect: "false"
        nginx.ingress.kubernetes.io/use-regex: "true"
        nginx.ingress.kubernetes.io/rewrite-target: /\
    spec:
      ingressClassName: nginx
      rules:
      - http:
          paths:
          - backend:
              service:
                name: my-backend-service
                port:
                  number: 5000
            path: /
            pathType: Prefix
          - backend:
              service:
                name: my-backend-serviceacr
                port:
                  number: 5000
            path: /acr(/|$)(.*)
            pathType: Prefix  
          - backend:
              service:
                name: my-nginx-service-01
                port:
                  number: 80
            path: /webapp1(/|$)(.*)
            pathType: Prefix        
          - backend:
              service:
                name: my-nginx-service-02
                port:
                  number: 80
            path: /webapp2(/|$)(.*)
            pathType: Prefix  
          - backend:
              service:
                name: my-nginx-service-03
                port:
                  number: 80
            path: /webapp3(/|$)(.*)
            pathType: Prefix                          
      - host: yourdomaine.com # change the IP address here
        http:
          paths:
          - backend:
              service:
                name: my-backend-service
                port: 
                  number: 5000
            path: /
            pathType: Prefix
          - backend:
              service:
                name: my-backend-serviceacr
                port: 
                  number: 5000
            path: /acr
            pathType: Prefix    
          - backend:
              service:
                name: my-nginx-service-01
                port: 
                  number: 80
            path: /webapp1
            pathType: Prefix        
          - backend:
              service:
                name: my-nginx-service-02
                port: 
                  number: 80
            path: /webapp2
            pathType: Prefix     
          - backend:
              service:
                name: my-nginx-service-03
                port: 
                  number: 80
            path: /webapp3
            pathType: Prefix

    Let’s deploy and see the results :

    kubectl apply -f app-ingress.yml

    Now if we visit the url of our ingress using the /acr prefix that we have created we should find the new deployment that we have added :
    Hope this was helpful ^^

ShareTweet
Previous Post

How to configure an ingress controller using TLS/SSL for the Azure Kubernetes Service (AKS)

Next Post

Configuring Self-hosted Agent In Azure DevOps Pipeline

Related Posts

AI

Model Context Protocol (MCP): The Future of AI Integration

April 21, 2025
110
Azure

Step-by-Step Guide: Azure Front Door + Storage Account Static Website + Custom Domain with Terraform

March 11, 2025
231
Network Security & Route Tables – Checking NSGs, route tables, and service endpoints for a targeted VNET or Subnet
Azure

Network Security & Route Tables – Checking NSGs, route tables, and service endpoints for a targeted VNET or Subnet

February 3, 2025
137
Understanding Generative AI and RAG Benefits
AI

Understanding Generative AI and RAG Benefits

January 12, 2025
96
Azure Communication Services Email Sending Simplified: From Setup to Execution and Monitoring
Azure

Azure Communication Services Email Sending Simplified: From Setup to Execution and Monitoring

December 8, 2024
1.6k
PowerShell Automation for Azure Networks: Detailed VNET and Subnet Analysis
Azure

PowerShell Automation for Azure Networks: Detailed VNET and Subnet Analysis

November 2, 2024
502
Next Post
Configuring Self-hosted Agent In Azure DevOps Pipeline

Configuring Self-hosted Agent In Azure DevOps Pipeline

Comments 1

  1. Pingback: Reflecting on a Year of Growth: 2023 in Review – achraf ben alaya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Terraform

Certifications

Microsoft certified trainer (MCT)

Recommended

Recover a deleted storage account azure

Recover a deleted storage account azure

December 14, 2020
1.1k
The easiest way to deploy a website to Azure with Azure App Service

The easiest way to deploy a website to Azure with Azure App Service

April 21, 2020
683
Migrate and modernize your applications on Azure

Migrate and modernize your applications on Azure

March 26, 2021
563

From Docker Hub, switch to Azure Container Registry & AKS

January 16, 2023
510
Finally Azure Static Web Apps no more in Preview!

Finally Azure Static Web Apps no more in Preview!

May 15, 2021
1.1k
My Trip to Turkey

My Trip to Turkey

February 5, 2022
347
Facebook Twitter LinkedIn Youtube

Model Context Protocol (MCP): The Future of AI Integration

April 21, 2025

Step-by-Step Guide: Azure Front Door + Storage Account Static Website + Custom Domain with Terraform

March 11, 2025
Network Security & Route Tables – Checking NSGs, route tables, and service endpoints for a targeted VNET or Subnet

Network Security & Route Tables – Checking NSGs, route tables, and service endpoints for a targeted VNET or Subnet

February 3, 2025

Categories

  • AI (2)
  • Apps (1)
  • Azure (63)
  • blazor (2)
  • Blog (91)
  • c# (7)
  • Cloud (65)
  • Courses (3)
  • Dapr (4)
  • docker (4)
  • Games (1)
  • General Tips & Fix (1)
  • Home (1)
  • Kubernetes Service (AKS) (1)
  • motivation (2)
  • Motivation (3)
  • News (9)
  • Resume (1)
  • sql (4)
  • Terrafrom (1)
  • Tricks, Tips and Fixes (4)
  • xamarin (5)
No Result
View All Result
  • Home
  • News
  • Blog
    • blazor
    • c#
    • Cloud
      • Azure
    • docker
    • sql
    • xamarin
    • Dapr
    • Tricks, Tips and Fixes
    • General Tips & Fix
  • AI
  • Cloud
  • Motivation
  • Courses
  • About
    • Resume
    • Privacy Policy