我是k8的新手,并尝试更新StatefulSet中的storageClassName。(从默认值更改为default-t1,仅在yaml中更改)
我尝试运行kubectl apply -f test.yaml
第一和第二Yaml(用于更新)的唯一区别是storageClassName:default-t1而不是default
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
podManagementPolicy: "Parallel"
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: default
resources:
requests:
storage: 1Gi
每次尝试更新时,我都会得到The StatefulSet "web" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden
我缺少什么或者应该采取什么步骤?
答案 0 :(得分:0)
StatefulSet的第一行应定义一个“ apiVersion”,您可以在此处statefulset看到示例。请在第一行中添加它:
apiVersion: apps/v1
您能告诉我“ www” PVC文件的输出吗?
kubectl get pvc www -o yaml
在PVC中,您有一个字段“ storageClassName”,该字段应在要使用的StorageClass上设置,因此在您的情况下为:
storageClassName: default-t1
答案 1 :(得分:0)
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
podManagementPolicy: "Parallel"
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: <storage class name>
resources:
requests:
storage: 1Gi
在上面的文件中添加存储类,您可以像这样应用它。
kubectl apply -f .yaml