Environments
Environments are variables specific to different clusters or namespaces.
Specify Environments
When running kosko generate
or kosko validate
, use --env, -e
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
.
- TypeScript
- JavaScript
export default {
imageRegistry: "gcr.io/acme-prod",
namespace: "prod"
};
module.exports = {
imageRegistry: "gcr.io/acme-prod",
namespace: "prod"
};
Once global variables are set, you can retrieve them with global()
function.
- TypeScript
- JavaScript
import env from "@kosko/env";
const params = env.global();
// {
// imageRegistry: "gcr.io/acme-prod",
// namespace: "prod"
// }
const env = require("@kosko/env");
const params = env.global();
// {
// imageRegistry: "gcr.io/acme-prod",
// 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
.
- TypeScript
- JavaScript
export default {
replicas: 3,
imageVersion: "stable"
};
module.exports = {
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.
- TypeScript
- JavaScript
import env from "@kosko/env";
const params = env.component("nginx");
// {
// imageRegistry: "gcr.io/acme-prod",
// namespace: "prod",
// replicas: 3,
// imageVersion: "stable"
// }
const env = require("@kosko/env");
const params = env.component("nginx");
// {
// imageRegistry: "gcr.io/acme-prod",
// namespace: "prod",
// replicas: 3,
// imageVersion: "stable"
// }
Get Current Environment
You can fetch current environment from env
property. Depending on the value of --env, -e
and baseEnvironment
option, it could be string
, string[]
or undefined
.
- TypeScript
- JavaScript
import env from "@kosko/env";
const currentEnv = env.env;
// "prod"
// ["base", "prod"]
// undefined
const env = require("@kosko/env");
const currentEnv = env.env;
// "prod"
// ["base", "prod"]
// undefined