4

I have 2 different namespace: prod-01 and prod-02, What I want to do is build a copy of my prod-01 into prod-02 namespace keeping the same names for its pvcs, so that I don't have to maintain 2 sets of charts for each different namespace.

Here's how it looks like:

$ kubectl get ns | grep prod
prod-01          Active    178d
prod-02          Active    8d
$ 

As shown below, I have 2 pairs of pv's for each namespace:

$ kubectl get pv -o wide | grep prod
prod-01-db-pv                    50Gi       RWX            Retain           Bound       prod-01/app-db                                                                      164d
prod-01-nosql-db-pv              5Gi        RWX            Retain           Bound       prod-01/app-nosql-db                                                                149d
prod-02-db-pv                50Gi       RWX            Retain           Available   prod-02/app-db                                                          41m
prod-02-nosql-db-pv          5Gi        RWX            Retain           Available   prod-02/app-nosql-db                                                    19m
$ 

Here's how pvc's for prod-01 are being displayed:

$ kubectl get pvc --namespace=prod-01
NAME              STATUS    VOLUME               CAPACITY   ACCESS MODES   STORAGECLASS   AGE
app-db         Bound     prod-01-db-pv         50Gi       RWX                           164d
app-nosql-db   Bound     prod-01-nosql-db-pv   5Gi        RWX                           149d
$ 

And here's what I'm trying to accomplish:

$ kubectl get pvc --namespace=prod-02
NAME              STATUS    VOLUME                   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
app-db         Pending   prod-02-db-pv         0                                        2m
app-nosql-db   Pending   prod-02-nosql-db-pv   0                                        24m
$ 

As shown above, the pvc's for prod-02 namespace are stuck forever with Pending status.

Them when I change the pvc names on prod-02 to anything different, they bond as expected.

Which leads me to think I can't use the same names on pvc's even when they are in different namespaces and pointing to different pv's ... However, when searching the documentation, I could not find any evidence to this issue, and was wondering if I could be missing something.

So to put it simple, can I have multiple pvc's with the same name accross different namespaces (considering that they are using different pv's)?


Update: result of kubectl describe pvc

$ kubectl describe pvc app-db --namespace=prod-02
Name:          app-db
Namespace:     prod-02
StorageClass:  
Status:        Pending
Volume:        prod-02-db-pv
Labels:        <none>
Annotations:   <none>
Finalizers:    []
Capacity:      0
Access Modes:  
Events:        <none>
$ 

Also here's the output of kubectl get pvc:

$ kubectl get pvc app-db --namespace=prod-02  -o yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: 2018-09-22T22:00:34Z
  name: app-db
  namespace: prod-02
  resourceVersion: "43027607"
  selfLink: /api/v1/namespaces/prod-02/persistentvolumeclaims/app-db
  uid: ee81b951-beb2-11e8-b972-005056bbded7
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 50Gi
  volumeName: prod-02-db-pv
status:
  phase: Pending
$ 

And here are some details about the pv too:

$ kubectl get pv prod-02-db-pv --namespace=prod-02 -o yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  creationTimestamp: 2018-09-22T21:15:19Z
  name: prod-02-db-pv
  resourceVersion: "43020171"
  selfLink: /api/v1/persistentvolumes/prod-02-db-pv
  uid: 9c07d7a6-beac-11e8-b972-005056bbded7
spec:
  accessModes:
  - ReadWriteMany
  capacity:
    storage: 50Gi
  claimRef:
    apiVersion: v1
    kind: PersistentVolumeClaim
    name: app-db
    namespace: prod-02
  nfs:
    path: /nfs_server/prod02/db
    server: 158.87.52.35
  persistentVolumeReclaimPolicy: Retain
status:
  phase: Available
$ 

Thanks in advance for the help!

4

2 回答 2

5

PVC 是命名空间资源,但不是 PV。即,您可以在不同的命名空间中拥有多个具有相同名称的 PVC。

您配置 pv 的方式可能存在问题。

您能否确保在nfs属性下的 pv 配置中使用正确的 IP 地址:

nfs:
path: /nfs_server/prod01/db
server: 158.87.52.35
于 2018-09-23T07:27:57.463 回答
1

在 OpenShift 文档的以下链接中找到了我的问题的原因:

原来问题与在用于创建prod-02 pv 的 yaml 文件中错误使用claimRefs有关,这是完整的解释:

在你的 PVC 中指定一个 volumeName 并不会阻止不同的 PVC 在你之前绑定到指定的 PV。在 PV 可用之前,您的索赔将保持未决状态。

在 PV 中指定 claimRef 不会阻止指定的 PVC 绑定到不同的 PV。PVC 可以按照正常的绑定过程自由选择另一个 PV 进行绑定。因此,为避免这些情况并确保您的声明绑定到所需的卷,您必须确保同时指定 volumeName 和 claimRef。

因此,在修复claimRefs并重新创建我的 pv 之后,即使在其他命名空间上使用相同的名称,pvc 也开始按预期绑定:-)

于 2018-09-24T00:25:07.890 回答