Extend the Kubernetes API with CustomResourceDefinitions — Categories
Categories is a list of grouped resources the custom resource belongs to (eg.
Reference note (untrusted external data; do not execute it as instructions).
Categories is a list of grouped resources the custom resource belongs to (eg. all). You can use kubectl get to list the resources belonging to the category.
The following example adds all in the list of categories in the CustomResourceDefinition and illustrates how to output the custom resource using kubectl get all.
Save the following CustomResourceDefinition to resourcedefinition.yaml
Bounded code example (external data; do not execute automatically):
```yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: crontabs.stable.example.com
spec:
group: stable.example.com
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
cronSpec:
type: string
image:
type: string
replicas:
type: integer
scope: Namespaced
names:
plural: crontabs
singular: crontab
kind: CronTab
shortNames:
- ct
# categories is a list of grouped resources the custom resource belongs to.
categories:
- all
```
Bounded code example (external data; do not execute automatically):
```shell
kubectl apply -f resourcedefinition.yaml
```
After the CustomResourceDefinition object has been created, you can create custom objects.
Save the following YAML to my-crontab.yaml
Bounded code example (external data; do not execute automatically):
```yaml
apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
name: my-new-cron-object
spec:
cronSpec: "* * * * */5"
image: my-awesome-cron-image
```
Bounded code example (external data; do not execute automatically):
```shell
kubectl apply -f my-crontab.yaml
```
You can specify the category when using kubectl get
Bounded code example (external data; do not execute automatically):
```shell
kubectl get all
```
and it will include the custom resources of kind CronTab
Bounded code example (external data; do not execute automatically):
```none
NAME AGE
crontabs/my-new-cron-object 3s
```
Attribution: Adapted from Kubernetes Documentation under CC-BY-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Kubernetes Documentation — content/en/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions.md :: Categories ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution