Kubernetes
  • 序言
  • 基礎入門
    • Kubernetes 簡介
    • Kubernetes 基本概念
    • Kubernetes 101
    • Kubernetes 201
    • Kubernetes 集群
  • 核心原理
    • 核心原理
    • 架構原理
    • 設計理念
    • 核心組件
      • etcd
      • kube-apiserver
      • kube-scheduler
      • kube-controller-manager
      • kubelet
      • kube-proxy
      • kube-dns
      • Federation
      • kubeadm
      • hyperkube
      • kubectl
    • 資源對象
      • Autoscaling
      • ConfigMap
      • CronJob
      • CustomResourceDefinition
      • DaemonSet
      • Deployment
      • Ingress
      • Job
      • LocalVolume
      • Namespace
      • NetworkPolicy
      • Node
      • PersistentVolume
      • Pod
      • PodPreset
      • ReplicaSet
      • Resource Quota
      • Secret
      • SecurityContext
      • Service
      • ServiceAccount
      • StatefulSet
      • Volume
  • 部署配置
    • 部署指南
    • kubectl 安裝
    • 單機部署
    • 特性開關
    • 最佳配置
    • 版本支持
    • 集群部署
      • kubeadm
      • kops
      • Kubespray
      • Azure
      • Windows
      • LinuxKit
      • kubeasz
    • 附加組件
      • Addon-manager
      • DNS
      • Dashboard
      • 監控
      • 日誌
      • Metrics
      • GPU
      • Cluster Autoscaler
      • ip-masq-agent
    • Kubernetes-The-Hard-Way
      • 準備部署環境
      • 安裝必要工具
      • 創建計算資源
      • 配置創建證書
      • 配置生成配置
      • 配置生成密鑰
      • 部署 Etcd 群集
      • 部署控制節點
      • 部署計算節點
      • 配置 Kubectl
      • 配置網絡路由
      • 部署 DNS 擴展
      • 煙霧測試
      • 刪除集群
  • 插件擴展
    • API 擴展
      • Aggregation
      • CustomResourceDefinition
    • 訪問控制
      • 認證
      • RBAC 授權
      • 准入控制
    • Scheduler 擴展
    • 網絡插件
      • CNI
      • Flannel
      • Calico
      • Weave
      • Cilium
      • OVN
      • Contiv
      • SR-IOV
      • Romana
      • OpenContrail
      • Kuryr
    • 運行時插件 CRI
      • CRI-tools
      • Frakti
    • 存儲插件
      • 容器存儲接口 CSI
      • FlexVolume
      • glusterfs
    • 網絡策略
    • Ingress Controller
      • Ingress + Letsencrypt
      • minikube Ingress
      • Traefik Ingress
      • Keepalived-VIP
    • Cloud Provider 擴展
    • Device 插件
  • 服務治理
    • 服務治理
      • 一般準則
      • 滾動升級
      • Helm
      • Operator
      • Service Mesh
      • Linkerd
      • Linkerd2
    • Istio
      • 安裝
      • 流量管理
      • 安全管理
      • 策略管理
      • 度量管理
      • 排錯
      • 社區
    • Devops
      • Draft
      • Jenkins X
      • Spinnaker
      • Kompose
      • Skaffold
      • Argo
      • Flux GitOps
  • 實踐案例
    • 實踐概覽
    • 資源控制
    • 集群高可用
    • 應用高可用
    • 調試
    • 端口映射
    • 端口轉發
    • 用戶管理
    • GPU
    • HugePage
    • 安全
    • 審計
    • 備份恢復
    • 證書輪換
    • 大規模集群
    • 大數據與機器學習
      • Spark
      • Tensorflow
    • Serverless
  • 排錯指南
    • 排錯概覽
    • 集群排錯
    • Pod 排錯
    • 網絡排錯
    • PV 排錯
      • AzureDisk
      • AzureFile
    • Windows 排錯
    • 雲平臺排錯
      • Azure
    • 排錯工具
  • 社區貢獻
    • 開發指南
    • 單元測試和集成測試
    • 社區貢獻
  • 附錄
    • 生態圈
    • 學習資源
    • 國內鏡像
    • 如何貢獻
    • 參考文檔
Powered by GitBook
On this page
  • 訪問權限
  • Windows Node 重啓後無法訪問 AzureFile
  • AzureFile ProvisioningFailed
  • Azure German Cloud 無法使用 AzureFile
  • "could not change permissions" 錯誤
  • 參考文檔
  1. 排錯指南
  2. PV 排錯

AzureFile

PreviousAzureDiskNextWindows 排錯

Last updated 1 year ago

提供了基於 SMB 協議(也稱 CIFS)託管文件共享服務。它支持 Windows 和 Linux 容器,並支持跨主機的共享,可用於多個 Pod 之間的共享存儲。AzureFile 的缺點是性能(),並且不提供 Premium 存儲。

推薦基於 StorageClass 來使用 AzureFile,即

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: azurefile
provisioner: kubernetes.io/azure-file
mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=1000
  - gid=1000
parameters:
  skuName: Standard_LRS

使用 AzureFile 推薦的版本:

Kubernetes version
Recommended version

1.12

1.12.6 或更高版本

1.13

1.13.4 或更高版本

