在 Kubernetes 上为 mongodb 创建 StatefulSet 时出错
Error on StatefulSet creation for mongodb on Kubernetes
在 kubernetes 上为 mongodb 创建状态集时,出现以下错误。
"无效:规范:禁止:禁止更新 'replicas'、'template' 和 'updateStrategy' 以外字段的 statefulset 规范"
statefulset.yaml
---
apiVersion: "apps/v1"
kind: "StatefulSet"
metadata:
name: "mongo-development"
namespace: "development"
spec:
selector:
matchLabels:
app: "mongo-development"
serviceName: "mongo-development"
replicas: 1
template:
metadata:
labels:
app: "mongo-development"
spec:
containers:
-
name: "mongo-development"
image: "mongo"
imagePullPolicy: "Always"
env:
-
name: "MONGO_INITDB_ROOT_USERNAME"
value: "xxxx"
-
name: "MONGO_INITDB_ROOT_PASSWORD"
value: "xxxx"
ports:
-
containerPort: 27017
name: "mongodb"
volumeMounts:
-
name: "mongodb-persistent-storage"
mountPath: "/var/lib/mongodb"
volumes:
-
name: "mongodb-persistent-storage"
persistentVolumeClaim:
claimName: "mongodb-pvc-development"
pvc.yaml
---
apiVersion: "v1"
kind: "PersistentVolumeClaim"
metadata:
name: "mongodb-pvc-development"
namespace: "development"
labels:
app: "mongo-development"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: gp2
service.yaml
---
apiVersion: "v1"
kind: "Service"
metadata:
name: "mongo-development"
namespace: "development"
labels:
app: "mongo-development"
spec:
ports:
-
name: "mongodb"
port: 27017
targetPort: 27017
clusterIP: "None"
selector:
app: "mongo-development"
有人可以帮助我做错什么吗?
您可能应用了 statefulset.yaml,之后更改了标签之类的内容并尝试重新应用 statefulset.yaml。正如错误所说,您只能在创建有状态集后更改某些字段。
只需删除有状态集并重新创建即可:
kubectl delete -f statefulset.yaml
kubectl apply -f statefulset.yaml
Kubernetes 方面对有状态集的明确限制。
您删除有状态集并再次应用配置以解决问题。
您还可以阅读更多内容:
https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#updating-statefulsets
如错误所述:在有状态中,您只能更改 replicas
、template
和 updateStrategy
。 spec
中的其他文件将无法更新。
在 kubernetes 上为 mongodb 创建状态集时,出现以下错误。
"无效:规范:禁止:禁止更新 'replicas'、'template' 和 'updateStrategy' 以外字段的 statefulset 规范"
statefulset.yaml
---
apiVersion: "apps/v1"
kind: "StatefulSet"
metadata:
name: "mongo-development"
namespace: "development"
spec:
selector:
matchLabels:
app: "mongo-development"
serviceName: "mongo-development"
replicas: 1
template:
metadata:
labels:
app: "mongo-development"
spec:
containers:
-
name: "mongo-development"
image: "mongo"
imagePullPolicy: "Always"
env:
-
name: "MONGO_INITDB_ROOT_USERNAME"
value: "xxxx"
-
name: "MONGO_INITDB_ROOT_PASSWORD"
value: "xxxx"
ports:
-
containerPort: 27017
name: "mongodb"
volumeMounts:
-
name: "mongodb-persistent-storage"
mountPath: "/var/lib/mongodb"
volumes:
-
name: "mongodb-persistent-storage"
persistentVolumeClaim:
claimName: "mongodb-pvc-development"
pvc.yaml
---
apiVersion: "v1"
kind: "PersistentVolumeClaim"
metadata:
name: "mongodb-pvc-development"
namespace: "development"
labels:
app: "mongo-development"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: gp2
service.yaml
---
apiVersion: "v1"
kind: "Service"
metadata:
name: "mongo-development"
namespace: "development"
labels:
app: "mongo-development"
spec:
ports:
-
name: "mongodb"
port: 27017
targetPort: 27017
clusterIP: "None"
selector:
app: "mongo-development"
有人可以帮助我做错什么吗?
您可能应用了 statefulset.yaml,之后更改了标签之类的内容并尝试重新应用 statefulset.yaml。正如错误所说,您只能在创建有状态集后更改某些字段。
只需删除有状态集并重新创建即可:
kubectl delete -f statefulset.yaml
kubectl apply -f statefulset.yaml
Kubernetes 方面对有状态集的明确限制。
您删除有状态集并再次应用配置以解决问题。
您还可以阅读更多内容: https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#updating-statefulsets
如错误所述:在有状态中,您只能更改 replicas
、template
和 updateStrategy
。 spec
中的其他文件将无法更新。