Kubernetes - 如何引用文件共享以挂载卷?
Kubernetes - how to reference file share in order to mount volume?
我们计划为 K8S 使用 Azure Kubernetes 服务。我们有 Azure 文件共享。
是否可以在 Pod 或 Deployment yaml 定义中以某种方式引用 Azure 文件共享,以便可以将卷挂载到容器 (Pod) 级别?此引用是否需要在 AKS 集群创建期间定义,或者当我们执行 kubectl apply
命令部署我们的容器时以某种方式引用它就足够了 Pods.
谢谢
因此,根据@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
并且为了创建该秘密,您应该使用 assign correct values to 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)
并使用它。
我们计划为 K8S 使用 Azure Kubernetes 服务。我们有 Azure 文件共享。
是否可以在 Pod 或 Deployment yaml 定义中以某种方式引用 Azure 文件共享,以便可以将卷挂载到容器 (Pod) 级别?此引用是否需要在 AKS 集群创建期间定义,或者当我们执行 kubectl apply
命令部署我们的容器时以某种方式引用它就足够了 Pods.
谢谢
因此,根据@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
并且为了创建该秘密,您应该使用 assign correct values to 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)
并使用它。