본문 바로가기
K8S

kubernetes CRD v1에서 작성 방법 (no matches for kind "CustomResourceDefinition" in version "apiextensions.k8s.io/v1beta1", "v1" cannot be handled as a CustomResourceDefinition: strict decoding error: unknown field "spec.version")

by Rainbound-IT 2023. 8. 19.
반응형

증상

아래명령어를 입력

kubectl apply -f .\test-crd.yaml

 

error: resource mapping not found for name: "test.extension.example.com" namespace: "" from ".\\test-crd.yaml": no matches for kind "CustomResourceDefinition" in version "apiextensions.k8s.io/v1beta1"

 

원인

v1beta1이 1.16부터 지원되지 않는다.

 

apiVersion: apiextensions.k8s.io/v1

로 변경하면 이런 에러가 나오는데

Error from server (BadRequest): error when creating ".\\test-crd.yaml": CustomResourceDefinition in version "v1" cannot be handled as a CustomResourceDefinition: strict decoding error: unknown field "spec.version"

 

 

해결

다음과 같이 version 부분을 변경해야한다.

apiVersion: apiextensions.k8s.io/v1
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:
                cronSpec:
                  type: string
                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

 

 

reference version 

https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/

 

 

반응형

댓글