gpt4 book ai didi

kubernetes - 如何在 Kubernetes 部署中使用卷?

转载 作者:行者123 更新时间:2023-12-01 06:16:26 24 4
gpt4 key购买 nike

<分区>

我想将卷用于具有多个副本的部署。如何定义 PersistentVolumeClaim 以便为每个副本生成它?目前(参见下面的示例)我能够生成一个卷并将其分配给 pod。问题是,只生成一个卷,导致此错误消息:

  38m   1m  18  {kubelet worker-1.loc}      Warning FailedMount Unable to mount volumes for pod "solr-1254544937-zblou_default(610b157c-549e-11e6-a624-0238b97cfe8f)": timeout expired waiting for volumes to attach/mount for pod "solr-1254544937-zblou"/"default". list of unattached/unmounted volumes=[datadir]
38m 1m 18 {kubelet worker-1.loc} Warning FailedSync Error syncing pod, skipping: timeout expired waiting for volumes to attach/mount for pod "solr-1254544937-zblou"/"default". list of unattached/unmounted volumes=[datadir]

如何告诉 Kubernetes 为每个副本生成一个卷?

我正在使用 Kubernetes 1.3。


例子:

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: solr-datadir
annotations:
volume.alpha.kubernetes.io/storage-class: anything
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
---
apiVersion: extensions/v1beta1
kind: Deployment

metadata:
name: solr
labels:
team: platform
tier: search
app: solr

spec:
revisionHistoryLimit: 3
replicas: 3

template:
metadata:
name: solr
labels:
team: platform
tier: search
app: solr

spec:
containers:
- name: solr
image: solr:6-alpine
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
resources:
requests:
cpu: 512m
memory: 512Mi
command:
- /bin/bash
args:
- -c
- /opt/solr/bin/solr start -f -z zookeeper:2181
volumeMounts:
- mountPath: "/opt/solr/server/solr/mycores"
name: datadir
volumes:
- name: datadir
persistentVolumeClaim:
claimName: solr-datadir

生成的 pod:

$ kubectl get pods -lapp=solr 
NAME READY STATUS RESTARTS AGE
solr-1254544937-chenr 1/1 Running 0 55m
solr-1254544937-gjud0 0/1 ContainerCreating 0 55m
solr-1254544937-zblou 0/1 ContainerCreating 0 55m

生成的卷:

$ kubectl get pv
NAME CAPACITY ACCESSMODES STATUS CLAIM REASON AGE
pvc-3955e8f1-549e-11e6-94be-060ea3314be5 50Gi RWO Bound default/solr-datadir 57m

生成的声明:

$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
solr-datadir Bound pvc-3955e8f1-549e-11e6-94be-060ea3314be5 0 57m

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