Reputation: 168
I have applied the following pvc yaml.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ebs-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: ebs-sc
resources:
requests:
storage: 4Gi
I now want my statefulset to use the PVC I have created. Instead, it is creating new PVC of a different storageclass.
apiVersion: v1
kind: statefulset
metadata:
name: example
spec:
# Name for the service object created by the operator
serviceName: mongodb-service
selector: {}
# Specifies a size for the data volume different from the default 10Gi
volumeClaimTemplates:
- metadata:
name: ebs-claim
template:
spec:
nodeSelector:
eks.amazonaws.com/nodegroup: managed-ng-private-1
How can I get my statefulset to use existing PVCs instead of creating new ones?
Upvotes: 6
Views: 5705
Reputation: 434
The stateful set definition is missing the volume. Give the below yaml a try and check.
apiVersion: v1
kind: statefulset
metadata:
name: example
spec:
# Name for the service object created by the operator
serviceName: mongodb-service
selector: {}
# Specifies a size for the data volume different from the default 10Gi
volumes:
- name: ebs-vol
persistentVolumeClaim:
claimName: PersistentVolumeClaim
volumeClaimTemplates:
- metadata:
name: ebs-claim
template:
spec:
nodeSelector:
eks.amazonaws.com/nodegroup: managed-ng-private-1
Upvotes: 0
Reputation: 54249
Specify it like normal in the volumes
section of the pod spec template. But you won't get the special behavior of creating a new PVC for each replica since that requires creating new ones.
Upvotes: 5