redis-cluster-operator icon indicating copy to clipboard operation
redis-cluster-operator copied to clipboard

kubectl v1.23.4: no matches for kind "CustomResourceDefinition" in version "apiextensions.k8s.io/v1beta1"

Open undo-nothing opened this issue 2 years ago • 5 comments

kubectl version -o yaml clientVersion: buildDate: "2022-02-16T12:38:05Z" compiler: gc gitCommit: e6c093d87ea4cbb530a7b2ae91e54c0842d8308a gitTreeState: clean gitVersion: v1.23.4 goVersion: go1.17.7 major: "1" minor: "23" platform: linux/amd64 serverVersion: buildDate: "2022-02-16T12:32:02Z" compiler: gc gitCommit: e6c093d87ea4cbb530a7b2ae91e54c0842d8308a gitTreeState: clean gitVersion: v1.23.4 goVersion: go1.17.7 major: "1" minor: "23" platform: linux/amd64

运行 kubectl create -f redis.kun_distributedredisclusters_crd.yaml

报错: error: unable to recognize "redis.kun_distributedredisclusters_crd.yaml": no matches for kind "CustomResourceDefinition" in version "apiextensions.k8s.io/v1beta1"

原因: kubernetes 版本 1.22删除了 CustomResourceDefinition "apiextensions.k8s.io/v1beta1" api

改成 apiextensions.k8s.io/v1 后运行: kubectl create -f redis.kun_distributedredisclusters_crd.yaml 报错: error: error validating "redis.kun_distributedredisclusters_crd.yaml": error validating data: [ValidationError(CustomResourceDefinition.spec): unknown field "additionalPrinterColumns" in io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionSpec, ValidationError(CustomResourceDefinition.spec): unknown field "subresources" in io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionSpec, ValidationError(CustomResourceDefinition.spec): unknown field "validation" in io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionSpec, ValidationError(CustomResourceDefinition.spec): unknown field "version" in io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionSpec]; if you choose to ignore these errors, turn validation off with --validate=false

undo-nothing avatar Mar 10 '22 01:03 undo-nothing

kubernetes 1.22 https://kubernetes.io/docs/reference/using-api/deprecation-guide/

dblife1024 avatar Apr 28 '22 09:04 dblife1024

Tried adapting for kubernetes version v1.22+

# Thus this yaml has been adapted for k8s v1.22 as per:
# https://kubernetes.io/docs/reference/using-api/deprecation-guide/#customresourcedefinition-v122
#
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: distributedredisclusters.redis.kun
spec:
  group: redis.kun
  names:
    kind: DistributedRedisCluster
    listKind: DistributedRedisClusterList
    plural: distributedredisclusters
    singular: distributedrediscluster
    shortNames:
    - drc
  scope: Namespaced
  versions:
  - name: v1alpha1
    served: true
    storage: true
    subresources:
      status: {}
    additionalPrinterColumns:
      - name: MasterSize
        jsonPath: .spec.masterSize
        description: The number of redis master node in the ensemble
        type: integer
      - name: Status
        jsonPath: .status.status
        description: The status of redis cluster
        type: string
      - name: Age
        jsonPath: .metadata.creationTimestamp
        type: date
      - name: CurrentMasters
        jsonPath: .status.numberOfMaster
        priority: 1
        description: The current master number of redis cluster
        type: integer
      - name: Images
        jsonPath: .spec.image
        priority: 1
        description: The image of redis cluster
        type: string
    schema:
      openAPIV3Schema:
        description: DistributedRedisCluster is the Schema for the distributedredisclusters API
        type: object
        properties:
          apiVersion:
            description: 'APIVersion defines the versioned schema of this representation
              of an object. Servers should convert recognized schemas to the latest
              internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
            type: string
          kind:
            description: 'Kind is a string value representing the REST resource this
              object represents. Servers may infer this from the endpoint the client
              submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
            type: string
          metadata:
            type: object
          spec:
            description: DistributedRedisClusterSpec defines the desired state of DistributedRedisCluster
            type: object
            properties:
              masterSize:
                format: int32
                type: integer
                minimum: 1
                maximum: 3
              clusterReplicas:
                format: int32
                type: integer
                minimum: 1
                maximum: 3
              serviceName:
                type: string
                pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
              annotations:
                additionalProperties:
                  type: string
                type: object
              config:
                additionalProperties:
                  type: string
                type: object
              passwordSecret:
                additionalProperties:
                  type: string
                type: object
              storage:
                type: object
                properties:
                  type:
                    type: string
                  size:
                    type: string
                  class:
                    type: string
                  deleteClaim:
                    type: boolean
              image:
                type: string
              securityContext:
                description: 'SecurityContext defines the security options the container should be run with'
                type: object
                properties:
                  allowPrivilegeEscalation:
                    type: boolean
                  privileged:
                    type: boolean
                  readOnlyRootFilesystem:
                    type: boolean
                  capabilities:
                    type: object
                    properties:
                      add:
                        items:
                          type: string
                        type: array
                      drop:
                        items:
                          type: string
                        type: array
                  sysctls:
                    items:
                      type: object
                      properties:
                        name:
                          type: string
                        value:
                          type: string
                      required:
                        - name
                        - value
                    type: array
              resources:
                type: object
                properties:
                  requests:
                    type: object
                    additionalProperties:
                      type: string
                  limits:
                    type: object
                    additionalProperties:
                      type: string
              toleRations:
                type: array
                items:
                  type: object
                  properties:
                    effect:
                      type: string
                    key:
                      type: string
                    operator:
                      type: string
                    tolerationSeconds:
                      type: integer
                      format: int64
                    value:
                      type: string
          status:
            description: DistributedRedisClusterStatus defines the observed state of DistributedRedisCluster
            type: object
            properties:
              numberOfMaster:
                type: integer
                format: int32
              reason:
                type: string
              status:
                type: string
              maxReplicationFactor:
                type: integer
                format: int32
              minReplicationFactor:
                type: integer
                format: int32
              status:
                type: string
              reason:
                type: string

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: redisclusterbackups.redis.kun
spec:
  group: redis.kun
  names:
    kind: RedisClusterBackup
    listKind: RedisClusterBackupList
    plural: redisclusterbackups
    singular: redisclusterbackup
    shortNames:
      - drcb
  scope: Namespaced
  versions:
    - name: v1alpha1
      # 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
      subresources:
        status: {}
      additionalPrinterColumns:
        - jsonPath: .metadata.creationTimestamp
          name: Age
          type: date
        - jsonPath: .status.phase
          description: The phase of redis cluster backup
          name: Phase
          type: string
      schema:
        openAPIV3Schema:
          description: RedisClusterBackup is the Schema for the redisclusterbackups
            API
          properties:
            apiVersion:
              description: 'APIVersion defines the versioned schema of this representation
                of an object. Servers should convert recognized schemas to the latest
                internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
              type: string
            kind:
              description: 'Kind is a string value representing the REST resource this
                object represents. Servers may infer this from the endpoint the client
                submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
              type: string
            metadata:
              type: object
            spec:
              description: RedisClusterBackupSpec defines the desired state of RedisClusterBackup
              type: object
            status:
              description: RedisClusterBackupStatus defines the observed state of RedisClusterBackup
              type: object
          type: object

