Kubernetes - 如何引用文件共享以挂载卷?

问题描述

我们计划将 Azure Kubernetes 服务用于 K8S。我们有 Azure 文件共享。 是否可以在 Pod 或部署 yaml 定义中以某种方式引用 Azure 文件共享,以便可以在容器 (Pod) 级别安装卷?此引用是否需要在 AKS 集群创建期间定义,或者在我们执行 kubectl apply 命令部署容器 Pod 时以某种方式引用它就足够了。

谢谢

解决方法

因此,根据@AndreyDonald 提供的 Mount the file share as a volume 文档,您可以像这样参考

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - image: mcr.microsoft.com/oss/nginx/nginx:1.15.5-alpine
    name: mypod
    resources:
      requests:
        cpu: 100m
        memory: 128Mi
      limits:
        cpu: 250m
        memory: 256Mi
    volumeMounts:
      - name: azure
        mountPath: /mnt/azure
  volumes:
  - name: azure
    azureFile:
      secretName: azure-secret
      shareName: aksshare
      readOnly: false

但在此之前您应该Create a Kubernetes secret

kubectl create secret generic azure-secret --from-literal=azurestorageaccountname=$AKS_PERS_STORAGE_ACCOUNT_NAME --from-literal=azurestorageaccountkey=$STORAGE_KEY

为了创建那个秘密,你应该使用为 vars 分配正确的值

$AKS_PERS_STORAGE_ACCOUNT_NAME
$STORAGE_KEY

您不必创建新的文件共享,只需

# Get storage account key
STORAGE_KEY=$(az storage account keys list --resource-group $AKS_PERS_RESOURCE_GROUP --account-name $AKS_PERS_STORAGE_ACCOUNT_NAME --query "[0].value" -o tsv)

并使用它。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...