So i try to set the manually assign Pvcs in the node wise Pods in kubernets So i have one Statefulset with 2 replicas and 2 PVCs The code is like this
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: busybox-pvc-0
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: standard # Change this if needed
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: busybox-pvc-1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: standard # Change this if needed
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: busybox
spec:
serviceName: "busybox"
replicas: 2
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-0
mountPath: /data0
- name: busybox-storage-1
mountPath: /data1
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- minikube
- minikube-m02
volumes:
- name: busybox-storage-0
persistentVolumeClaim:
claimName: busybox-pvc-0
- name: busybox-storage-1
persistentVolumeClaim:
claimName: busybox-pvc-1
So i try to do this code and see the reaction of this code the Output is
busybox-0 → minikube → busybox-pvc-0 , busybox-pvc-1 ,
busybox-1 → minikube-m02 → busybox-pvc-0 , busybox-pvc-1
but i want to this Output :
busybox-0 → minikube → busybox-pvc-0 ,
busybox-1 → minikube-m02 → busybox-pvc-1
in this outputs
Pods is busybox-0 , busybox-1 and Nodes is minikube , minikube-m02 and PVCs is busybox-pvc-0 , busybox-pvc-1
So i try to set the manually assign Pvcs in the node wise Pods in kubernets So i have one Statefulset with 2 replicas and 2 PVCs The code is like this
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: busybox-pvc-0
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: standard # Change this if needed
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: busybox-pvc-1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: standard # Change this if needed
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: busybox
spec:
serviceName: "busybox"
replicas: 2
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-0
mountPath: /data0
- name: busybox-storage-1
mountPath: /data1
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- minikube
- minikube-m02
volumes:
- name: busybox-storage-0
persistentVolumeClaim:
claimName: busybox-pvc-0
- name: busybox-storage-1
persistentVolumeClaim:
claimName: busybox-pvc-1
So i try to do this code and see the reaction of this code the Output is
busybox-0 → minikube → busybox-pvc-0 , busybox-pvc-1 ,
busybox-1 → minikube-m02 → busybox-pvc-0 , busybox-pvc-1
but i want to this Output :
busybox-0 → minikube → busybox-pvc-0 ,
busybox-1 → minikube-m02 → busybox-pvc-1
in this outputs
Share Improve this question asked Mar 21 at 6:25 om makwanaom makwana 91 bronze badge 4 |Pods is busybox-0 , busybox-1 and Nodes is minikube , minikube-m02 and PVCs is busybox-pvc-0 , busybox-pvc-1
1 Answer
Reset to default 0You've defined only one container, to be ran as 2 replicas.
spec:
containers:
- name: busybox
And you've attached both PVCs to that container
volumeMounts:
- name: busybox-storage-0
mountPath: /data0
- name: busybox-storage-1
mountPath: /data1
To achieve what you want, you should define them separately. Something like:
spec:
containers:
- name: busybox-0
volumeMounts:
- name: busybox-storage-0
mountPath: /data0
- name: busybox-1
volumeMounts:
- name: busybox-storage-1
mountPath: /data0
Same goes for the node affinity
volumeClaimTemplates:
to automatically create the PVCs; you wouldn't normally create them by hand. That won't help you manually place Pods or storage on specific nodes, but that's also not a typical pattern; why do you want more specific placement? – David Maze Commented Mar 21 at 10:06