Slide 1

Slide 1 text

(without introducing more risk) Kubernetes without the YAML Puppet Gareth Rushgrove Alternative configuration options for K8

Slide 2

Slide 2 text

(without introducing more risk) @garethr

Slide 3

Slide 3 text

(without introducing more risk) Gareth Rushgrove

Slide 4

Slide 4 text

(without introducing more risk) What we’ll cover This talk

Slide 5

Slide 5 text

- Why not (only) YAML - A quick look at some alternatives - Short discussion Gareth Rushgrove

Slide 6

Slide 6 text

(without introducing more risk) The argument Why not (only) YAML

Slide 7

Slide 7 text

Gareth Rushgrove Brian Grant, Google, Kubernetes Config SIG “We've had a few complaints that YAML is ugly, error prone, hard to read, etc. Are there any other alternatives we might want to support?

Slide 8

Slide 8 text

(without introducing more risk) Gareth Rushgrove API wire format as user interface template: metadata: labels: app: guestbook tier: frontend spec: containers: - name: php-redis image: gcr.io/google_samples/gb-frontend:v4 resources: requests: cpu: 100m memory: 100Mi env:

Slide 9

Slide 9 text

The language to represent the data should be a simple, data-only format such as JSON or YAML, and programmatic modification of this data should be done in a real programming language Gareth Rushgrove Borg, Omega, and Kubernetes, ACM Queue, Volume 14, issue 1 http://queue.acm.org/detail.cfm?id=2898444 “

Slide 10

Slide 10 text

- Avoid repetition - Combine external inputs - Enforce correctness - Introduce abstractions Gareth Rushgrove

Slide 11

Slide 11 text

(without introducing more risk) Configuration language for JSON data Jsonnet

Slide 12

Slide 12 text

(without introducing more risk) jsonnet.org

Slide 13

Slide 13 text

(without introducing more risk) Gareth Rushgrove Jonnet template // Example template { person1: { name: "Alice", welcome: "Hello " + self.name + "!", }, person2: self.person1 { name: "Bob" }, }

Slide 14

Slide 14 text

(without introducing more risk) Gareth Rushgrove Render templates $ jsonnet example.jsonnet { "person1": { "name": "Alice", "welcome": "Hello Alice!" }, "person2": { "name": "Bob", "welcome": "Hello Bob!" } }

Slide 15

Slide 15 text

(without introducing more risk) kubernetes examples

Slide 16

Slide 16 text

(without introducing more risk) kubernetes-anywhere

Slide 17

Slide 17 text

(without introducing more risk) Gareth Rushgrove Jsonnet functions function(cfg) local if_enabled(addon, manifest) = if cfg.phase3[addon] then manifest local join(arr) = std.foldl(function(a, b) a + b, arr, {}); if_enabled("run_addons", join([ if_enabled("kube_proxy", (import "kube-proxy/kube-proxy.jsonnet" if_enabled("dashboard", (import "dashboard/dashboard.jsonnet")(c if_enabled("heapster", (import "heapster/heapster.jsonnet")(cfg) if_enabled("kube_dns", (import "kube-dns/kube-dns.jsonnet")(cfg) ]))

Slide 18

Slide 18 text

(without introducing more risk) A REPL for Kubernetes Kubeplay

Slide 19

Slide 19 text

(without introducing more risk) errordeveloper/kubeplay

Slide 20

Slide 20 text

(without introducing more risk) Gareth Rushgrove A REPL for Kubernetes $ ./kubeplay kubeplay (namespace="*")> pods # list pods in the cluster kubeplay (namespace="*")> @pod = _.any # pick a random pod from the list kubeplay (namespace="*")> puts @pod.to_json # output the pod definition { "metadata": { ... }, "spec": { ... "containers": [ {

Slide 21

Slide 21 text

(without introducing more risk) Gareth Rushgrove Ruby based DSL @metadata = replicasets("*/").to_ruby.items.map do |k,v| v.metadata end @metadata.each do |i| puts "Name:\t#{i.name}" puts "Labels:\t#{i.labels}" puts end

Slide 22

Slide 22 text

(without introducing more risk) Declarative Domain Specific Language Puppet

Slide 23

Slide 23 text

(without introducing more risk) garethr/garethr-kubernetes

Slide 24

Slide 24 text

(without introducing more risk) Gareth Rushgrove Puppet DSL kubernetes_pod { 'sample-pod': ensure => present, metadata => { namespace => 'default', }, spec => { containers => [{ name => 'container-name', image => 'nginx', }] }, }

Slide 25

Slide 25 text

(without introducing more risk) Gareth Rushgrove Query existing resources $ puppet resource kubernetes_pod sample-pod kubernetes_pod { 'sample-pod': ensure => 'present', metadata => { 'creationTimestamp' => '2016-01-20T14:03:23Z', 'name' => 'sample-pod', 'namespace' => 'default', 'resourceVersion' => '4579', 'selfLink' => '/api/v1/namespaces/default/pods/sample-pod’, 'uid' => '91c8a550-bf7e-11e5-816e-42010af001b1' }, spec => { 'containers' => [{ ‘image' => 'nginx',

Slide 26

Slide 26 text

(without introducing more risk) More Domain Specific Language Terraform

Slide 27

Slide 27 text

(without introducing more risk) maxmanuylov/terraform-provider-kubernetes

Slide 28

Slide 28 text

(without introducing more risk) Gareth Rushgrove Terraform provider resource "kubernetes_resource" "mypod" { # Required, must link on the corresponding "kubernetes_cluster" data s cluster = "${data.kubernetes_cluster.main.cluster}" collection = "pods" name = "mypod" labels { a = "b" } }

Slide 29

Slide 29 text

(without introducing more risk) If you’re interested in this topic One last thing

Slide 30

Slide 30 text

(without introducing more risk) KubeCon BoF session

Slide 31

Slide 31 text

(without introducing more risk) Questions? And thanks for listening