a tale of three tools: kubernetes, jsonnet, and bazel

29
A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel Miles Yucht SF Kubernetes Meetup July 26, 2017 1

Upload: databricks

Post on 15-Mar-2018

1.293 views

Category:

Software


0 download

TRANSCRIPT

Page 1: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Miles YuchtSF Kubernetes MeetupJuly 26, 2017 1

Page 2: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Who am I?

Miles• CS @ Princeton• SWE on Growth team @ Databricks

since 2015• "Lead Developer" of kubecfg

2

Page 3: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Agenda

• Kubernetes @ Databricks • Why Jsonnet• Combining Bazel and Kubernetes• Q & A

3

Page 4: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Kubernetes

4

Page 5: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Kubernetes at Databricks

● Multiple Kubernetes clusters, hundreds of deployments● 6+ terabytes of memory, hundreds of cores● Many customizations for security● Everything new goes onto Kubernetes● All managed by a 7-person team

5

Page 6: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Kubernetes at Databricks

We're hiring! Come talk to Priya or me after the talks!

6

Page 7: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Combinatorial Configurations

6 clusters, 3 environments, 4 modes of deployment● Lots of parameters● Extremely verbose

○ >75k lines of checked-in YAML templates● YAML is not modular● Hard to manage, manipulate, and correctly refactor templates

7

Page 8: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Kubernetes development lifecycle

● Simple to test & develop in Kubernetes● Keep dev, test, staging, prod environments similar● Critical for testing kubernetes/cloud features

○ E.g. replication, PROXY protocol

8

Page 9: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Many-step Deployment

9

Build Docker Image

Tag Docker Image

Push Docker ImageEdit Template

Apply Template

Page 10: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

kubecfg!

● Python wrapper around kubectl○ Still have all your favorite kubectl commands

● Preprocesses inputs and passes the result to kubectl● Augments kubectl

○ Easy to add new commands to kubecfg● Automates several common workflows

○ Simpler for developers○ Fewer chances to make mistakes

10

Page 11: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Jsonnet

11

Page 12: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Jsonnet

● DSL for defining JSON data● Break up monolithic configurations into composable parts● >75k lines of YAML → ~20k lines of Jsonnet● To learn about how we use Jsonnet:

○ https://databricks.com/blog/2017/06/26/declarative-infrastructure-jsonnet-templating-language.html

12

Page 13: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Jsonnet → JSON

When running kubecfg apply -f webapp.jsonnet:● jsonnet webapp.jsonnet > /tmp/aaa.json● kubectl apply -f /tmp/aaa.json

13

Page 14: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Original kubecfg architecture

14

Jsonnet Template Kubernetes spec Kubectl

Page 15: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Integrating build and deploy

Kubernetes template⇕

Tagged image

15

Page 16: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Integrating build and deploy

Kubernetes template⇕

How to produce the artifact that it depends on

16

Page 17: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Integrating build and deploy

1. What do you need to do to prepare the artifact?→ Ask your build tool.

2. How do you refer to the artifact?→ Use a tagged docker image.

17

Page 18: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Bazel

18

Page 19: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Bazel

● Open-source, language-agnostic build tool● Very customizable/configurable● Ported our build from SBT to Bazel mid-2016● To learn about how we use Bazel:

○ Blog post coming soon!

19

Page 20: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Kubectl Templates

{

image: "registry.databricks.com/webapp:latest",

...

}

20

Page 21: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Kubectl Templates

{

image: "registry.databricks.com/webapp:latest",

...

}

Kubernetes template⇕

Tagged image21

Page 22: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Kubecfg Templates

{

target: "//docker/webapp",

...

}

22

Page 23: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Kubecfg Templates

{

target: "//docker/webapp",

...

}

Kubernetes template⇕

Bazel target23

Page 24: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Integrating build and deploy

Build:● bazel build //docker/webapp:webapp

Tag & Push (new):● bazel run //docker/webapp:webapp_push -t <tag>

Deploy (new):● $(cat //docker/webapp:webapp_repository):<tag>

24

Page 25: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Tagging images

For clean checkouts:● <GIT_SHA>-<COMMIT_TIMESTAMP>

For dirty checkouts:● <GIT_SHA>-<COMMIT_TIMESTAMP>-DIRTY-<DIFF_SHA>

25

Page 26: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Current kubecfg architecture

26

Jsonnet Template “Kubernetes spec” with Bazel targets

Kubectl Kubernetes spec with images

Build docker image

Tag and push imagegit ref-log

Page 27: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Conclusion

● kubecfg makes deployment a two-step operation1. git checkout my-branch2. kubecfg apply -f the-template.jsonnet

● Speeds up development cycle● Helps with tracking down errors

27

Page 28: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Future of kubecfg

● We plan on open sourcing this library● Development in Bazel makes this easier

○ https://github.com/bazelbuild/rules_docker

28

Page 29: A Tale of Three Tools: Kubernetes, Jsonnet, and Bazel

Thank youWe're hiring! Talk to me or Priya if you're interested in joining our team.

29