【问题标题】:Kubernetes - how to reference file share in order to mount volume?Kubernetes - 如何引用文件共享以挂载卷?
【发布时间】:2021-05-03 05:03:56
【问题描述】:

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

谢谢

【问题讨论】:

标签: docker kubernetes containers azure-aks fileshare


【解决方案1】:

因此,根据@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)

并使用它。

【讨论】:

  • 谢谢,但我也很困惑在哪些情况下我需要使用 PersistentVolume 和 PersistentVolumeClaim?我不需要这个用例吗?我可以毫无问题地引用挂载卷吗?谢谢
  • 您能否告诉我是否也应该通过它们的专用 yaml 文件定义 PersistenVolume 和 PersistentVolumeClaim?
  • 你能告诉我是否也应该在 YAML 中定义 PersistentVolument 和 PersistentVolumeClaim 吗?谢谢
猜你喜欢
  • 2018-11-14
  • 2019-09-28
  • 2020-08-07
  • 1970-01-01
  • 1970-01-01
  • 2019-08-24
  • 2021-10-26
  • 2019-10-09
  • 1970-01-01
相关资源
最近更新 更多