【问题标题】:Kubernetes statefulset : other than 'replicas', 'template', and 'updateStrategy' are forbiddenKubernetes statefulset:除了'replicas'、'template'和'updateStrategy'是被禁止的
【发布时间】:2021-06-17 17:10:06
【问题描述】:

注意:nfs 服务器和权限都很好,我检查了 PV 和 PVC 正在创建正常只有 statefulSet 给我这个错误。

错误消息:StatefulSet "auth-mongo-ss" 无效:spec: Forbidden: 禁止对除 'replicas'、'template' 和 'updateStrategy' 以外的字段的 statefulset 规范进行更新 (错误消息很简单,但没有帮助解决它!我在这里错过了什么?)

Kubernetes(minkube) 版本:

客户端版本:v1.20.2 服务器版本:v1.20.2

操作系统:

Linux mint - 20

apiVersion: v1
kind: PersistentVolume
metadata:
  name: auth-pv
spec:
  capacity:
    storage: 250Mi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: manual
  nfs:
    path: /nfs/auth
    server: 192.168.10.104
---
apiVersion: v1
kind: Service
metadata:
  name: auth-mongo-serv
  labels:
    app: auth-mongo-serv
spec:
  ports:
    - name: db
      protocol: TCP
      port: 27017
      targetPort: 27017
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: auth-mongo-ss
spec:
  selector:
    matchLabels:
      app: auth-mongo-serv # has to match .spec.template.metadata.labels
  serviceName: auth-mongo-ss
  replicas: 1 # by default is 1
  template:
    metadata:
      labels:
        app: auth-mongo-serv # has to match .spec.selector.matchLabels
    spec:
      terminationGracePeriodSeconds: 10
      containers:
        - name: auth-mongo-docker
          image: mongo
          ports:
            - containerPort: 27017
          resources:
            limits:
              memory: "250Mi"
              cpu: "250m"
          volumeMounts:
            - name: auth-mongo-data
              mountPath: /data/db
  volumeClaimTemplates:
    - metadata:
        name: auth-mongo-data
      spec:
        storageClassName: manual
        accessModes: ["ReadWriteMany"]
        resources:
          requests:
            storage: 250Mi
    ```

【问题讨论】:

  • 您可能正在尝试更改现有 statefulset 上的 spec 字段,而不是 replicastemplateupdateStrategy,这是不允许的,您需要删除现有的 statefulset 并创建一个新的。
  • 谢谢,Krishna,我已经删除了旧的,又用新的,但仍然没有工作。另外,我从官方 Kubernetes 文档中获取了 statefulset 的样本。我遗漏了一些非常小的东西(或做错了我无法捕捉的配置)。

标签: kubernetes minikube


【解决方案1】:

错误spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden 说明一切。

StatefultSet 中,只有可变(您可以更改/更新)是replicastemplateupdateStrategy。除了Spec 中的这些字段之外,您无法在更新期间更改其他字段。

更新

您有多个问题:

  1. 在你使用serviceName: auth-mongo-ssStatefuleSet规范中,你有这个无头服务吗?

  2. 在此服务规范中您没有提供selector

apiVersion: v1
kind: Service
metadata:
  name: auth-mongo-serv
  labels:
    app: auth-mongo-serv
spec:
  ports:
    - name: db
      protocol: TCP
      port: 27017
      targetPort: 27017

下面给出了来自 k8s 文档的 StatefulSet 示例,对于 statefulset,您需要一个无头服务。

apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: nginx # has to match .spec.template.metadata.labels
  serviceName: "nginx"
  replicas: 3 # by default is 1
  template:
    metadata:
      labels:
        app: nginx # has to match .spec.selector.matchLabels
    spec:
      terminationGracePeriodSeconds: 10
      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: "my-storage-class"
      resources:
        requests:
          storage: 1Gi

【讨论】:

  • 谢谢,shahadat,如果不允许我更改规范,我将如何将 mongo 配置添加到规范中?与volumenClaim。我是 kubernetes 的新手,所以我知道的基本问题可能是 :)
  • 删除旧的并用你想要的东西创建新的
  • 请看问题中的cmets,他已经试过了,还是不行。
  • @KrishnaChaurasia 我第一次没有注意到 cmets,我的错!我已经更新了我的答案
  • 使用 StackOverflow 的时间太长了。让我找到并做。
猜你喜欢
  • 2018-08-24
  • 1970-01-01
  • 2018-10-26
  • 2019-05-23
  • 1970-01-01
  • 2020-02-10
  • 1970-01-01
  • 2021-05-23
  • 1970-01-01
相关资源
最近更新 更多