【问题标题】:smb/cifs mountOptions failed to apply in kubernetessmb/cifs mountOptions 在 kubernetes 中应用失败
【发布时间】:2021-12-05 23:41:35
【问题描述】:

发生了什么:

无法将 mountOptions 用于 onprem smb 挂载

你预期会发生什么:

使用 mountOptions 创建清单

如何重现它(尽可能最小和精确):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: "test"
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "smbmount.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "smbmount.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          resources:
            limits:
              memory: "16048Mi"
              cpu: "16000m"
          volumeMounts:
          - name: smb01
            mountPath: /smb/01

      volumes:
      - name: smb01
        csi:
          driver: file.csi.azure.com
          volumeAttributes:
            server: 10.10.10.100
            shareName: share01
            secretName: smbcreds
            mountOptions:
            - dir_mode=0777

什么错误:

错误:无法从发布清单构建 kubernetes 对象:错误 验证“”:错误验证数据: ValidationError(Deployment.spec.template.spec.volumes[0].csi.volumeAttributes.mountOptions): io.k8s.api.core.v1.CSIVolumeSource.volumeAttributes 的类型无效: 得到“数组”,预期“字符串”

我是否为 mountOptions 使用了正确的位置?或者我在部署文件中犯了什么错误

values.yaml

# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 2

image:
  repository: prxzzzzjjkkk.azurecr.io/smbtest
  pullPolicy: Always
  # Overrides the image tag whose default is the chart appVersion.
  tag: latest

imagePullSecrets:
  - name: acr-pull-secrets
nameOverride: ""
fullnameOverride: ""

serviceAccount:
  # Specifies whether a service account should be created
  create: true
  # Annotations to add to the service account
  annotations: {}
  # The name of the service account to use.
  # If not set and create is true, a name is generated using the fullname template
  name: ""

podAnnotations: {}

podSecurityContext: {}
  # fsGroup: 2000

securityContext: {}
  # capabilities:
  #   drop:
  #   - ALL
  # readOnlyRootFilesystem: true
  # runAsNonRoot: true
  # runAsUser: 1000

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  className: ""
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  hosts:
    - host: chart-example.local
      paths:
        - path: /
          pathType: ImplementationSpecific
  tls: []
  #  - secretName: chart-example-tls
  #    hosts:
  #      - chart-example.local

resources: {}
  # We usually recommend not to specify default resources and to leave this as a conscious
  # choice for the user. This also increases chances charts run on environments with little
  # resources, such as Minikube. If you do want to specify resources, uncomment the following
  # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
  # limits:
  #   cpu: 100m
  #   memory: 128Mi
  # requests:
  #   cpu: 100m
  #   memory: 128Mi

autoscaling:
  enabled: false
  minReplicas: 1
  maxReplicas: 100
  targetCPUUtilizationPercentage: 80
  # targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

【问题讨论】:

  • 你的Values.yaml在哪里?
  • 在问题中更新,删除了一些秘密

标签: azure kubernetes kubernetes-helm azure-aks cifs


【解决方案1】:

请将deployment.spec.template.spec.volumes.csi.volumeAttributes.mountOptions 修改为逗号分隔的键值对字符串,而不是数组。

所以您修改后的部署清单应该有

...
 volumes:
      - name: smb01
        csi:
          driver: file.csi.azure.com
          volumeAttributes:
            server: 10.10.10.100
            shareName: share01
            secretName: smbcreds
            mountOptions: "dir_mode=0777" #correct format

而不是

 ...
 volumes:
      - name: smb01
        csi:
          driver: file.csi.azure.com
          volumeAttributes:
            server: 10.10.10.100
            shareName: share01
            secretName: smbcreds
            mountOptions: #incorrect format
            - dir_mode=0777 

参考:https://raw.githubusercontent.com/kubernetes-sigs/azurefile-csi-driver/master/deploy/example/nginx-pod-azurefile-inline-volume.yaml

【讨论】:

    【解决方案2】:

    CSIVolumeSource.volumeAttributes: got "array", expected "string" 的地方明确提到了错误,它得到了数组而不是字符串

    你的 YAML 应该是这样的

    volumes:
          - name: smb01
            csi:
              driver: file.csi.azure.com
              volumeAttributes:
                server: 10.10.10.100
                shareName: share01
                secretName: smbcreds
                mountOptions: dir_mode=0777
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      • 2015-03-15
      • 2013-07-21
      • 2019-04-04
      • 2017-11-21
      • 1970-01-01
      相关资源
      最近更新 更多