komuw avatar Nov 11 '22 10:11 komuw

@komuw Hi, After I created crd according to the configuration you sent, I created a redis cluster and reported an error:

error: error validating "/tmp/redis-cluster/redis-cluster.yaml": error validating data: [ValidationError(DistributedRedisCluster.spec): unknown field "config" in kun.redis.v1alpha1.DistributedRedisCluster.spec, ValidationError(DistributedRedisCluster.spec): unknown field "image" in kun.redis.v1alpha1.DistributedRedisCluster.spec, ValidationError(DistributedRedisCluster.spec): unknown field "monitor" in kun.redis.v1alpha1.DistributedRedisCluster.spec, ValidationError(DistributedRedisCluster.spec): unknown field "passwordSecret" in kun.redis.v1alpha1.DistributedRedisCluster.spec, ValidationError(DistributedRedisCluster.spec): unknown field "resources" in kun.redis.v1alpha1.DistributedRedisCluster.spec, ValidationError(DistributedRedisCluster.spec): unknown field "storage" in kun.redis.v1alpha1.DistributedRedisCluster.spec]; if you choose to ignore these errors, turn validation off with --validate=false

redis-cluster yaml config:

apiVersion: redis.kun/v1alpha1
kind: DistributedRedisCluster
metadata:
  annotations:
    # if your operator run as cluster-scoped, add this annotations
    redis.kun/scope: cluster-scoped
  name: example-distributedrediscluster
spec:
  masterSize: 3
  clusterReplicas: 1
  image: redis:6.2.7-alpine
  serviceName: redis-svc
  monitor:
    image: oliver006/redis_exporter
  passwordSecret:
      name: redissecret
  resources:
    limits:
      cpu: 2
      memory: 4Gi
    requests:
      cpu: 2
      memory: 4Gi
  storage:
    type: persistent-claim
    size: 1Gi
    class: nfs
    deleteClaim: true
  config:
    activerehashing: "yes"
    appendfsync: everysec
    appendonly: "no"
    hash-max-ziplist-entries: "512"
    hash-max-ziplist-value: "64"
    hll-sparse-max-bytes: "3000"
    list-compress-depth: "0"
    maxmemory-policy: volatile-lru
    maxmemory-samples: "5"
    no-appendfsync-on-rewrite: "no"
    notify-keyspace-events: ""
    set-max-intset-entries: "512"
    slowlog-log-slower-than: "10000"
    slowlog-max-len: "128"
    stop-writes-on-bgsave-error: "yes"
    tcp-keepalive: "0"
    timeout: "0"
    zset-max-ziplist-entries: "128"
    zset-max-ziplist-value: "64"
    maxclients: "10000"

bogeit avatar Nov 15 '22 09:11 bogeit

@bogeit I have updated my comment; https://github.com/ucloud/redis-cluster-operator/issues/95#issuecomment-1311507954 Try with the update.

komuw avatar Nov 15 '22 15:11 komuw

@komuw Thank you very much, I succeeded according to your new yaml configuration, but under the premise of removing the monitor field, the error report of adding monitor is as follows:

error: error validating "redis-cluster.yaml": error validating data: ValidationError(DistributedRedisCluster.spec): unknown field "monitor" in kun.redis.v1alpha1.DistributedRedisCluster.spec; if you choose to ignore these errors, turn validation off with --validate=false

bogeit avatar Nov 16 '22 02:11 bogeit