Create Custom Objects

This workshop has been deprecated and archived. The new Amazon EKS Workshop is now available at

After the CustomResourceDefinition object has been created, you can create custom objects. Custom objects can contain custom fields. These fields can contain arbitrary JSON. In the following example, the cronSpec and image custom fields are set in a custom object of kind CronTab. The kind CronTab comes from the spec of the CustomResourceDefinition object you created above.

If you save the following YAML to my-crontab.yaml:

cat <<EoF > ~/environment/my-crontab.yaml
apiVersion: ""
kind: CronTab
  name: my-new-cron-object
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image

and create it:

kubectl apply -f my-crontab.yaml

You can then manage your CronTab objects using kubectl. For example:

kubectl get crontab

Should print a list like this:

NAME                 AGE
my-new-cron-object   6s

Resource names are not case-sensitive when using kubectl, and you can use either the singular or plural forms defined in the CRD, as well as any short names.

You can also view the raw YAML data:

kubectl get ct -o yaml

You should see that it contains the custom cronSpec and image fields from the yaml you used to create it:

apiVersion: v1
- apiVersion:
  kind: CronTab
    creationTimestamp: "2022-07-15T12:15:25Z"
    generation: 1
    name: my-new-cron-object
    namespace: default
    resourceVersion: "822447"
    uid: d6698dd8-69f4-4ffa-9e83-0549f7162cdd
    cronSpec: '* * * * */5'
    image: my-awesome-cron-image
kind: List
  resourceVersion: ""
  selfLink: ""

We can also describe the custom object with kubectl:

kubectl describe crontab

The output being something like this:

Name:         my-new-cron-object
Namespace:    default
Labels:       <none>
Annotations:  <none>
API Version:
Kind:         CronTab
  Creation Timestamp:  2022-07-15T12:15:25Z
  Generation:          1
  Managed Fields:
    API Version:
    Fields Type:  FieldsV1

    Manager:         kubectl-client-side-apply
    Operation:       Update
    Time:            2022-07-15T12:15:25Z
  Resource Version:  822447
  UID:               d6698dd8-69f4-4ffa-9e83-0549f7162cdd
  Cron Spec:  * * * * */5
  Image:      my-awesome-cron-image
Events:       <none>

Or we can check the resource directly from the Kubernetes API. First, we start the proxy in one tab of the Cloud9 environment:

kubectl proxy --port=8080 --address='' --disable-filter=true

And in another tab we check the existance of the Custom Resource

curl -i

With the output:

HTTP/1.1 200 OK
Audit-Id: 1d451453-0edf-49ea-95d3-612d64070a53
Cache-Control: no-cache, private
Content-Length: 943
Content-Type: application/json
Date: Fri, 15 Jul 2022 12:52:47 GMT
X-Kubernetes-Pf-Flowschema-Uid: 16b0834b-6ac6-4b7e-8b43-505208a6efc8
X-Kubernetes-Pf-Prioritylevel-Uid: f3c0805c-6d2b-493b-a958-724b2adeb80b

{"apiVersion":"","kind":"CronTab","metadata":{"annotations":{"":"{\"apiVersion\":\"\",\"kind\":\"CronTab\",\"metadata\":{\"annotations\":{},\"name\":\"my-new-cron-object\",\"namespace\":\"default\"},\"spec\":{\"cronSpec\":\"* * * * */5\",\"image\":\"my-awesome-cron-image\"}}\n"},"creationTimestamp":"2022-07-15T12:15:25Z","generation":1,"managedFields":[{"apiVersion":"","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:annotations":{".":{},"":{}}},"f:spec":{".":{},"f:cronSpec":{},"f:image":{}}},"manager":"kubectl-client-side-apply","operation":"Update","time":"2022-07-15T12:15:25Z"}],"name":"my-new-cron-object","namespace":"default","resourceVersion":"822447","uid":"d6698dd8-69f4-4ffa-9e83-0549f7162cdd"},"spec":{"cronSpec":"* * * * */5","image":"my-awesome-cron-image"}}