Kubernetes 如何配置StatefolSet的侧车以使用主容器的持久卷?
我有一个statefulset,我想为该statefulset添加另一个container-2&我想让container-2访问container-1使用volumeClaimTemplates创建的pv:Kubernetes 如何配置StatefolSet的侧车以使用主容器的持久卷?,kubernetes,google-kubernetes-engine,kubernetes-helm,kubernetes-pod,kubernetes-statefulset,Kubernetes,Google Kubernetes Engine,Kubernetes Helm,Kubernetes Pod,Kubernetes Statefulset,我有一个statefulset,我想为该statefulset添加另一个container-2&我想让container-2访问container-1使用volumeClaimTemplates创建的pv: 我们有什么办法可以实现上述目标吗?您提出的问题相当笼统,没有任何具体要求,只有GKE标签和两个使用相同PV的容器 我已经测试了一个非常简单的示例。 当您使用statefulset时,您必须记住一些 在这个测试中,我使用了Kubernetes文档示例,它使用busybox而不是nginx和GK
我们有什么办法可以实现上述目标吗?您提出的问题相当笼统,没有任何具体要求,只有GKE标签和两个使用相同PV的容器 我已经测试了一个非常简单的示例。 当您使用statefulset时,您必须记住一些 在这个测试中,我使用了Kubernetes文档示例,它使用busybox而不是nginx和GKE集群v1.14.10-GKE.36。 请记住 状态设置和服务yaml如下: 输出: 测试: 这个例子是在GKE上测试的,所以您不需要像云提供商那样创建PV和PVC。
希望这能回答你的问题。你以前试过什么吗?或者如果可能的话,这只是一个理论问题?
apiVersion: v1
kind: Service
metadata:
name: busybox-service
labels:
app: busybox
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: busybox
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: busybox
spec:
serviceName: busybox
replicas: 1
selector:
matchLabels:
app: busybox
template:
metadata:
labels:
app: busybox
spec:
containers:
- image: busybox
args: [/bin/sh, -c, 'sleep 9999' ]
volumeMounts:
- mountPath: /test
name: busybox-volume
name: busybox
- image: busybox
args: [/bin/sh, -c, 'sleep 9999' ]
volumeMounts:
- mountPath: /test
name: busybox-volume
name: busybox-two
volumeClaimTemplates:
- metadata:
name: busybox-volume
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
$ kubectl get pods,pv,pvc
NAME READY STATUS RESTARTS AGE
pod/busybox-0 2/2 Running 0 2m38s
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pvc-3fe7dbe8-96ce-11ea-ae2e-42010a9a012f 1Gi RWO Delete Bound default/busybox-volume-busybox-0 standard 2m36s
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/busybox-volume-busybox-0 Bound pvc-3fe7dbe8-96ce-11ea-ae2e-42010a9a012f 1Gi RWO standard 2m39s
$ kubectl exec -ti busybox-0 -c busybox -- /bin/sh
/ # ls
bin dev etc home proc root sys test tmp usr var
/ # cd test
/test # ls
lost+found
/test # echo "This is test message, container buxybox" >> msg.txt
/test # cat msg.txt
This is test message, container buxybox
/test # exit
$ kubectl exec -ti busybox-0 -c busybox-two -- /bin/sh
/ # ls
bin dev etc home proc root sys test tmp usr var
/ # cd test/
/test # ls
lost+found msg.txt
/test # cat msg.txt
This is test message, container buxybox
/test # echo "This is message from container busybox-two" >> msg.txt
/test # exit
$ kubectl exec -ti busybox-0 -c busybox -- /bin/sh
/ # cat /test/msg.txt
This is test message, container buxybox
This is message from container busybox-two