0

如何在将现有对象手动升级到 kubernetes 自定义资源中的新存储版本时从“status.storedVersions”中删除版本

CRD 的 apiVersion:apiextensions.k8s.io/v1beta1

使用 aws EKS

CRD YAML

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: crontabs.stable.example.com
spec:
  # group name to use for REST API: /apis/<group>/<version>
  group: stable.example.com
  # list of versions supported by this CustomResourceDefinition
  versions:
    - name: v1
      # Each version can be enabled/disabled by Served flag.
      served: true
      # One and only one version must be marked as the storage version.
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                image:
                  type: string
                replicas:
                  type: integer
  # either Namespaced or Cluster
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: crontabs
    # singular name to be used as an alias on the CLI and for display
    singular: crontab
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: CronTab
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - ct

并将 CRD 升级到 v2

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: crontabs.stable.example.com
spec:
  # group name to use for REST API: /apis/<group>/<version>
  group: stable.example.com
  # list of versions supported by this CustomResourceDefinition
  versions:
    - name: v2
      # Each version can be enabled/disabled by Served flag.
      served: true
      # One and only one version must be marked as the storage version.
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                image:
                  type: string
                replicas:
                  type: integer
    - name: v1
      # Each version can be enabled/disabled by Served flag.
      served: false
      # One and only one version must be marked as the storage version.
      storage: false
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                image:
                  type: string
                replicas:
                  type: integer
  # either Namespaced or Cluster
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: crontabs
    # singular name to be used as an alias on the CLI and for display
    singular: crontab
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: CronTab
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - ct

禁用版本 v1 后,我想将其从版本列表中删除,我需要将其从 status.storedVersions 中删除,我该怎么做才能让 kubernetes 文档没有提供有关该内容的详细信息

4

2 回答 2

1

还有另一种status.specVersion使用集群 API 删除的方法。

状态下的字段通过状态子资源修改:

curl -d '[{ "op": "replace", "path":"/status/storedVersions", "value": ["v2"] }]' \
  -H "Content-Type: application/json-patch+json" \
  -X PATCH \
 http://localhost:8080/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/crontabs.stable.example.com/status

要访问 API,您需要先连接到集群文档

于 2020-01-31T13:37:55.463 回答
0

我在 Minikube、Kubeadm、GKE 上尝试了许多不同的选项,但所有地方的输出都是相同的。

不幸的是,使用它是不可能的,而且kubectl文档Remove the old version from the CustomResourceDefinition spec.versions list有点误导。

一旦定义落入specVersion,就不可能删除它。storage: true将其放入storedVersions列表中。

这个 Github 线程中有很好的描述,尤其是来自@sebgl 的评论。

IUC 正确地验证了 CRD 的方式,似乎不可能轻松地更新 CRD 以删除旧版本。

更新 CRD 时:

  • 预期的 storedVersions 列表是根据之前 CRD 中的 status.StoredVersions + 新 CRD 中较新的 storedVersions 构建的
  • 此 storedVersions 列表被传递给验证函数,该函数检查所有预期的 storedVersions 是否仍存在于新 CRD 中

CRD 历史中所有服务的版本最终都在状态中。对 CRD 状态的任何更新都是不可能的。对 CRD 版本的任何更新都包括删除状态中存在的版本是不可能的。

但是,他也提到可以使用operator-lifecycle-manager来完成。

可以在此处找到以编程方式更新 CRD 。这将绕过 CRD 的验证storedVersion

于 2020-01-29T10:54:48.293 回答