设置GCP FileStorage和Kubernetes

时间:2019-07-03 11:46:30

标签: kubernetes google-cloud-platform vpc google-cloud-filestore

如何将FileStorage挂载到GCP的Kubernetes容器中

我确实遵循了文档,但吊舱仍在等待中

我做到了:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: <some name>
spec:
  capacity:
    storage: 50Gi
  accessModes:
  - ReadWriteMany
  nfs:
    path: /
    server: <filestorage_ip with this format xx.xxx.xxx.xx>
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: <some name>
  namespace: <some name>
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 50Gi
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: <some name>
  name: <some name>
  labels:
    app: <some name>
spec:
  replicas: 2
  selector:
    matchLabels:
      app: <some name>
  template:
    metadata:
      labels:
        app: <some name>
    spec:
      containers:
      - name: <some name>
        image: gcr.io/somepath/<some name>@sha256:<some hash>
        ports:
        - containerPort: 80 
        volumeMounts:
          - name: <some name>
            mountPath: /var/www/html
        imagePullPolicy: Always
      restartPolicy: Always
      volumes:
        - name: <some name>
          persistentVolumeClaim:
            claimName: <some name>
            readOnly: false

运行kubectl -n <some name> describe pods返回:

Events:
  Type     Reason       Age                     From                                                        Message
  ----     ------       ----                    ----                                                        -------
  Warning  FailedMount  23m (x52 over 3h21m)    kubelet, gke-<some name>-default-pool-<some hash>  Unable to mount volumes for pod "<some name>-<some hash>_<some name>(<some hash>)": timeout expired waiting for volumes to attach or mount for pod "<some name>"/"<some name>-<some hash>". list of unmounted volumes=[<some name>-persistent-storage]. list of unattached volumes=[<some name>-persistent-storage default-token-<some hash>]
  Warning  FailedMount  3m5s (x127 over 3h21m)  kubelet, gke-<some name>-default-pool-<some hash>  (combined from similar events): MountVolume.SetUp failed for volume "<some name>-storage" : mount failed: exit status 1
Mounting command: systemd-run
Mounting arguments: --description=Kubernetes transient mount for /var/lib/kubelet/pods/<some path>/volumes/kubernetes.io~nfs/<some name>-storage --scope -- /home/kubernetes/containerized_mounter/mounter mount -t nfs <filestorage_ip with this format xx.xxx.xxx.xx>:/ /var/lib/kubelet/pods/<some hash>/volumes/kubernetes.io~nfs/<some name>-storage
Output: Running scope as unit: run-<some hash>.scope
Mount failed: mount failed: exit status 32
Mounting command: chroot
Mounting arguments: [/home/kubernetes/containerized_mounter/rootfs mount -t nfs <filestorage_ip with this format xx.xxx.xxx.xx>:/ /var/lib/kubelet/pods/<some hash>/volumes/kubernetes.io~nfs/<some name>-storage]
Output: mount.nfs: access denied by server while mounting <filestorage_ip with this format xx.xxx.xxx.xx>:/

似乎Pod无法访问FileStorage服务的IP 在文档中说,该文件必须位于同一VPC上

“授权网络* 只能从授权的VPC网络上的计算机访问文件存储实例。选择您需要访问的网络。“

但是我不知道如何将Kubernetes集群添加到VPC

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我发现了问题

PersistentVolume无法安装在path: /中 它需要“文件共享属性”字段,可让您填写创建内容 现在可以与多个吊舱​​一起使用!