简体   繁体   English

Kube.netes - 如何引用文件共享以挂载卷?

[英]Kubernetes - how to reference file share in order to mount volume?

we plan to use Azure Kube.netes Service for K8S.我们计划为 K8S 使用 Azure Kube.netes 服务。 We have our Azure File Share.我们有 Azure 文件共享。 Is it possible to reference somehow Azure File Share within the Pod or Deployment yaml definition so that volume can be mounted on the container (Pod) level?是否可以在Pod 或部署yaml 定义中以某种方式引用 Azure 文件共享,以便可以在容器 (Pod) 级别上安装卷? Is this reference something which needs to be defined during the AKS cluster creation or it is enough to reference it somehow when we execute kubectl apply command to deploy our containers Pods.这个引用是需要在 AKS 集群创建期间定义的东西,还是在我们执行kubectl apply命令部署我们的容器 Pod 时以某种方式引用它就足够了。

Thanks谢谢

So, as per Mount the file share as a volume documentation, provided by @AndreyDonald, you can reference like this因此,根据@AndreyDonald 提供的将文件共享安装为卷文档,您可以这样参考

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

But prior to that you should Create a Kube.netes secret .但在此之前,您应该创建一个 Kube.netes secret

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

And in order to create that secret you should use assign correct values to vars为了创建该秘密,您应该使用 assign correct values to vars

$AKS_PERS_STORAGE_ACCOUNT_NAME
$STORAGE_KEY

You dont have to create new File Share, just您不必创建新的文件共享,只需

# 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)

and use it.并使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM