Achraf Ben Alaya
No Result
View All Result
  • News
  • Blog
    • blazor
    • c#
    • Cloud
      • Azure
    • docker
    • sql
    • xamarin
    • Dapr
    • Tricks, Tips and Fixes
  • Cloud
  • Motivation
  • General Tips & Fix
  • Exam Preparation
    • AZ-104
    • AZ-400
  • About
    • Resume
SUBSCRIBE
  • News
  • Blog
    • blazor
    • c#
    • Cloud
      • Azure
    • docker
    • sql
    • xamarin
    • Dapr
    • Tricks, Tips and Fixes
  • Cloud
  • Motivation
  • General Tips & Fix
  • Exam Preparation
    • AZ-104
    • AZ-400
  • About
    • Resume
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
0
Switch to Azure Container Registry from Docker Hub
0
SHARES
132
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: /$1
    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)

Related Posts

How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)
Azure

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

November 25, 2022
229
How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)
Azure

How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)

November 23, 2022
102
How to setup nginx reverse proxy for aspnet core apps with and without  Docker compose
Azure

How to setup nginx reverse proxy for aspnet core apps with and without Docker compose

November 23, 2022
153
Win free certifications at the Microsoft Build Cloud Skills Challenge | May 2022 🎁
Blog

Win free certifications at the Microsoft Build Cloud Skills Challenge | May 2022 🎁

May 28, 2022
107
Generating report for SSL Certificates for Websites with PowerShell
Azure

Generating report for SSL Certificates for Websites with PowerShell

April 10, 2022
386
Win a free certifications at the Microsoft spring skills challenge  🎁
Blog

Win a free certifications at the Microsoft spring skills challenge 🎁

March 20, 2022
381

Leave a Reply Cancel reply

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

Terraform

Certifications

Microsoft certified trainer (MCT)

Recommended

Kubernetes is deprecating Docker runtime support !

Kubernetes is deprecating Docker runtime support !

December 3, 2020
469
Animations with Lottie in Xamarin Forms

Animations with Lottie in Xamarin Forms

April 26, 2020
804
How to Claim My Free Microsoft Certification Voucher

How to Claim My Free Microsoft Certification Voucher

October 15, 2020
549
How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)

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

November 25, 2022
229
Configure postman / newman API tests in Azure DevOps

Configure postman / newman API tests in Azure DevOps

October 25, 2021
2.2k
Welcome to Azure Resource Mover service

Welcome to Azure Resource Mover service

February 2, 2021
149
Facebook Twitter LinkedIn Youtube
Switch to Azure Container Registry from Docker Hub

From Docker Hub, switch to Azure Container Registry & AKS

January 16, 2023
How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)

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

November 25, 2022
How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)

How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)

November 23, 2022

Categories

  • Apps (1)
  • Azure (39)
  • blazor (2)
  • Blog (62)
  • c# (7)
  • Cloud (37)
  • Dapr (4)
  • docker (3)
  • Games (1)
  • General Tips & Fix (1)
  • motivation (2)
  • Motivation (3)
  • News (9)
  • Resume (1)
  • sql (4)
  • Tricks, Tips and Fixes (3)
  • xamarin (5)
No Result
View All Result
  • News
  • Blog
    • blazor
    • c#
    • Cloud
      • Azure
    • docker
    • sql
    • xamarin
    • Dapr
    • Tricks, Tips and Fixes
  • Cloud
  • Motivation
  • General Tips & Fix
  • Exam Preparation
    • AZ-104
    • AZ-400
  • About
    • Resume