qbec supports components written as YAML, JSON or jsonnet files. YAML and JSON documents are static and unable to support parameterization per environment. These formats are good enough for Kubernetes objects like roles, role bindings, service accounts etc. where the content doesn’t usually vary per environment. In order to create components that need to be different per environment, you are pretty much required to use jsonnet.
Components are loaded from the components directory defined for your app.
This defaults to
components/ under the source tree but you can change this path in
A component is:
index.jsonnetfile. In this case the component name is the subdirectory name and the
index.jsonnetis processed by qbec.
index.yamlfile. In this case the component name is the subdirectory name and all json and yaml files under the directory are loaded by qbec.
It is valid for a component to return an empty set of objects if runtime parameters determine that nothing should be installed for a specific target environment.
You can use existing helm charts as a basis for loading a component. In this case, you would create a jsonnet file that uses the expandHelmTemplate native function that qbec exposes. This function loads the objects returned by the helm chart and allows you to patch them with jsonnet before returning them for qbec processing.
k8s-yaml-patch, for example, is a jsonnet library that allows you to load YAML documents, patch runtime values and return them for qbec use.
If you use the above or any other library, the correct way to integrate it with qbec is to use
the jsonnet bundler. download the dependencies
locally to a
vendor directory, and add this directory to the
libPaths array in
You will then be able to use these dependencies in your jsonnet code.
Most objects that you create using qbec are objects with fixed names (e.g. deployments, services etc.). Occasionally you may need to create transient objects like jobs and one-off pods.
qbec, like kubectl, allows you to set the
generateName instead of the
name metadata attribute for an object.
generateName attribute is set, qbec will change its behavior such that:
generateNameattribute are not considered duplicates.