2017-02-08 11:50:26 +01:00
|
|
|
KonTemplate - A simple Kubernetes templater
|
|
|
|
===========================================
|
|
|
|
|
2017-02-08 13:03:06 +01:00
|
|
|
[![Build Status](https://travis-ci.org/tazjin/kontemplate.svg?branch=master)](https://travis-ci.org/tazjin/kontemplate)
|
|
|
|
|
2017-02-08 11:50:26 +01:00
|
|
|
I made this tool out of frustration with the available ways to template Kubernetes resource files. All I want out of
|
|
|
|
such a tool is a way to specify lots of resources with placeholders that get filled in with specific values, based on
|
|
|
|
which context (i.e. k8s cluster) is specified.
|
|
|
|
|
|
|
|
## Overview
|
|
|
|
|
|
|
|
KonTemplate lets you describe resources as you normally would in a simple folder structure:
|
|
|
|
|
|
|
|
```
|
|
|
|
.
|
2017-02-08 13:15:36 +01:00
|
|
|
├── prod-cluster.yaml
|
2017-02-08 11:50:26 +01:00
|
|
|
└── some-api
|
|
|
|
├── deployment.yaml
|
|
|
|
└── service.yaml
|
|
|
|
```
|
|
|
|
|
|
|
|
This example has all resources belonging to `some-api` (no file naming conventions enforced at all!) in the `some-api`
|
|
|
|
folder and the configuration for the cluster `prod-cluster` in the corresponding file.
|
|
|
|
|
2017-02-08 13:15:36 +01:00
|
|
|
Lets take a short look at `prod-cluster.yaml`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
---
|
|
|
|
context: k8s.prod.mydomain.com
|
|
|
|
global:
|
|
|
|
globalVar: lizards
|
|
|
|
include:
|
|
|
|
- name: some-api
|
|
|
|
values:
|
|
|
|
version: 1.0-0e6884d
|
|
|
|
importantFeature: true
|
|
|
|
apiPort: 4567
|
2017-02-08 11:50:26 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Those values are then templated into the resource files of `some-api`.
|
|
|
|
|
2017-02-08 13:53:46 +01:00
|
|
|
## Installation
|
|
|
|
|
|
|
|
Assuming you have Go configured correctly, you can simply `go get github.com/tazjin/kontemplate/...`.
|
|
|
|
|
2017-02-08 11:50:26 +01:00
|
|
|
## Usage
|
|
|
|
|
2017-02-08 13:53:46 +01:00
|
|
|
You must have `kubectl` installed to use KonTemplate effectively.
|
|
|
|
|
2017-02-08 14:07:56 +01:00
|
|
|
```
|
|
|
|
NAME:
|
2017-02-08 15:35:58 +01:00
|
|
|
kontemplate - simple Kubernetes resource templating
|
2017-02-08 14:07:56 +01:00
|
|
|
|
|
|
|
USAGE:
|
2017-02-08 15:35:58 +01:00
|
|
|
kontemplate [global options] command [command options] [arguments...]
|
2017-02-08 14:07:56 +01:00
|
|
|
|
2017-02-08 15:35:58 +01:00
|
|
|
VERSION:
|
|
|
|
0.0.1
|
|
|
|
|
|
|
|
COMMANDS:
|
|
|
|
template Interpolate and print templates
|
|
|
|
apply Interpolate templates and run 'kubectl apply'
|
2017-02-08 16:47:33 +01:00
|
|
|
replace Interpolate templates and run 'kubectl replace'
|
2017-02-08 18:08:54 +01:00
|
|
|
delete Interpolate templates and run 'kubectl delete'
|
2017-02-08 15:35:58 +01:00
|
|
|
help, h Shows a list of commands or help for one command
|
|
|
|
|
|
|
|
GLOBAL OPTIONS:
|
|
|
|
--help, -h show help
|
|
|
|
--version, -v print the version
|
2017-02-08 14:07:56 +01:00
|
|
|
```
|
|
|
|
|
2017-02-08 16:47:33 +01:00
|
|
|
All options support the same set of extra flags:
|
|
|
|
|
|
|
|
```
|
|
|
|
OPTIONS:
|
|
|
|
--file value, -f value Cluster configuration file to use
|
|
|
|
--include value, -i value Limit templating to explicitly included resource sets
|
|
|
|
--exclude value, -e value Exclude certain resource sets from templating
|
|
|
|
```
|
|
|
|
|
2017-02-08 15:35:58 +01:00
|
|
|
Examples:
|
2017-02-08 13:53:46 +01:00
|
|
|
|
|
|
|
```
|
2017-02-08 15:35:58 +01:00
|
|
|
# Look at output for a specific resource set and check to see if it's correct ...
|
2017-02-08 16:47:33 +01:00
|
|
|
kontemplate template -f example/prod-cluster.yaml -i some-api
|
2017-02-08 13:53:46 +01:00
|
|
|
|
2017-02-08 15:35:58 +01:00
|
|
|
# ... maybe do a dry-run to see what kubectl would do:
|
|
|
|
kontemplate apply -f example/prod-cluster.yaml --dry-run
|
2017-02-08 13:53:46 +01:00
|
|
|
|
2017-02-08 15:35:58 +01:00
|
|
|
# And actually apply it if you like what you see:
|
|
|
|
kontemplate apply -f example/prod-cluster.yaml
|
2017-02-08 13:53:46 +01:00
|
|
|
```
|