0

Worked with CRDs a bit so far. Recently a colleague of mine claimed that custom resources only ever manage pods in the end. Is this true? Can you do CRDs for services or config maps as well?

User12547645
  • 6,955
  • 3
  • 38
  • 69

2 Answers2

3

A custom resource definition doesn't manage anything. It is just a definition for some specific API group, version, and kind (as you see at the top of a Kubernetes manifest) that is not part of the standard Kubernetes API. If you've installed a CRD then you can kubectl get customtypename and run similar commands, but nothing actually happens as a result of creating one of these objects.

The other part of the typical operator pattern is a Kubernetes controller. This is a program, that usually runs inside the cluster, that uses the Kubernetes API to take some action.

A controller can read and write any Kubernetes resource; it is not limited to Pods. You could, for example, create a ConfigMap in response to a custom resource changing, or reference a ConfigMap in your custom resource and combine those two data to invoke some external API.

David Maze
  • 130,717
  • 29
  • 175
  • 215
1

CRDs are used to create, store and expose Kubernetes API objects, when they can be used for other purposes also. CRDs can be used to create custom resources for services and configs also.For example a CRD for a service,

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: service-crd
spec:
  group: mycompany.com
  version: v1
  scope: Namespaced
  names:
    kind: Service
    plural: services

Above yaml will specify a CRD called service-crd that can be used to create and manage with the mycompany.com. With this custom resource definition in place, you can use the API to create, update and delete services.

It is possible to mount a config map into a custom object using CRDs. Whereas configmaps are better suited for storing non- confidential information in kubernetes. Use a CRD if you need to store more complex data structures.

For more information follow a blog by Dawid Ziolkowski.

Sai Chandra Gadde
  • 2,242
  • 1
  • 3
  • 15