gpt4 book ai didi

kubernetes - 如何让 Kubernetes PetSet 使用现有的 Persistent Volumes?

转载 作者:行者123 更新时间:2023-12-03 12:54:35 24 4
gpt4 key购买 nike

作为 PetSet 定义的一部分,为 Kubernetes 定义了 volumeClainTemplates 以动态生成持久卷声明。例如:

  volumeClaimTemplates:
- metadata:
name: datadir
annotations:
volume.alpha.kubernetes.io/storage-class: anything
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 24Gi

但是,我已经定义了一些持久卷:
#kubectl get pv    
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
pv-1-rw 24Gi RWO Retain Bound rnd/pvc-1-rw 1h
pv-2-rw 24Gi RWO Retain Bound rnd/pvc-2-rw 6d
pv-3-rw 24Gi RWO Retain Bound rnd/pvc-3-rw 6d
...

我希望 Kubernetes 从现有卷中选择持久卷,而不是动态创建新卷。

我正在使用 Kubernetes 1.4.3。有谁知道这是怎么做到的吗?

最佳答案

volumeClaimTemplatesPersistentVolumeClaim 的数组.您可以尝试使用 selector 来定义它们。并以某种方式标记现有卷,即:

kind: PersistentVolume
apiVersion: v1
metadata:
name: pv0001
labels:
foo: foo
bar: bar
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 5Gi
hostPath:
path: /data/pv0001/
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: pv0002
labels:
foo: foo
bar: bar
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 5Gi
hostPath:
path: /data/pv0002/
---
kind: Service
apiVersion: v1
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
selector:
app: nginx
---
kind: PetSet
apiVersion: apps/v1alpha1
metadata:
name: nginx
spec:
serviceName: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: gcr.io/google_containers/nginx-slim:0.8
ports:
- containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: html
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
selector:
matchLabels:
foo: foo
bar: bar

当然,体积必须可用于边界。
$ kubectl get pvc html-nginx-0
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
html-nginx-0 Bound pv0002 5Gi RWO 1m
$ kubectl get pv
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
pv0001 5Gi RWO Retain Available 2m
pv0002 5Gi RWO Retain Bound default/html-nginx-0 2m

关于kubernetes - 如何让 Kubernetes PetSet 使用现有的 Persistent Volumes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40299715/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com