Skip to main content

Posts

Azure KV and FuncApp

1. Create a FunctionApp and add a system assigned identity to it. Create on the search bar and select func app. The go to the identity section and turn on the status button. This creates an identity and registers the func app in azure ad. Now we need to grant this identity permissions to read from KV 2. Create a Keyvault and create a secret. I have created 2 (Name = Anish and surname = Aravind) 3. Give the function app identity access to read the secrets from Keyvault 4. Select the certificates drop down and select Get and List. Since we need to read the secrets.  5. Save the changes 6. Go to the Configuration section in the function app and add the following values. Cliick on create new application setting. The setting is a key value pair.  I have created 2 because I need to read 2 secrets from KV. The application setting key will be the key for the secret in KV. Name : @Microsoft.KeyVault(SecretUri= secretidentifierfor the secret ) To  get the secret identifier for...

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 ins...

Docker

 1.  docker run --rm -it microsoft/dotnet:2-runtime  Run linux container cmd. we get a command prompt for the container. 2. share a folder from host to container-- windows to linux docker run -it --rm -v E:\Docker\code\ACRTOAKS:/abcd microsoft/dotnet:2-runtime from E:\Docker\code\ACRTOAKS to /abcd inside the container 3. Get IP Address of the container docker inspect containername docker ps --list all running containers

AZ-204 KeyVault

Rather than storing credentials in the application, we can use Azure keyvault to store user secrets. We can also use it to store  1. secret , application that stores the secrets in files can be at risk if someone gets a peek at the source code. KV happens at runtime. 2. keys (for encryption/decryption)  3. certificates (SSL certificates) 4. Storage accounts have access keys and KV can be used to manage them. 5. Azure VM disks encryption. We can encrypt the data stored on VMS using azure disk encryption. 6. In AKS  DATA PROTECTION  An Azure app service app can use certificates stored in KV to encrypt the data (in transit) or it can be used to encrypt the data stored in a database (in rest)  Access control should follow the principle of least privilege. Add new Resource => Keyvault Create a Keyvault Using Keyvault when using azure AD NUGETS:  Azure.Identity and Azure.Security.KeyVault.Secrets _______________________________________________________________...

AZ-204 Azure Redis Cache

Why should we cache? 1. Because we dont want to hit the database everytime. 2. Caches store data in memory, so its faster to query them. 3. Caches use a key value pair to store data rather than any complex data structure , So the time complexity is less. 4. Also it improves availability , as if the backend in unavailable we can still get the data from the cache. Not all of it but the most frequently used ones. So its important to make sure that we are caching the right data. Azure Cache 1. Geo Replication: The main copy remains writable whereas the other copies are maintained as readable. So not only is the data available in a new region but also available in case the primary cache is down. In such a scenario the secondary instance becomes writable. DATA Types NUGET Microsoft.Extensions.Caching.StackExchangeRedis -- allows more data types and operations  services.AddStackExchangeRedisCache(op => {                 op.Configuration = "Conn...

BLOB STORAGE

Blob stands for Binary large object. we can store files , text , videos etc. Once we create a storage account, we can create containers ex: image where we can place the image files. The image img1 can be accessed by using the above url. The storage account name has to be uniques because in order to access the blobs the we need to a unique url.. that is http[s]:// storagename .blob.core.windows,net Virtual Directories instead of hierarchical structure Blob storage doesnt support a heirarchical structure, so we can create nested folders to group our files. but we can name the files based on whatever way we want to group the files. Ex: 2020/personal/images/img.jpg In short , there are no folders. It creates virtual directories and we can access the blobs using the url based on the path. TYPES 1. Block Blobs: we cant append data to existing ones, but we can replace the old file with a new one. Ex: image , video etc. So if we store the log file as a block blob the...

Refresh Cache using Redis and BackgroundService .net 5

Install Nuget package   Microsoft. Extensions. Caching. StackExchangeRedis Creating a cache attribute [Cached(time: 10)]  public async Task<IActionResult> GetAll() => Ok(await SalesdbContext.Employees.ToListAsync()); We create an attribute called cached that accepts the expiry time for the cached data. Once the expiry time is over the response returned will be null and we will fetch the data from the database and update the cahce. [AttributeUsage(AttributeTargets.Method)]     public class CachedAttribute : Attribute, IAsyncActionFilter     {         public int Time { get; set; }         public CachedAttribute(int time)         {             Time = time;         }         public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)       ...