Krypton is a CLI tool designed for generating Kubernetes YAML manifests from a custom Domain-Specific Language (DSL). It allows developers to define Kubernetes resources in a more human-readable way using .kp files, which are then parsed and converted into YAML files.
- DSL Parsing: Parse custom .kp files to define Kubernetes deployments.
- YAML Generation: Generate deployment YAML manifests from the parsed DSL.
- Extensible: The code structure allows for easy extension to support other Kubernetes resources beyond deployments.
- Template-based: Uses Go templates for generating YAML, making it easy to customize the output format.
- Go 1.23+ installed
To build the kptn binary, run:
make buildDisplay the version of kptn:
./kptn versionDefine Your Application in the DSL:
- Write your application specification using the custom DSL in a .kp file:
deploy app "my-app" {
namespace: "default";
replicas: 3;
image: "my-app:v1.0";
ports {
http: 8080;
metrics: 2112;
}
env {
DATABASE_URL: "postgres://user:password@host/db";
}
resources {
limits {
memory: "512Mi";
cpu: "500m";
}
requests {
memory: "256Mi";
cpu: "250m";
}
}
storage {
volume: "my-app-data";
size: "5Gi";
}
}
Refer in the examples/ folder as basic_app.kp i.e. examples/basic_app.kp
- Generate Kubernetes Manifests:
Use the generate command to produce Kubernetes YAML:
./kptn generate examples/basic_app.kp --output=generated.yamlThis will read the DSL file, parse it, and generate a generated.yaml file with the Kubernetes Deployment manifest.
- Output
The generated YAML will be similar to the following:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:v1.0
ports:
- name: "http"
containerPort: 8080
- name: "metrics"
containerPort: 2112
env:
- name: "DATABASE_URL"
value: "postgres://user:password@host/db"
resources:
limits:
memory: "512Mi"
cpu: "500m"
requests:
memory: "256Mi"
cpu: "250m"
volumeMounts:
- name: "my-app-data"
mountPath: /data
volumes:
- name: "my-app-data"
persistentVolumeClaim:
claimName: "my-app-data"- cmd/krypton: Contains the main entry point for the kptn CLI.
- pkg/parser: Handles the parsing logic for .kp files.
- pkg/generator: Contains the logic for converting parsed structures into YAML using templates.
- pkg/generator/templates: Holds the Go templates used for generating Kubernetes YAML.
- examples/: Directory containing example .kp files and their corresponding generated YAML files.
To extend the DSL to support more Kubernetes resources, follow these steps:
- Define a new parser function in the pkg/parser package.
- Add a new Go template in the pkg/generator/templates directory.
- Update the generator package to use the new template for the corresponding resource.
- Add the necessary parsing logic in the NewGenerateCommand to handle the new resource type.
Feel free to open issues or submit pull requests. Contributions are always welcome!
This project will be licensed under the Apache License, Version 2.0. The LICENSE file will be available soon, providing the full terms and conditions for usage, including permissions, conditions, and limitations.