Cloud Intermediate
Kubernetes CRDs — Custom Resource Definitions¶
KubernetesCRDAPIExtensibility 5 min read
Extending the Kubernetes API with custom resource types. CRD definitions, validation, versioning and best practices.
What Are CRDs¶
Custom Resource Definitions extend the Kubernetes API with custom object types.
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: databases.example.com
spec:
group: example.com
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
required: [engine, version]
properties:
engine:
type: string
enum: [postgres, mysql, mongodb]
version:
type: string
replicas:
type: integer
minimum: 1
maximum: 7
default: 3
scope: Namespaced
names:
plural: databases
singular: database
kind: Database
shortNames: [db]
Using a Custom Resource¶
apiVersion: example.com/v1
kind: Database
metadata:
name: orders-db
namespace: production
spec:
engine: postgres
version: "16"
replicas: 3
# kubectl get databases
# kubectl describe db orders-db
Versioning¶
CRDs support multiple versions with a conversion webhook.
versions:
- name: v1
served: true
storage: true
- name: v1beta1
served: true
storage: false
conversion:
strategy: Webhook
webhook:
conversionReviewVersions: ["v1"]
clientConfig:
service:
name: db-conversion
namespace: system
path: /convert
Summary¶
CRDs are the foundation of Kubernetes extensibility. They enable declarative management of any infrastructure via kubectl and the standard K8s API.
Need Help with Implementation?¶
Our team has experience designing and implementing modern architectures. We’re happy to help.