This template assumes a three-level configuration hierarchy: application, environment, and cluster.
Modules at the root of the configuration hierarchy directly amend this module
(amends "package://pkg.pkl-lang.org/pkl-pantry/k8s.contrib.appEnvCluster@<version>#/AppEnvCluster.pkl"
).
All other modules amend their parent (amends "..."
).
Leaf modules dictate which Kubernetes resources are generated.
To generate all resources, evaluate all modules (non-leaf modules are automatically ignored):
$ pkl eval **/*.pkl
By default, all resources are written to standard output as a YAML stream, where each resource
is separated using ---
.
This YAML stream may also be written to a file using the
-o
flag.
Each resource can also be written to its own file using the
-m
flag.
When writing individual files, the file paths follow the same three-level hierarchy of
application, environment and cluster.
# Write all resources as a YAML stream into `output.yaml`
$ pkl eval -o output.yaml **/*.pkl
# Write each resource to its own file to the `.out/` directory
$ pkl eval -m .out/ **/*.pkl
Modules higher up in the config hierarchy contain configuration common to their descendants.
Kubernetes resources are grouped by kind and keyed by name:
ingresses {
["cluster-service.example.com"] { ... }
}
services {
["cluster-service"] { ... }
}
Resource names are used as default values for the resources' metadata.name
properties.
Kubernetes configuration often contains lists of key-value pairs.
To override a particular value, match its key with a predicate:
env { // list of environment variable names and values
[[name == "IMAGE_REPOSITORY"]] { // override value(s) matching this predicate
value = "docker.com"
}
}
Note the use of double brackets ([[...]]
), which distinguishes a predicate from an ordinary key ([...]
).
== Extending This Template
This template only covers the most common kinds of resources: configMaps
, deployments
, ingresses
, etc.
To describe other kinds of resources, extend this template and add additional top-level properties.
For example, to describe HorizontalPodAutoscaler resources,
create a new file named MyTemplate.pkl
with the following content:
module MyTemplate
extends "package://pkg.pkl-lang.org/pkl-pantry/k8s.contrib.appEnvCluster@<version>#/AppEnvCluster.pkl"
import "package://pkg.pkl-lang.org/pkl-k8s/k8s@<version>#/api/autoscaling/v1/HorizontalPodAutoscaler.pkl"
horizontalPodAutoscalers: Mapping<String, HorizontalPodAutoscaler> = module.resourceMapping(HorizontalPodAutoscaler)
To browse Pkl Kubernetes templates and determine their import URIs (such as package://pkg.pkl-lang.org/pkl-k8s/k8s@1.0.0#/api/core/v1/Pod.pkl
),
go to the package repo.
Template for generating Kubernetes manifests for apps.