Skip to main content

Az-204 Docker to Container registry to AKS

 1. https://github.com/Azure-Samples/azure-voting-app-redis.git -- pull this code from github

 2.  it has a docker-compose file . So run docker-compose up -d

 3. Create a container registry. 

4. Tag the docker image to the container registry.

docker tag hello-world demoacr5416.azurecr.io/hello-world-demo:v1

hello-world: name of the image

demoacr5416.azurecr.io -- name of the ACR

hello-world-demo:v1 -- what we want to call it inside ACR


5. push  

https://pascalnaber.wordpress.com/2020/01/21/access-keyvault-from-azure-kubernetes-service-aks-with-an-asp-net-core-application-using-a-managed-identity/

VISUAL STUDIO APP TO DOCKER

1. Publish the app to a folder (publish).


FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
EXPOSE 80
EXPOSE 443
COPY ./publish .
ENTRYPOINT ["dotnet""ACRTOAKS.dll"]

copy the publish file into a folder called publish and paste the docker file. Then copy everything inside the docker container.

docker build -t myacrtoaks .

build the publish folder to an image. The . at the end is the location for the docker file. -t is the name of the image we build 

docker run -d -p 8080:80 --name myacrtoaks myacrtoaks //name of the image

where --name is the name of the container



PUSH TO ACR


















Create an ACR and in Access keys enable admin user.

1. Open CMD and az login
2. Login to Acr
az acr login --name=demoacranish.azurecr.io --username=demoacranish --password=xxxx

3. tag the image
docker tag myacrtoaks demoacranish.azurecr.io/demoacrtoaks:v2

4. Push to acr

docker push demoacranish.azurecr.io/demoacrtoaks:v2

5.  List everything
az acr repository list --name=demoacranish -o=table


6. az acr repository show-tags

7. Delete
az acr repository delete --name=demoacranish -t demoacrtoaks:v2

MULTIPROJECT FILE

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["AppServiceDemo/AppServiceDemo.csproj", "AppServiceDemo/"]
COPY ["BAL/*.csproj", "BAL/"]
COPY ["DAL/*.csproj", "DAL/"]
RUN dotnet restore "AppServiceDemo/AppServiceDemo.csproj"
COPY . .
WORKDIR "/src/AppServiceDemo"
RUN dotnet build "AppServiceDemo.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "AppServiceDemo.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "AppServiceDemo.dll"]


TO AKS

kubectl is like the azure cli. Used to work with kubernetes.

kubectl version --short  

az account set --subscription name or ID  -- select subscription

az group create --name=demorsaks -l centralus  -- create RG

az acr create --name=acrtoaksdemo -g demorsaks --sku=standard --create ACR

az acr login --name=acrtoaksdemo -- login to ACR

docker tag appservicedemo:v2 acrtoaksdemo.azurecr.io/appservicetoakscemo:v1 -- TAG with acr server name


Connect Kubectl with AKS

where kubernetesdemo is the name of an AKS cluster




Check if kubectl has connected

Kubectl get nodes  --this will return the number of nodes running in aks.


-- Run the yaml file


-- Get the running POD info

Kubectl get service  -- Get the services



Comments

Popular posts from this blog

Az-500 NSG and ASG

Application security groups Application security groups enable you to configure network security as a natural extension of an application's structure, allowing you to group virtual machines and define network security policies based on those groups. You can reuse your security policy at scale without manual maintenance of explicit IP addresses. The platform handles the complexity of explicit IP addresses and multiple rule sets, allowing you to focus on your business logic. To better understand application security groups, consider the following example: In the previous picture,  NIC1  and  NIC2  are members of the  AsgWeb  application security group.  NIC3  is a member of the  AsgLogic  application security group.  NIC4  is a member of the  AsgDb  application security group. Though each network interface in this example is a member of only one network security group, a network interface can be a member of multiple app...

App Role assignment to service principal --

 Using Ms Graph Rest API's Permissions One of the following permissions is required to call this API. To learn more, including how to choose permissions, see  Permissions . Permission type Permissions (from least to most privileged) Delegated (work or school account) AppRoleAssignment.ReadWrite.All and Application.Read.All, AppRoleAssignment.ReadWrite.All and Directory.Read.All, Application.ReadWrite.All, Directory.ReadWrite.All Delegated (personal Microsoft account) Not supported. Application AppRoleAssignment.ReadWrite.All and Application.Read.All, AppRoleAssignment.ReadWrite.All and Directory.Read.All, Application.ReadWrite.All, Directory.ReadWrite.All Create 2 app registrations. App role owner will contain the app role that will be assigned to a service principal. The  reader role in approleowner will be added to the approlesubscriber Setup postman to use the Oauth auth flow to get a token for MS Graph. ClientId:   Application (client) ID for approlesubscrib...

Get user groups

 string[] scopes = new string[] { "https://graph.microsoft.com/.default" };             string clientId = "";             string tenantId = "";             string secret = "";                        var options = new TokenCredentialOptions             {                 AuthorityHost = AzureAuthorityHosts.AzurePublicCloud             };             // https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential             try             {                 var clientSecretCredential = new ClientSecretCredential(                        ...