Skip to content

Latest commit

 

History

History
36 lines (20 loc) · 1.39 KB

File metadata and controls

36 lines (20 loc) · 1.39 KB

Kubernetes Custom Resource Definition (CRD)

One of the ways to extend Kubernetes is to write your own Custom Resource Definition (CRD). This allows you to extend the KRM with your own "types", like this:

  1. Let's first look at the built-in KRM API resource "types", and note e.g. the Pod we used in the previous lesson:

     k api-resources
    
  2. Glance at, and then apply, the foo.crd.yaml:

    k apply -f https://raw.githubusercontent.com/vorburger/LearningKubernetes-CodeLabs/develop/docs/files/foo.crd.yaml
    
  3. This has created a new (custom) KRM API resource kind, named foo. It now appears on the API:

    k api-resources | grep foo
    
    k explain foo
    k explain foo.spec
    
  4. We can now create a new resource of this kind, e.g. by applying the hello.foo.yaml:

    k apply -f https://raw.githubusercontent.com/vorburger/LearningKubernetes-CodeLabs/develop/docs/files/hello.foo.yaml
    
  5. You now have a Foo. Let's list it, look at it's YAML:

    k get foos
    k get foo hello -o yaml
    
  6. Try to edit it, and change "xyz" from "7" to "13", and not the validation error you'll get, xyz =< 10:

    k edit foo hello
    
  7. Clean up:

    k delete foo hello