So i try to set each pod in the StatefulSet should be manually assigned a specific PVC without use volumeClaimTemplates.
I use the petch for each pods and statefulset also but there are not working.
So this is my pvc.yaml file code :
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: busybox-pvc-0
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: busybox-pvc-1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: busybox-pvc-2
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
and this is my statefullset.yaml code :
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: busybox
spec:
serviceName: "busybox-service"
replicas: 3
selector:
matchLabels:
app: busybox
template:
metadata:
labels:
app: busybox
spec:
containers:
- name: busybox
image: busybox
command: ["/bin/sh", "-c", "sleep 3600"]
volumeMounts:
- name: busybox-storage
mountPath: /mnt/data
volumes:
- name: busybox-storage
persistentVolumeClaim:
claimName: busybox-pvc-0
and i try to use “petch” like this but there are get error like this:
dev_2@Tadhak-dev-02:~/Backup/Opensearch/Stateful_PVC$ minikube kubectl -- patch pod busybox-0 --type='json' -p '[{"op": "replace", "path": "/
spec/volumes/0/persistentVolumeClaim/claimName", "value": "busybox-pvc-0"}]'
The request is invalid: the server rejected our request due to an error in our request
dev_2@Tadhak-dev-02:~/Backup/Opensearch/Stateful_PVC$ minikube kubectl -- patch pod busybox-1 --type='json' -p '[{"op": "replace", "path": "/spec/volumes/0/persistentVolumeClaim/claimName", "value": "busybox-pvc-1"}]'
The Pod "busybox-1" is invalid: spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`,`spec.initContainers[*].image`,`spec.activeDeadlineSeconds`,`spec.tolerations` (only additions to existing tolerations),`spec.terminationGracePeriodSeconds` (allow it to be set to 1 if it was previously negative)
core.PodSpec{
Volumes: []core.Volume{
{
Name: "busybox-storage",
VolumeSource: core.VolumeSource{
... // 7 identical fields
ISCSI: nil,
Glusterfs: nil,
PersistentVolumeClaim: &core.PersistentVolumeClaimVolumeSource{
- ClaimName: "busybox-pvc-0",
+ ClaimName: "busybox-pvc-1",
ReadOnly: false,
},
RBD: nil,
Quobyte: nil,
... // 18 identical fields
},
},
{Name: "kube-api-access-jzfbk", VolumeSource: {Projected: &{Sources: {{ServiceAccountToken: &{ExpirationSeconds: 3607, Path: "token"}}, {ConfigMap: &{LocalObjectReference: {Name: "kube-root-ca.crt"}, Items: {{Key: "ca.crt", Path: "ca.crt"}}}}, {DownwardAPI: &{Items: {{Path: "namespace", FieldRef: &{APIVersion: "v1", FieldPath: "metadata.namespace"}}}}}}, DefaultMode: &420}}},
},
InitContainers: nil,
Containers: {{Name: "busybox", Image: "busybox", Command: {"/bin/sh", "-c", "sleep 3600"}, VolumeMounts: {{Name: "busybox-storage", MountPath: "/mnt/data"}, {Name: "kube-api-access-jzfbk", ReadOnly: true, MountPath: "/var/run/secrets/kubernetes.io/serviceaccount"}}, ...}},
... // 30 identical fields
}
So how to do this working for set each pod in the StatefulSet should be manually assigned a specific PVC without use volumeClaimTemplates.
busybox-0 → busybox-pvc-0
busybox-1 → busybox-pvc-1
busybox-2 → busybox-pvc-2
Kubernetes version:
Client Version: v1.31.0
Kustomize Version: v5.4.2
Server Version: v1.31.0