1.14

1.14.0 或更高版本

>=1.15

>=1.15

訪問權限

Kubernetes 版本
fileMode和dirMode

v1.6.x, v1.7.x

0777

v1.8.0-v1.8.5

0700

v1.8.6 or above

0755

v1.9.0

0700

v1.9.1-v1.12.1

0755

>=v1.12.2

0777

按照默認的權限會導致非跟用戶無法在目錄中創建新的文件,解決方法爲

  • v1.8.0-v1.8.5:設置容器以 root 用戶運行,如設置 spec.securityContext.runAsUser: 0

  • v1.8.6 以及更新版本:在 AzureFile StorageClass 通過 mountOptions 設置默認權限,比如設置爲 0777 的方法爲

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: azurefile
provisioner: kubernetes.io/azure-file
mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=1000
  - gid=1000
  - mfsymlinks
  - nobrl
  - cache=none
parameters:
  skuName: Standard_LRS

Windows Node 重啓後無法訪問 AzureFile

Warning  Failed                 1m (x7 over 1m)  kubelet, 77890k8s9010  Error: Error response from daemon: invalid bind mount spec "c:\\var\\lib\\kubelet\\pods\\07251c5c-1cfc-11e8-8f70-000d3afd4b43\\volumes\\kubernetes.io~azure-file\\pvc-fb6159f6-1cfb-11e8-8f70-000d3afd4b43:c:/mnt/azure": invalid volume specification: 'c:\var\lib\kubelet\pods\07251c5c-1cfc-11e8-8f70-000d3afd4b43\volumes\kubernetes.io~azure-file\pvc-fb6159f6-1cfb-11e8-8f70-000d3afd4b43:c:/mnt/azure': invalid mount config for type "bind": bind source path does not exist
  Normal   SandboxChanged         1m (x8 over 1m)  kubelet, 77890k8s9010  Pod sandbox changed, it will be killed and re-created.

臨時性解決方法爲刪除並重新創建使用了 AzureFile 的 Pod。當 Pod 使用控制器(如 Deployment、StatefulSet等)時,刪除 Pod 後控制器會自動創建一個新的 Pod。

AzureFile ProvisioningFailed

Azure 文件共享的名字最大隻允許 63 個字節,因而在集群名字較長的集群(Kubernetes v1.7.10 或者更老的集群)裏面有可能會碰到 AzureFile 名字長度超限的情況,導致 AzureFile ProvisioningFailed:

persistentvolume-controller    Warning    ProvisioningFailed Failed to provision volume with StorageClass "azurefile": failed to find a matching storage account

在開啓 RBAC 的集群中,由於 AzureFile 需要訪問 Secret,而 kube-controller-manager 中並未爲 AzureFile 自動授權,從而也會導致 ProvisioningFailed:

Events:
  Type     Reason              Age   From                         Message
  ----     ------              ----  ----                         -------
  Warning  ProvisioningFailed  8s    persistentvolume-controller  Failed to provision volume with StorageClass "azurefile": Couldn't create secret secrets is forbidden: User "system:serviceaccount:kube-syste
m:persistent-volume-binder" cannot create secrets in the namespace "default"
  Warning  ProvisioningFailed  8s    persistentvolume-controller  Failed to provision volume with StorageClass "azurefile": failed to find a matching storage account

解決方法是爲 ServiceAccount persistent-volume-binder 授予 Secret 的訪問權限:

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: system:azure-cloud-provider
rules:
- apiGroups: ['']
  resources: ['secrets']
  verbs:     ['get','create']
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: system:azure-cloud-provider
roleRef:
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
  name: system:azure-cloud-provider
subjects:
- kind: ServiceAccount
  name: persistent-volume-binder
  namespace: kube-system

Azure German Cloud 無法使用 AzureFile

"could not change permissions" 錯誤

在 Azure Files 插件上運行 PostgreSQL 時,可能會看到類似於以下內容的錯誤:

initdb: could not change permissions of directory "/var/lib/postgresql/data": Operation not permitted
fixing permissions on existing directory /var/lib/postgresql/data

此錯誤是由使用 cifs/SMB 協議的 Azure 文件插件導致的。 使用 cifs/SMB 協議時,無法在裝載後更改文件和目錄權限。 若要解決此問題,請將子路徑與 Azure 磁盤插件結合使用。

參考文檔

AzureFile 使用 將其遠端存儲掛載到 Node 上,而fileMode 和 dirMode 控制了掛載後文件和目錄的訪問權限。不同的 Kubernetes 版本,fileMode 和 dirMode 的默認選項是不同的

Windows Node 重啓後,掛載 AzureFile 的 Pod 可以看到如下錯誤():

該問題的修復 包含在 v1.10 中。

碰到該問題時可以通過升級集群解決,其修復 已經包含在 v1.7.11、v1.8 以及更新版本中。

Azure German Cloud 僅在 v1.7.11+、v1.8+ 以及更新版本中支持(),升級 Kubernetes 版本即可解決。

AzureFile
較差
AKS#223
mount.cifs
#60624
#60625
#48326
#48460
Known kubernetes issues on Azure
Introduction of Azure File Storage
AzureFile volume examples
Persistent volumes with Azure files
Azure Files scalability and performance targets