Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ahoi! Complex applications on Kubernetes

Ahoi! Complex applications on Kubernetes

This is a talk I gave at the 60th Berlin Elixir UG on Jun 13

Lukas Rieder

June 13, 2019
Tweet

More Decks by Lukas Rieder

Other Decks in Technology

Transcript

  1. Imagine an Elixir Supervisor. children = [
 %{
 id: MyApplication,


    start: {MyApplication, :start_link, [[:hello]]}
 }
 ]
 
 {:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one)
  2. Imagine an Elixir Supervisor. children = [
 %{
 id: MyApplication,


    start: {MyApplication, :start_link, [[:hello]]}
 }
 ]
 
 {:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one)
  3. Imagine an Elixir Supervisor. children = [
 %{
 id: MyApplication,


    start: {MyApplication, :start_link, [[:hello]]}
 }
 ]
 
 {:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one)
  4. A Deployment in Kubernetes. apiVersion: apps/v1
 kind: Deployment
 metadata:
 name:

    my-app
 labels:
 app: my-app
 spec:
 # ... snip ...
 template:
 spec:
 containers:
 - name: my-container
 image: my-app:1.7.9
 command: ["myapp", "start_link"]
 args: ["hello"]

  5. Elixir Declarative programming. apiVersion: apps/v1
 kind: Deployment
 metadata:
 name: my-app


    labels:
 app: my-app
 spec:
 # ... snip ...
 template:
 spec:
 containers:
 - name: my-container
 image: my-app:1.7.9
 command: ["myapp", "start_link"]
 args: ["hello"]
 children = [
 %{
 id: MyApplication,
 start: {MyApplication, :start_link, [[:hello]]}
 }
 ]
 
 {:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one) Kubernetes
  6. Meet the operator pattern. It allows developers to encode domain

    knowledge
 into an extension of the K8s API.
  7. Custom
 Resource
 Definition Controller API Custom
 Resource Resources are the

    common declarative language, to describe a desired state.
  8. Custom
 Resource
 Definition Controller API Custom
 Resource apiVersion: apiextensions.k8s.io/v1beta1
 kind:

    CustomResourceDefinition
 metadata:
 name: crontabs.stable.example.com
 spec:
 group: stable.example.com
 versions:
 - name: v1
 served: true
 storage: true
 scope: Namespaced
 names:
 plural: crontabs
 singular: crontab
 kind: CronTab
 shortNames:
 - ct

  9. Custom
 Resource
 Definition Controller API Custom
 Resource The controller manages

    K8s and Custom resources for the given application domain.
  10. Pattern matching. Deconstruction. %{ "apiVersion" => "apps/v1", "kind" => "Deployment",

    "metadata" => %{ "labels" => %{"app" => "nginx"}, "name" => "nginx-deployment", "namespace" => "default" }, "spec" => %{ "replicas" => 3, "selector" => %{"matchLabels" => %{"app" => "nginx"}}, "template" => %{ "metadata" => %{"labels" => %{"app" => "nginx"}}, "spec" => %{ "containers" => [ %{ "image" => "nginx:1.7.9", "name" => "nginx", "ports" => [%{"containerPort" => 80}] } ] } } } }
  11. hs-preview "As a customer, I want to see my campaigns

    live, to check if they meet my expectations."
  12. Software multitenancy "As a customer, I want my workflows to

    run in a predictable and reliable manner."
  13. Customer apiVersion: "internal.example.com/v1"
 kind: Customer
 metadata:
 name: big-client-0815
 spec:
 features:


    database:
 enabled: true
 storage: 256gb
 scheduler:
 enabled: true
 workers: 4
 webhooks:
 enabled: false
 Software multitenancy
  14. Customer Database Scheduler Job
 (k8s) Namespace
 (k8s) Deployment
 (k8s) Customer


    Controller API Database
 Controller Scheduler
 Controller Software multitenancy
  15. Software multitenancy Customer Database Scheduler Job
 (k8s) Namespace
 (k8s) Deployment


    (k8s) Customer Database Scheduler Job
 (k8s) Namespace
 (k8s) Deployment
 (k8s) Customer Database Scheduler Job
 (k8s) Namespace
 (k8s) Deployment
 (k8s)
  16. Getting started ✓ Docker / Docker for Mac ✓ minikube

    / Kubernetes ✓ Elixir, Erlang ✓ bonni / k8s
  17. Example: global connection pools "As a customer, I want my

    database to be running at all times, in order to make money."