Introduction
Nowadays, all developers are moving towards cutting edge technologies like Cloud computing, Containerization, Azure Container Registry, orchestration of an application/microservices, etc. Today we will discuss the below two major processes and data points in all these technologies.
- Build a .NET Core project’s Docker image build and pulling to Azure Container Registry- ACR
- Steps for deploying an application to K8S (Kubernetes) using the KubeController command - kubectl in Azure CLI
Prerequisites
- Docker for desktop installed on a machine
- Azure CLI installed on a machine
- Azure Resource Group in Azure account
Build a Docker image
- Create any .NET core project in Visual Studio 2017/2019 with a containerization option which will create a docker file in it.
- After creating it, build a project.
- Open command a prompt and check whether KubeCLI installed proper or not by using below steps
- Window + Run
- Write cmd in Run
- Write a kubectl and press Enter - which will give a detail that whether KuberController running or not
- Now do Azure login on CLI using below command
- az login
- Now time to check to get access on Azure account, before that we have to list out all Azure account by below command
Which will give a list of subscriptions in table format. In this table, the default access value - True/False, will represent that on which subscription users have access.- az account list --output table
- This subscription can be changed by a user with the below command.
- Syntax - az account set --subscription "<NameOfSubscription>"
- E.g. - az account set --subscription DemoSubscription
- Now set the project folder on the command prompt where a project is located
- Syntax - cd <Project Folder path>
- E.g. - cd D:\DemoProject
- So, now time to build an image of project Docker file and pull it to the ACR using below command
Here in the above command developers have to take care at the time of the given path of the file. If the developer already on prompt of project folder in which "Docker" file located then used below command. Whereas Docker file is located in D:\Project folder- Syntax - az acr build --registry <ACrName From Azure> --image <imageName> --file <DockerFileLocationInProjectFolder> .
- E.g. - az acr build --registry DemoACR --image test:v1 --file .\Project\Dockerfile .
If user command prompt folder is 1-2 folder out then he/she must be reached to that folder in which Docker file is located and give above command- az acr build --registry DemoACR --image test:v1 --file .\Dockerfile .
- It's time to log in with AKS - Azure Kubernetes Service using below command
- Syntax - az aks get -credentials --name <NameOfAKS> --resource-group <NameOfResourceGroup> --admin
- E.g. - az aks get-credentials --name MyManagedCluster --resource-group MyResourceGroup --admin
- Here, in the above command it's mandatory to use --admin because it will give the user access on AKS as admin so It will help the user further to do certain operations like service deployment and publishing on Kubernetes nodes and pods.
- Now time to get a list of Nodes from Kube controller using the below command
After everything is set to deploy service to the AKS, before that, we have to create a YAML file for service deployment. Now, the question is arise what type of detail available in the YAML file. In the YAML file, we will set short of a configuration of service deployment and publishing detail. For understanding purposes, I put the YAML file example below.- kubectl get nodes ---this will list out all nodes name from all namespace
- kubectl get nodes -n <NameSpaceName> ---- this will list out all node from specific namespace
Test YAML file - please consider it for understanding purposes:
- apiVersion: v1
- kind: Service
- metadata:
- name: demo1
- namespace: demo1
- spec:
- type: NodePort
- ports:
- - port: 80
- targetPort: 80
- protocol: TCP
- name: http
- Before deployment of yaml file, we have to set that file path .
- Deployment of an application to the AKS, use this yaml file which contains configuration related to AKS.
After the creation of services, now its time to test services which will be Kubernetes service that exposes the application front end to the internet.- Syntax - kubectl apply -f <yaml file name>
- E.g. kubectl apply -f demo.yaml
- Syntax - kubectl get service <serviceNameFromYamlfile> --watch
- E.g. - kubectl get service demo1 --watch
This command will give IP of service, so the user can consume it in the browser for further use.
Join the conversation! Your thoughts help the community grow.