Skip to content
Snippets Groups Projects
README.md 2.74 KiB
Newer Older
Jessica Yuen's avatar
Jessica Yuen committed
# ksonnet
Angus Lees's avatar
Angus Lees committed

Jessica Yuen's avatar
Jessica Yuen committed
[![Build Status](https://travis-ci.org/ksonnet/ksonnet.svg?branch=master)](https://travis-ci.org/ksonnet/ksonnet)
[![Go Report Card](https://goreportcard.com/badge/github.com/ksonnet/ksonnet)](https://goreportcard.com/report/github.com/ksonnet/ksonnet)
Angus Lees's avatar
Angus Lees committed

Angus Lees's avatar
Angus Lees committed
A tool for managing Kubernetes resources as code.

Jessica Yuen's avatar
Jessica Yuen committed
`ksonnet` allows you to express the patterns across your
Angus Lees's avatar
Angus Lees committed
infrastructure and reuse these powerful "templates" across many
services, and then manage those templates as files in version control.
The more complex your infrastructure is, the more you will gain from
using kubecfg.

Angus Lees's avatar
Angus Lees committed
Status: Basic functionality works, and the tool is usable.  The focus
now is on clearer error reporting and advanced features.
Angus Lees's avatar
Angus Lees committed

## Install

To build from source:

```console
% PATH=$PATH:$GOPATH/bin
Jessica Yuen's avatar
Jessica Yuen committed
% go get github.com/ksonnet/ksonnet
Angus Lees's avatar
Angus Lees committed
```

Requires golang >=1.7 and a functional cgo environment (C++ with libstdc++).
Angus Lees's avatar
Angus Lees committed
Note that recent OSX environments
[require golang >=1.8.1](https://github.com/golang/go/issues/19734) to
avoid an immediate `Killed: 9`.
Angus Lees's avatar
Angus Lees committed

## Quickstart

```console
Jessica Yuen's avatar
Jessica Yuen committed
# Include <ksonnet.git>/lib in ksonnet/jsonnet library search path.
# Can also use explicit `-J` args everywhere.
Jessica Yuen's avatar
Jessica Yuen committed
% export KUBECFG_JPATH=/path/to/ksonnet/lib
Angus Lees's avatar
Angus Lees committed

# Show generated YAML
Jessica Yuen's avatar
Jessica Yuen committed
% ks show -o yaml -f examples/guestbook.jsonnet
Angus Lees's avatar
Angus Lees committed

# Create resources
Jessica Yuen's avatar
Jessica Yuen committed
% ks apply -f examples/guestbook.jsonnet

# Modify configuration (downgrade gb-frontend image)
% sed -i.bak '\,gcr.io/google-samples/gb-frontend,s/:v4/:v3/' examples/guestbook.jsonnet
# See differences vs server
Jessica Yuen's avatar
Jessica Yuen committed
% ks diff -f examples/guestbook.jsonnet
Angus Lees's avatar
Angus Lees committed

# Update to new config
Jessica Yuen's avatar
Jessica Yuen committed
% ks apply -f examples/guestbook.jsonnet

# Clean up after demo
Jessica Yuen's avatar
Jessica Yuen committed
% ks delete -f examples/guestbook.jsonnet
Angus Lees's avatar
Angus Lees committed
```

## Features

- Supports JSON, YAML or jsonnet files (by file suffix).
- Best-effort sorts objects before updating, so that dependencies are
  pushed to the server before objects that refer to them.
- Additional jsonnet builtin functions. See `lib/kubecfg.libsonnet`.
Angus Lees's avatar
Angus Lees committed

## Infrastructure-as-code Philosophy

The idea is to describe *as much as possible* about your configuration
as files in version control (eg: git).

Changes to the configuration follow a regular review, approve, merge,
etc code change workflow (github pull-requests, phabricator diffs,
etc).  At any point, the config in version control captures the entire
desired-state, so the system can be easily recreated in a QA cluster
or to recover from disaster.

### Jsonnet

Jessica Yuen's avatar
Jessica Yuen committed
ksonnet relies heavily on [jsonnet](http://jsonnet.org/) to describe
Angus Lees's avatar
Angus Lees committed
Kubernetes resources, and is really just a thin Kubernetes-specific
wrapper around jsonnet evaluation.  You should read the jsonnet
[tutorial](http://jsonnet.org/docs/tutorial.html), and skim the functions available in the jsonnet [`std`](http://jsonnet.org/docs/stdlib.html)
Angus Lees's avatar
Angus Lees committed
library.