Skip to main content


Environments are variables specific to different clusters or namespaces.

Specify Environments

When running kosko generate or kosko validate, use -e,--env to specify environments.

kosko generate -e prod

You can also set baseEnvironment as the default environment.

baseEnvironment = "base"

Global Variables

Global variables are shared across all components. They are defined in environments/<env>/index.js.

export default {
imageRegistry: "",
namespace: "prod"

Once global variables are set, you can retrieve them with global() function.

import env from "@kosko/env";

const params =;
// {
// imageRegistry: "",
// namespace: "prod"
// }

Component Variables

Component variables should only be used within a component. However, you can still retrieve them from another components. If you find a component variable is used by multiple components, you should consider move it to global variables.

Component variables are defined in environments/<env>/<component>.js.

export default {
replicas: 3,
imageVersion: "stable"

Once component variables are set, you can retrieve them with component() function. It returns deep merge of global and component variables.

import env from "@kosko/env";

const params = env.component("nginx");
// {
// imageRegistry: "",
// namespace: "prod",
// replicas: 3,
// imageVersion: "stable"
// }

Get Current Environment

You can fetch current environment from env property. Depending on the value of -e/--env and baseEnvironment option, it could be string, string[] or undefined.

import env from "@kosko/env";

const currentEnv = env.env;
// "prod"
// ["base", "prod"]
// undefined