Skip to content

Latest commit

 

History

History
106 lines (84 loc) · 2.07 KB

i.crd.md

File metadata and controls

106 lines (84 loc) · 2.07 KB

Extend the Kubernetes API with CRD (CustomResourceDefinition)

  • Note: CRD is part of the new CKAD syllabus. Here are a few examples of installing custom resource into the Kubernetes API by creating a CRD.

CRD in K8s

Create a CustomResourceDefinition manifest file for an Operator with the following specifications :

  • Group : stable.example.com
  • Schema: <email: string><name: string><age: integer>
  • Scope: Namespaced
  • Names: <plural: operators><singular: operator><shortNames: op>
show

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: operators.stable.example.com
spec:
  group: stable.example.com
  versions:
    - name: v1
      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:
                email:
                  type: string
                name:
                  type: string
                age:
                  type: integer
  scope: Namespaced
  names:
    plural: operators
    singular: operator
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: Operator
    shortNames:
    - op

Create the CRD resource in the K8S API

show

kubectl apply -f operator-crd.yml

Create custom object from the CRD

show

apiVersion: stable.example.com/v1
kind: Operator
metadata:
  name: operator-sample
spec:
  email: operator-sample@stable.example.com
  name: "operator sample"
  age: 30
kubectl apply -f operator.yml

Listing operator

show

Use singular, plural and short forms

kubectl get operators

kubectl get operator

kubectl get op