Kubernetes Custom Resource Definition (CRDs)

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: foxcrds.foxutech.com
spec:
group: foxutech.com
names:
kind: foxcrds
listKind: foxcrdslist
plural: foxcrds
singular: foxcrd
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: foxcrd is the foxutech custom resource definition
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/sig-architecture/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/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: foxcrdsSpoc is the spec for a foxcrds resource
type: object
properties:
title:
type: string
author:
type: string
status:
description: foxcrdsStatus is the status for a foxcrds resource
type: object
properties:
publishedAt:
type: string
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
  • The first two lines defines what the apiversion is and we are saying we want to create a custom resource definition.
  • The metadata field helps us define what the name of the resource is. In our case foxcrds (plural).
  • Spec group help us define what the group name will be.
  • Spec version helps us define the version. In our case we are versioning it as v1.
  • As you can see, we can define a version of our CRD and only one version can be a storage version at a time, so keep that in mind. We then made sure that this CRD is a namespaced and not cluster wide. This allows us to create the CRD for either just a specific namespace or for the whole cluster.
  • Next, we defined what the singular and plural name of our CRD will be.
  • Lastly, we defined the kind name and the short name. We can then create it with “kubectl create -f crd.yaml”. The new namespaced RESTful API endpoint for our CRD will be found at /apis/stable.example.com/v1/namespaces/*/foxcrds/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
FoxuTech

FoxuTech

Discuss about #Linux, #DevOps, #Docker, #kubernetes, #HowTo’s, #cloud & IT technologies like #argocd #crossplane #azure https://foxutech.com/