2
1

More than 1 year has passed since last update.

Azure Blob StorageをNFSでマウント

Last updated at Posted at 2022-01-22

Azure Blob StorageをVMやAKSからマウントするにはこれまでは、Azure Blob Storage CSI driverを使わなければいけませんでした。

2021年12月にNFSもサポートされるようになったので、それを試してみます。

#NFSを使用可にしたストレージ アカウント
現在のところ、既存のストレージ アカウントにNFSを追加することはできないようです。ですので、新しいストレージ アカウントの作成が必要です。

Terraformの場合は、以下のような感じです。nfsv3_enabled = "true"とするだけです。

resource "azurerm_storage_account" "nfssa1" {
  name                     = "nfssa"
  resource_group_name      = "mygroup"
  location                 = "Japan West"
  account_tier             = "Standard"
  account_replication_type = "ZRS"
  min_tls_version          = "TLS1_2"
  account_kind             = "StorageV2"
  is_hns_enabled           = "true"
  nfsv3_enabled            = "true"

  network_rules {
    default_action             = "Deny"
    ip_rules                   = ["x.x.x.x/28"]
    virtual_network_subnet_ids = [data.azurerm_subnet.mysubnet.id]
  }  
}

resource "azurerm_storage_container" "sa_container" {
  name                  = "mycontainer"
  storage_account_name = azurerm_storage_account.nfssa1.name
  container_access_type = "private"
  depends_on = [
    azurerm_storage_account.nfssa1
  ]  
}

ちなみに、default_action = "Deny"がないとエラーが出ます。

#VMからNFSでマウント
AzureでUbuntuのVMを使用する場合は、こんな感じでできます。

sudo apt install -y nfs-common
install -d /mnt/mystorage

#mount -o sec=sys,vers=3,nolock,proto=tcp <storage-account-name>.blob.core.windows.net:/<storage-account-name>/<container-name>  /mnt/mystorage
mount -o sec=sys,vers=3,nolock,proto=tcp nfssa.blob.core.windows.net:/nfssa/mycontainer  /mnt/mystorage

/etc/fstabを編集する場合は、以下のように1行足せば永続的にマウントできます。

#vi /etc/fstab
nfssa.blob.core.windows.net:/nfssa/mycontainer /mount/mystorage nfs sec=sys,vers=3,nolock,proto=tcp 0 0

NFSのアクセスの制限は、VNetやネットワークセキュリティキー設定で行う必要があるようです。デファルトでは、Terraformで設定したvirtual_network_subnet_ids = [data.azurerm_subnet.mysubnet.id]内からはマウントが可能になります。一部のVMのみにアクセスを制限する場合は、ネットワークセキュリティキー設定を使う必要があるでしょう。

2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1