|
| 1 | +# kubecfg |
| 2 | + |
| 3 | +A tool for managing Kubernetes resources as code. |
| 4 | + |
| 5 | +`kubecfg` allows you to express the patterns across your |
| 6 | +infrastructure and reuse these powerful "templates" across many |
| 7 | +services, and then manage those templates as files in version control. |
| 8 | +The more complex your infrastructure is, the more you will gain from |
| 9 | +using kubecfg. |
| 10 | + |
| 11 | +Status: This is a golang-rewrite of |
| 12 | +https://github.com/anguslees/kubecfg. The original version has a few |
| 13 | +additional features, but the golang version will feel more similar to |
| 14 | +`kubectl` and is the focus of future development. |
| 15 | + |
| 16 | +Yes, Google employees will recognise this as being very similar to a |
| 17 | +similarly-named internal tool ;) |
| 18 | + |
| 19 | +## Install |
| 20 | + |
| 21 | +To build from source: |
| 22 | + |
| 23 | +```console |
| 24 | +% PATH=$PATH:$GOPATH/bin |
| 25 | +% go install github.com/ksonnet/kubecfg |
| 26 | +``` |
| 27 | + |
| 28 | +Requires golang >=1.7 and a functional cgo environment (C++ with libstdc++). |
| 29 | + |
| 30 | +## Quickstart |
| 31 | + |
| 32 | +```console |
| 33 | +# This example uses ksonnet-lib |
| 34 | +% git clone https://github.com/ksonnet/ksonnet-lib.git |
| 35 | + |
| 36 | +# Set kubecfg/jsonnet library search path. Can also use `-J` args everywhere. |
| 37 | +% export KUBECFG_JPATH=$PWD/ksonnet-lib |
| 38 | + |
| 39 | +# Hello-world ksonnet-lib example |
| 40 | +% cd ksonnet-lib/examples/hello-world |
| 41 | + |
| 42 | +# Show generated YAML |
| 43 | +% kubecfg show -o yaml hello.v1.jsonnet |
| 44 | + |
| 45 | +# Create resources |
| 46 | +% kubecfg update hello.v1.jsonnet |
| 47 | + |
| 48 | +# Modify configuration |
| 49 | +% sed -ie 's/nginx:1.7.9/nginx:1.13.0/' hello.v1.jsonnet |
| 50 | +# Update to new config |
| 51 | +% kubecfg update hello.v1.jsonnet |
| 52 | +``` |
| 53 | + |
| 54 | +## Features |
| 55 | + |
| 56 | +- Supports JSON, YAML or jsonnet files (by file suffix). |
| 57 | +- Best-effort sorts objects before updating, so that dependencies are |
| 58 | + pushed to the server before objects that refer to them. |
| 59 | + |
| 60 | +## Infrastructure-as-code Philosophy |
| 61 | + |
| 62 | +The idea is to describe *as much as possible* about your configuration |
| 63 | +as files in version control (eg: git). |
| 64 | + |
| 65 | +Changes to the configuration follow a regular review, approve, merge, |
| 66 | +etc code change workflow (github pull-requests, phabricator diffs, |
| 67 | +etc). At any point, the config in version control captures the entire |
| 68 | +desired-state, so the system can be easily recreated in a QA cluster |
| 69 | +or to recover from disaster. |
| 70 | + |
| 71 | +### Jsonnet |
| 72 | + |
| 73 | +Kubecfg relies heavily on [jsonnet](http://jsonnet.org/) to describe |
| 74 | +Kubernetes resources, and is really just a thin Kubernetes-specific |
| 75 | +wrapper around jsonnet evaluation. You should read the jsonnet |
| 76 | +tutorial, and skim the functions available in the jsonnet `std` |
| 77 | +library. |
0 commit comments