当我提供hostpath时,它表明它是只读文件系统,因为我是kubernetes的新手,我没有找到其他任何方法,请告知我,还有其他实现卷的方法,我正在这样做在GKE上
这是我的yaml代码

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "10"
  creationTimestamp: "2019-11-22T10:52:16Z"
  generation: 17
  labels:
    app: dataset
  name: dataset
  namespace: default
  resourceVersion: "283767"
  selfLink: /apis/apps/v1/namespaces/default/deployments/dataset
  uid: 26111fe8-0d16-11ea-a66e-42010aa00042
spec:
  progressDeadlineSeconds: 600
  replicas: 2
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: dataset
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: dataset
    spec:
      containers:
      - env:
        - name: RABBIT_MQ_HOST
          valueFrom:
            configMapKeyRef:
              key: RABBIT_MQ_HOST
              name: dataset-config
        - name: RABBIT_MQ_USER
          valueFrom:
            configMapKeyRef:
              key: RABBIT_MQ_USER
              name: dataset-config
        - name: RABBIT_MQ_PASSWORD
          valueFrom:
            configMapKeyRef:
              key: RABBIT_MQ_PASSWORD
              name: dataset-config
        - name: DATASET_DB_HOST
          valueFrom:
            configMapKeyRef:
              key: DATASET_DB_HOST
              name: dataset-config
        - name: DATASET_DB_NAME
          valueFrom:
            configMapKeyRef:
              key: DATASET_DB_NAME
              name: dataset-config
        - name: LICENSE_SERVER
          valueFrom:
            configMapKeyRef:
              key: LICENSE_SERVER
              name: dataset-config
        - name: DATASET_THUMBNAIL_SIZE
          valueFrom:
            configMapKeyRef:
              key: DATASET_THUMBNAIL_SIZE
              name: dataset-config
        - name: GATEWAY_URL
          valueFrom:
            configMapKeyRef:
              key: GATEWAY_URL
              name: dataset-config
        - name: DEFAULT_DATASOURCE_ID
          valueFrom:
            configMapKeyRef:
              key: DEFAULT_DATASOURCE_ID
              name: dataset-config
        - name: RABBIT_MQ_QUEUE_NAME
          valueFrom:
            configMapKeyRef:
              key: RABBIT_MQ_QUEUE_NAME
              name: dataset-config
        - name: RABBIT_MQ_PATTERN
          valueFrom:
            configMapKeyRef:
              key: RABBIT_MQ_PATTERN
              name: dataset-config
        image: gcr.io/gcr-testing-258008/dataset@sha256:8416ec9b023d4a4587a511b855c2735b25a16dbb1a15531d8974d0ef89ad3d73
        imagePullPolicy: IfNotPresent
        name: dataset-sha256
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: ./data/uploads
          name: dataset-volume-uploads
        - mountPath: ./data/thumbnails
          name: dataset-volume-thumbnails
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - hostPath:
          path: /build/uploads
          type: ""
        name: dataset-volume-uploads
      - hostPath:
          path: /build/thumbnails
          type: ""
        name: dataset-volume-thumbnails
status:
  availableReplicas: 2
  conditions:
  - lastTransitionTime: "2019-11-23T07:19:13Z"
    lastUpdateTime: "2019-11-23T07:19:13Z"
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  - lastTransitionTime: "2019-11-23T06:31:03Z"
    lastUpdateTime: "2019-11-23T07:24:42Z"
    message: ReplicaSet "dataset-75b46f868f" is progressing.
    reason: ReplicaSetUpdated
    status: "True"
    type: Progressing
  observedGeneration: 17
  readyReplicas: 2
  replicas: 3
  unavailableReplicas: 1
  updatedReplicas: 1

这是我对 pods 的描述
    Path:          /build/uploads
    HostPathType:
  dataset-volume-thumbnails:
    Type:          HostPath (bare host directory volume)
    Path:          /build/thumbnails
    HostPathType:
  default-token-x2wmw:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-x2wmw
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                From                                              Message
  ----     ------     ----               ----                                              -------
  Normal   Scheduled  96s                default-scheduler                                 Successfully assigned default/dataset-75b46f868f-wffm7 to gke-teric-ai-default-pool-41929025-fxnx
  Warning  BackOff    15s (x6 over 93s)  kubelet, gke-teric-ai-default-pool-41929025-fxnx  Back-off restarting failed container
  Normal   Pulled     2s (x5 over 95s)   kubelet, gke-teric-ai-default-pool-41929025-fxnx  Container image "gcr.io/gcr-testing-258008/dataset@sha256:8416ec9b023d4a4587a511b855c2735b25a16dbb1a15531d8974d0ef89ad3d73" already present on machine
  Normal   Created    2s (x5 over 95s)   kubelet, gke-teric-ai-default-pool-41929025-fxnx  Created container
  Warning  Failed     1s (x5 over 95s)   kubelet, gke-teric-ai-default-pool-41929025-fxnx  Error: failed to start container "dataset-sha256": Error response from daemon: error while creating mount source path '/build/uploads': mkdir /build/uploads: read-only file system

所以这是问题所在,即使我动态地给chmod权限也不允许执行写操作。我尝试了持久卷也无法正常工作,所以请告诉我我必须以哪种方式挂载卷。

最佳答案

  • 首先,不要使用hostPath,去进行持久性存储
  • 如果您需要存储一些数据,我将使用StatefulSets而不是Deployment。

  • 我能够以root用户身份在我的GKE实例上手动创建两个hostPath。

    我想您必须为hostPath指定类型以创建请求目录(如果该目录不存在)。 type: DirectoryOrCreate,您可以阅读有关hostPath和可用类型值的更多信息。
    而且,如果您使用的是容器内用户的hostPath权限,则必须与节点上的所有权匹配,这样会使它变得更加复杂,当然,您可以以root身份运行它,但是不建议这样做。

    总结起来,只需要使用谷歌提供的持久存储。如果遇到权限问题,则可能需要init contaner更改权限,或者必须为容器设置适当的fsGroup

    10-06 08:46