How to Create Custom Resources in Kubernetes

Extend Kubernetes API with CRDs

Planted .

To create custom resources:

  1. Create a CRD.
  2. Apply using kubectl apply -f
  3. You can check existing CRDs using kubectl get crd
  4. Create a new resource file.
apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image
  1. Apply using kubectl apply -f
  2. Then you can get that custom resource using kubectl get <resourcename>

So, if you did not create the CRD yourself, you can do this:

  1. Get the crd, example: kubectl get crd globals.traffic.controller -o yaml
  2. Create the resource file:
apiVersion: traffic.controller/v1
kind: Global
metadata:
  name: datacenter
spec:
  dataField: 2
  access: true
  1. And then apply
Updated . Thoughts? Email me.