Kubernetes - ReplicationController和Persistent Disks

时间:2016-04-20 13:34:21

标签: ruby-on-rails docker kubernetes

我遇到了与Kubernetes相关的问题。我刚刚从Pod配置转移到ReplicationController以获取Ruby on Rails应用程序,我正在使用持久磁盘用于Rails pod。当我尝试应用ReplicationController时,它会出现以下错误:

  

The ReplicationController "cartelhouse-ror" is invalid. spec.template.spec.volumes[0].gcePersistentDisk.readOnly: Invalid value: false: must be true for replicated pods > 1; GCE PD can only be mounted on multiple machines if it is read-only

这是否意味着在使用ReplicationControllers时无法使用永久磁盘(R / W),还是有其他方式?

如果没有,我如何扩展和/或应用滚动更新到Pod配置?

Pod配置:

apiVersion: v1
kind: Pod
metadata:
  name: appname
  labels:
    name: appname
spec:
  containers:
        - image: gcr.io/proj/appname:tag
      name: appname
      env:
            - name: POSTGRES_PASSWORD
              # Change this - must match postgres.yaml password.
          value: pazzzzwd
            - name: POSTGRES_USER
          value: rails
      ports:
            - containerPort: 80
          name: appname
      volumeMounts:
              # Name must match the volume name below.
            - name: appname-disk-per-sto
              # Mount path within the container.
          mountPath: /var/www/html
  volumes:
        - name: appname-disk-per-sto
      gcePersistentDisk:
            # This GCE persistent disk must already exist.
        pdName: appname-disk-per-sto
        fsType: ext4

ReplicationController配置:

apiVersion: v1
kind: ReplicationController
metadata:
      labels:
        name: appname
      name: appname
spec:
      replicas: 2
      selector:
        name: appname
      template:
        metadata:
          labels:
            name: appname
        spec:
          containers:
            - image: gcr.io/proj/app:tag
              name: appname
              env:
                - name: POSTGRES_PASSWORD
                  # Change this - must match postgres.yaml password.
                  value: pazzzzwd
                - name: POSTGRES_USER
                  value: rails
              ports:
                - containerPort: 80
                  name: appname
              volumeMounts:
                  # Name must match the volume name below.
                - name: appname-disk-per-sto
                  # Mount path within the container.
                  mountPath: /var/www/html
          volumes:
            - name: appname-disk-per-sto
              gcePersistentDisk:
                # This GCE persistent disk must already exist.
                pdName: appname-disk-per-sto
                fsType: ext4

2 个答案:

答案 0 :(得分:3)

目前的Kubernetes无法实现这一目标 - 请参阅Independent storage for replicated pods。这将在v1.3中应用的PetSets的实现中涵盖。

答案 1 :(得分:2)

问题不在于Kubernetes,而在于共享块设备和文件系统无法同时安装到多个主机。 https://unix.stackexchange.com/questions/68790/can-the-same-ext4-disk-be-mounted-from-two-hosts-one-readonly

您可以尝试使用声明:http://kubernetes.io/docs/user-guide/persistent-volumes/

或其他文件系统,例如nfs:http://kubernetes.io/docs/user-guide/volumes/