Kubegen is a lightweight CLI tool written for generating Kubernetes manifests from templates
Find a file
bot_rosco 3449034f43
All checks were successful
Build / build (release) Successful in 2m44s
add configmap init container and namespace create
2026-04-09 15:22:10 +01:00
.forgejo/workflows Hide archive on latest 2026-03-28 23:55:49 +00:00
cmd/kubegen Cleanup comments and readme 2026-03-28 22:50:51 +00:00
pkg add configmap init container and namespace create 2026-04-09 15:22:10 +01:00
go.mod New system 2026-03-28 22:04:25 +00:00
go.sum New system 2026-03-28 22:04:25 +00:00
LICENSE.md A new start 2026-03-28 14:07:59 +00:00
main.go New system 2026-03-28 22:04:25 +00:00
README.md add space 2026-03-29 00:06:20 +00:00

Kubegen

Kubegen is a lightweight CLI tool written for generating Kubernetes manifests from templates.

It reads custom .gotmpl files that contain YAML frontmatter to define expected variables. Based on this frontmatter, kubegen dynamically generates command-line flags, enforces required fields, handles default values, and outputs the rendered templates.

Features

  • Dynamic CLI Flags: Automatically generates command-line flags (with type enforcement for string, bool, and int) based on your template's YAML frontmatter.
  • Embedded Templates: Bundle your organization's standard templates directly inside the compiled binary for easy, single-file distribution.
  • Local Overrides: Reference local files on your filesystem to override embedded templates or test new ones.
  • Built-in Validation: Enforces required fields before attempting to render the template.
  • Intelligent Output: Print to standard output, or provide a target directory to automatically split multi-document templates into logically named, individual files (e.g., app.yaml, app-secret.yaml).
  • Self-Documenting: Use the info command to instantly see what variables a template expects.

Installation

  1. Download latest build for your platform from releases
  2. (Optional) Move the binary to your PATH e.g. for linux:
    mv kubegen_v0.1.0_linux /usr/local/bin/kubegen
    

Build

Prerequisites

  • Go 1.26 or higher

Setup

  1. Clone or initialize the repository.
  2. Download the required YAML dependency:
    go get gopkg.in/yaml.v3
    
  3. Build the binary from the cmd directory:
    go build -o kubegen ./cmd/kubegen
    
  4. (Optional) Move the binary to your PATH:
    mv kubegen /usr/local/bin/
    

Directory Structure

For the embedded templates to work correctly, your project should look like this before building:

kubegen/
├── go.mod
├── go.sum
├── cmd/
│   └── kubegen/
│       └── main.go           # CLI entry point
└── pkg/
    ├── tpl/
    │   ├── tpl.go            
    │   └── templates/        # Put your .gotmpl files here
    │       └── deployment.gotmpl 
    ├── parser/
    │   └── parser.go         
    └── generator/
        └── generator.go      

Template Format

Templates must contain a YAML frontmatter block defining the variables, followed by a --- separator, and then the standard Go text/template body.
Also see pre-packaged templates: pkg/tpl/templates

Example (templates/deployment.gotmpl):

values:
  - name: Name
    type: string
    description: Name of the application
    required: true
  - name: Replicas
    type: int
    description: Number of pod replicas
    default: 3
    required: false
  - name: UseGpu
    type: bool
    description: Whether to request GPU resources
    default: false
    required: false
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Name }}
spec:
  replicas: {{ .Replicas }}
  template:
    spec:
      containers:
      - name: {{ .Name }}
        image: nginx:latest
        {{- if .UseGpu }}
        resources:
          limits:
            [nvidia.com/gpu](https://nvidia.com/gpu): 1
        {{- end }}

Supported Data Types

  • string
  • int
  • bool

Usage

1. List Bundled Templates

See which templates are compiled into the binary.

kubegen list

2. View Template Info

Check the required flags, types, and defaults for a specific template. You can use the short name for embedded templates or provide a path to a local file.

kubegen info deployment

Output:

Available Values:
--------------------------------------------------------------------------------
NAME        TYPE      REQUIRED   DEFAULT   DESCRIPTION
Name        string    true       -         Name of the application
Replicas    int       false      3         Number of pod replicas
UseGpu      bool      false      false     Whether to request GPU resources

3. Generate Manifests

Generate the final text by passing the required variables as CLI flags. By default, this prints to standard output.

kubegen generate deployment --Name=my-web-app --Replicas=5 --UseGpu=true

Saving to a Directory (Intelligent Splitting)

Use the -o or --output flag to specify a target directory. Kubegen will split the YAML by document separators (---) and create intelligently named files based on the resource Kind and Name (e.g., Deployments drop the kind suffix for cleaner naming).

kubegen generate deployment --Name=my-app --Namespace=dev --o ./manifests

Output:

Writing manifests to directory: ./manifests
  - Created: my-app.yaml
  - Created: my-app-service.yaml
  - Created: my-app-secret.yaml