Loading Kustomize
Kosko supports loading manifests from Kustomize files. You have to install either kustomize or kubectl CLI before using this package.
@kosko/kustomize uses the kustomize build command to generate Kubernetes manifests. Most options of kustomize build command are supported. See API documentation for available options.
Under the hood, @kosko/kustomize uses @kosko/yaml to load YAML, which means the loadKustomize function supports all options of the loadString function. See loading Kubernetes YAML for more details.
Install
- NPM
- Yarn
- PNPM
npm install @kosko/kustomize @kosko/yaml
yarn add @kosko/kustomize @kosko/yaml
pnpm install @kosko/kustomize @kosko/yaml
Load from a local directory
Load Kubernetes manifests from a local directory which contains a kustomization.yaml file. For example, you can use __dirname to load manifests from the current directory.
- TypeScript
- JavaScript (ESM)
- JavaScript (CJS)
import { loadKustomize } from "@kosko/kustomize";
loadKustomize({
path: "./dir"
});
import { loadKustomize } from "@kosko/kustomize";
loadKustomize({
path: "./dir"
});
const { loadKustomize } = require("@kosko/kustomize");
loadKustomize({
path: "./dir"
});
Load from a URL
You can also load manifests from a URL. See Kustomize docs for supported URL formats.
- TypeScript
- JavaScript (ESM)
- JavaScript (CJS)
import { loadKustomize } from "@kosko/kustomize";
loadKustomize({
path: "github.com/kubernetes-sigs/kustomize/examples/multibases?ref=v1.0.6"
});
import { loadKustomize } from "@kosko/kustomize";
loadKustomize({
path: "github.com/kubernetes-sigs/kustomize/examples/multibases?ref=v1.0.6"
});
const { loadKustomize } = require("@kosko/kustomize");
loadKustomize({
path: "github.com/kubernetes-sigs/kustomize/examples/multibases?ref=v1.0.6"
});
Specify the Build Command
By default, loadKustomize function uses kustomize build command to generate Kubernetes manifests, and fallbacks to kubectl kustomize command if kustomize CLI is not installed.
You can also customize the build command with the buildCommand option if kustomize or kubectl is not present in your PATH.
- TypeScript
- JavaScript (ESM)
- JavaScript (CJS)
import { loadKustomize } from "@kosko/kustomize";
loadKustomize({
path: "./dir",
buildCommand: ["./path/to/kustomize", "build"]
});
import { loadKustomize } from "@kosko/kustomize";
loadKustomize({
path: "./dir",
buildCommand: ["./path/to/kustomize", "build"]
});
const { loadKustomize } = require("@kosko/kustomize");
loadKustomize({
path: "./dir",
buildCommand: ["./path/to/kustomize", "build"]
});
Related
📄️ @kosko/kustomize
@kosko/kustomize package
📄️ Loading Kubernetes YAML
If you already have lots of existing Kubernetes YAML files, you don't have to rewrite all of them in JavaScript. Kosko provides two ways for you to load Kubernetes YAML files.