Components

Create Components

Create components by using templates or add files to components folder. For example:

components
โ””โ”€โ”€ nginx.js

You can also split manifests into multiple files and export them in index.js.

components
โ””โ”€โ”€ nginx
โ”œโ”€โ”€ deployment.js
โ”œโ”€โ”€ index.js
โ””โ”€โ”€ service.js

Declare Manifests

Export manifests to module.exports in CommonJS modules or export default in ES modules. It can be written in the following styles.

Single Manifest

const { Deployment } = require("kubernetes-models/apps/v1");
module.exports = new Deployment();

Multiple Manifests

const { Deployment } = require("kubernetes-models/apps/v1");
const { Service } = require("kubernetes-models/v1");
module.exports = [new Deployment(), new Service()];

In a Function

const { Deployment } = require("kubernetes-models/apps/v1");
const { Service } = require("kubernetes-models/v1");
module.exports = function () {
return [new Deployment(), new Service()];
};

In a Async Function

const { Deployment } = require("kubernetes-models/apps/v1");
const { Service } = require("kubernetes-models/v1");
module.exports = async function () {
return [new Deployment(), new Service()];
};

Nested Manifests

info

This feature is available since v1.0.0.

Arrays and functions in components are flattened. This is useful for reusing manifests across different components.

const { Deployment } = require("kubernetes-models/apps/v1");
const { Service } = require("kubernetes-models/v1");
module.exports = [
[new Deployment(), new Service()],
async () => [new Deployment(), new Service()]
];

Validate Manifests

Built-in Validation

We use kubernetes-models by default. This package validates against Kubernetes OpenAPI schema.

Custom Validation

Create a class with validate() method and throw an error when the validation failed.

class Pod {
validate() {
if (!this.metadata.name) {
throw new Error("metadata.name is required");
}
}
}