Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Azure] Create or Provision Cache Azure for redis

Posted on May 17, 2025May 19, 2025 By nim No Comments on [Azure] Create or Provision Cache Azure for redis

Bạn đang chưa biết gì về Cache Azure hay đọc ngay post này.

Đầu tiên để tạo redis trên azure bạn cần register “Microsoft.Cache”

╷
│ Error: creating Redi (Subscription: "7f8e5acb-a937-4163-80b1-f874c3a4d62c"
│ Resource Group Name: "nimtechnology"
│ Redis Name: "redis-elearning"): performing Create: unexpected status 409 (409 Conflict) with error: MissingSubscriptionRegistration: The subscription is not registered to use namespace 'Microsoft.Cache'. See https://aka.ms/rps-not-found for how to register subscriptions.
│ 
│   with module.redis.azurerm_redis_cache.this,
│   on .terraform/modules/redis/main.rediscache.tf line 4, in resource "azurerm_redis_cache" "this":
│    4: resource "azurerm_redis_cache" "this" {
│ 

Giờ bắt đầu tạo redis trên azure:

Bạn thực hiện Chọn subscription, Resource Group, Region, rồi anh em khai báo tên redis cluster của anh em.

Ở đây mình cần giải thích thêm: Cache SKU và cache size:

Cache SKU đề cập đến các loại cấu hình (Stock Keeping Unit) khác nhau của bộ nhớ đệm (cache) được cung cấp bởi Azure. SKU của Azure Cache giúp xác định tính năng, hiệu suất, và giá của một cache instance.
Chúng ta cũng có nhiều SKU:

BasicStandardPremiumEnterpriseEnterprise Flash

Bạn có thể tìm lun ở link này:
https://azure.microsoft.com/en-us/pricing/details/cache/

Tiếp theo cache size trong Azure Cache đề cập đến dung lượng bộ nhớ đệm mà bạn muốn cấp phát cho một cache instance trong Azure. Kích thước này quyết định lượng dữ liệu mà bộ nhớ đệm có thể lưu trữ tại một thời điểm, và nó ảnh hưởng trực tiếp đến hiệu suất và khả năng mở rộng của hệ thống cache

Ví dụ trong SKU Basic sẽ có các loại cache size từ C0 đến C6

Và tương tự các SKU khác cũng có các cấu hình khác nhau:
https://azure.microsoft.com/en-us/pricing/details/cache/

Phần network chúng ta sẽ chọn dạng Private Endpoint hay là Public Endpoint.
Phần này mình tạm thời chọn Public Endpoint.

Phần này thì các bọn chọn version 6 đang là mới nhất.
Chọn access key authentication để tý đăng nhập vào redis chúng ta sẽ có key kiểu như username và password.

Phần cuối cùng thì nhấn review và create thôi.

Phải nói thêm nếu bạn SKU là Premium thì phần advance bạn có nhiều option hơn đê custom:

Để access và Redis cluster thì bạn vào Setting > Properties

Mình có curl từ máy mình thì con redis này public internet thật

Password của redis thì bạn lấy ở setting > Authentication

Để connect test vào Cache Azure thì bạn sử dụng:
https://nimtechnology.com/2024/09/04/redisinsight-developer-gui-for-redis-by-redis/

[RedisInsight] Developer GUI for Redis, by Redis

Nếu bạn có enable ssl trong connection của redis.

Nếu bạn chán click thì có thể sử dụng thẳng terraform.

module "redis" {
  source  = "Azure/avm-res-cache-redis/azurerm"
  version = "0.4.0"
  name    = "redis-elearning"
  resource_group_name =  var.resource_group_name
  location = var.resource_group_location
  sku_name            = "Premium"
  capacity = 3
  redis_version = "6.0"
  replicas_per_master = 1
  shard_count = 1
  access_keys_authentication_enabled = true
  redis_configuration = {
    enable_authentication = true # If false, use Entra ID for authentication
  }
  managed_identities = {
    system_assigned = true
  }
}

Apply Private Endpoint for Azure cache for redis.

resource "azurerm_private_dns_zone" "this" {
  name                = "privatelink.redis.cache.windows.net"
  resource_group_name = var.resource_group_name
}

resource "azurerm_private_dns_zone_virtual_network_link" "this" {
  name                  = "vnet-link"
  private_dns_zone_name = azurerm_private_dns_zone.this.name
  resource_group_name   = var.resource_group_name
  virtual_network_id    = module.vnet.vnet_id
}


module "redis" {
  source  = "Azure/avm-res-cache-redis/azurerm"
  version = "0.4.0"
  name    = "redis-elearning"
  resource_group_name =  var.resource_group_name
  location = var.resource_group_location
  sku_name            = "Premium"
  capacity = 3
  redis_version = "6.0"
  replicas_per_master = 1
  shard_count = 1
  access_keys_authentication_enabled = true
  redis_configuration = {
    enable_authentication = true # If false, use Entra ID for authentication
  }
  private_endpoints = {
    endpoint1 = {
      subnet_resource_id            = module.vnet.subnet_ids[0]
      private_dns_zone_group_name   = "private-dns-zone-group"
      private_dns_zone_resource_ids = [azurerm_private_dns_zone.this.id]
    }
  }
  managed_identities = {
    system_assigned = true
  }
}

Bạn sẽ để ý chúng ta sẽ có phần setup private endpoints ở đây:

resource "azurerm_private_dns_zone" "this" {
  name                = "privatelink.redis.cache.windows.net"
  resource_group_name = var.resource_group_name
}

Terraform tạo một Khu vực DNS Riêng tư trong Azure có tên là privatelink.redis.cache.windows.net trong nhóm tài nguyên được chỉ định.
Mục đích: DNS zone này sẽ được sử dụng để phân giải tên miền riêng tư trong mạng ảo (VNet) của bạn.

ở phần này có 1 lưu ý là không phải bạn thích khai báo domain nào cho private dns zone cũng được nó sẽ cần tuân thủ như sau:

Bước 1 bạn cần vào:
https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-dns

Bước 2 bạn cần biết bạn sử dụng service nào của azure
Ở bài này chúng ta đang tạo: Azure Cache for Redis thì cần sử dụng domain là: privatelink.redis.cache.windows.net

Link DNS Zone to Virtual Network

resource "azurerm_private_dns_zone_virtual_network_link" "this" {
  name                  = "vnet-link"
  private_dns_zone_name = azurerm_private_dns_zone.this.name
  resource_group_name   = var.resource_group_name
  virtual_network_id    = module.vnet.vnet_id
}
  • What happens: Terraform tạo một link between the Private DNS Zone và VNet của bạn.
  • Purpose: Điều này cho phép các tài nguyên trong VNet resolve các DNS records trong private DNS zone (e.g., *.azure.nimtechnology.academy).

Provision Azure Cache for Redis with Private Endpoint

module "redis" {
  source  = "Azure/avm-res-cache-redis/azurerm"
  # ... other config ...
  private_endpoints = {
    endpoint1 = {
      subnet_resource_id            = module.vnet.subnet_ids[0]
      private_dns_zone_group_name   = "private-dns-zone-group"
      private_dns_zone_resource_ids = [azurerm_private_dns_zone.this.id]
    }
  }
}
  • What happens:
    • The Redis instance is created.
    • A Private Endpoint được tạo trên 1 subnet nhất định.
    • The Private Endpoint được liên với  the Private DNS Zone thông qua một DNS Zone Group Name.
  • Purpose:
    • The Private Endpoint exposes(tiết lộ) a private IP address in your VNet for the Redis instance.
    • The DNS Zone Group links the Private Endpoint to the DNS zone, so DNS queries for the Redis hostname resolve to the private IP.

How the Domain is Linked to the Private IP

  • When the Private Endpoint is created:
  • Azure automatically creates a DNS record (e.g., redis-elearning.privatelink.redis.cache.windows.net) in the Private DNS Zone.
  • This record points to the private IP address assigned to the Private Endpoint in your VNet.
  • Because the VNet is linked to the DNS Zone:
  • Any VM or service in the VNet can resolve the Redis hostname to the private IP, ensuring traffic stays within the Azure network.

Bạn kiểm tra private endpoint như sau:

Tiếp đến bạn click vào private endpoint:

Tiếp đến là kiểm tra endpoint

Ngoài ra nếu bạn cần tạo firewall cho azure cache hoàn toàn dễ dàng:
bạn có thể tham khảo variabe sau:

variable "cache_access_policies" {
  type = map(object({
    name        = string
    permissions = string
  }))
  default     = {}
  description = <<DESCRIPTION
A map of objects describing one or more Redis cache access policies.
- `<map key>` - The map key is deliberately arbitrary to avoid issues where map keys may be unknown at plan time.
  - `name` - (Required) - The name string of the Redis Cache Access Policy. Changing this forces a new policy to be created.
  - `permissions` - (Required) - A string describing the permissions to be assigned to this Redis Cache Access Policy. Changing this forces a new policy to be created.

Example Input:

```hcl
cache_access_policies = {
  example_policy = {
    name = "example policy"
    permissions = "+@read +@connection +cluster|info"
  }
}
```
Uncategorized

Post navigation

Previous Post: [Azure/Loadbalancer] Creating an internal load balancer on Azure Kubernetes Service (AKS).
Next Post: [Service Endpoint] Explain the Service Endpoint in Azure VNet.

More Related Articles

[Gitlab] How to Install, Configure and Use Gitlab CE on Ubuntu Uncategorized
Đường link hỗ trợ các bạn download khoá học trên udemy free! Uncategorized
[PromQL] Use Count and Count by (xx) to count the number of pods that hold many containers inside these pods. Uncategorized
[Argo Workflow] Build the docker image with argo-workflow and Kaniko then push the image to ECR ArgoWorkflows
[GRPC] Checking GPRC Port by fullstorydev/grpcurl Coding
[Jenkins] Lưu ý nho nhỏ trong jenkins Jenkins

Leave a Reply Cancel reply

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

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [WordPress] Hướng dấn gửi mail trên WordPress thông qua gmail. June 15, 2025
  • [Bitbucket] Git Clone/Pull/Push with Bitbucket through API Token. June 12, 2025
  • [Teamcity] How to transfer the value from pipeline A to pipeline B June 9, 2025
  • [Windows] Remove the process that consumes too much CPU. June 3, 2025
  • Deploying Web-Based File Managers: File Browser and KubeFileBrowser with Docker and Kubernetes June 3, 2025

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.