Kubes supports a DSL that builds Kubernetes YAML files. The DSL substantially reduces the amount of code you have to write. Each part of the structure can be customized and overridden.
In general, the available DSL methods correspond to resource fields available. To find available methods:
- Look the at the source for each of the resources.
- Refer to each resource’s docs, linked at the bottom of this page.
- And use the
Sometimes the methods may not exactly match to avoid field names collisions. Though this is the exception, not the rule.
Here’s a simple example:
name "demo-web" labels(role: "web") namespace "demo" port 80 targetPort 80
--- apiVersion: v1 kind: Service metadata: name: demo-web labels: app: demo namespace: demo spec: ports: - port: 80 protocol: TCP targetPort: 8080 selector: app: demo type: NodePort
targetPort correspond to
spec.ports.targetPort in the YAML.
Reader and Writer Methods
- The DSL methods behave as reader methods when no arguments are passed to it. IE:
name "demo-web"sets the value.
- The DSL methods behave as writer methods when arguments are passed to it. IE:
namereturns the value.
Generally, the merge should behave as expected. For example, map or Hash fields are merged together from multiple layers. Strings are simply replaced. See more details at Layering Merge Behavior