我创建了一个 StatefulSet 用于运行具有 3 个副本的 NodeJS,并希望附加到一个 gce 磁盘,该磁盘可以成为用户上传文件的数据存储。
我的项目命名:carx;服务器名称:汽车服务器
但是,在创建第二个 pod 时出现错误。
kubectl describe pod car-server-statefulset-1
卷“my-app-data”的 AttachVolume.Attach 失败:googleapi:错误 400:RESOURCE_IN_USE_BY_ANOTHER_RESOURCE - 磁盘资源“projects/.../disks/carx-disk”已被“projects/.../instances”使用/gke-cluster-...-2dw1'
汽车服务器-statefulset.yml
apiVersion: v1
kind: Service
metadata:
name: car-server-service
labels:
app: car-server
spec:
ports:
- port: 8080
name: car-server
clusterIP: None
selector:
app: car-server
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: car-server-statefulset
spec:
serviceName: "car-server-service"
replicas: 3
template:
metadata:
labels:
app: car-server
spec:
containers:
- name: car-server
image: myimage:latest
ports:
- containerPort: 8080
name: nodejs-port
volumeMounts:
- name: my-app-data
mountPath: /usr/src/app/mydata
volumes:
- name: my-app-data
persistentVolumeClaim:
claimName: example-local-claim
selector:
matchLabels:
app: car-server
pvc.yml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: example-local-claim
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
storageClassName: standard
pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-app-data
labels:
app: my-app
spec:
capacity:
storage: 60Gi
storageClassName: standard
accessModes:
- ReadWriteMany
gcePersistentDisk:
pdName: carx-disk
fsType: ext4