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

Creating a fast Kubernetes Development Workflow

Creating a fast Kubernetes Development Workflow

Bastian Hofmann

November 13, 2019
Tweet

More Decks by Bastian Hofmann

Other Decks in Programming

Transcript

  1. @BastianHofmann
    Creating a fast
    Kubernetes Development Workflow
    Bastian Hofmann

    View full-size slide

  2. Container orchestration platform

    View full-size slide

  3. Deploy, run and scale your services
    in isolated containers

    View full-size slide

  4. No vendor lock in

    View full-size slide

  5. Cloud Providers

    View full-size slide

  6. And if you don't want to install and
    maintain Kubernetes yourself

    View full-size slide

  7. Managed Kubernetes

    View full-size slide

  8. Standardized APIs

    View full-size slide

  9. It works the same everywhere*

    View full-size slide

  10. It works the same everywhere*
    *mostly

    View full-size slide

  11. This talk is about
    how to use Kubernetes

    View full-size slide

  12. Not only for production workloads

    View full-size slide

  13. But in your development workflows

    View full-size slide

  14. Goal:
    Development environment as close
    to production as possible

    View full-size slide

  15. Kubernetes' standardized API makes
    this easier

    View full-size slide

  16. Deployment of a micro-service
    application

    View full-size slide

  17. Some tools to help with local
    development of this application on
    Kubernetes

    View full-size slide

  18. Let's have a look at the sample
    application

    View full-size slide

  19. OpenStack Cloud LoadBalancer
    NGINX Ingress Controller NGINX Ingress Controller NGINX Ingress Controller
    web-application web-application
    MySQL Primary
    MySQL Secondary
    quote-svc
    quote-svc
    hello-svc
    hello-svc

    View full-size slide

  20. external-dns to create DNS entries
    automatically

    View full-size slide

  21. cert-manager to retrieve
    Let's Encrypt certificates
    automatically

    View full-size slide

  22. Database is managed by an Operator

    View full-size slide

  23. MySQL Operator MySQLCluster
    MySQL pods
    MySQL statefulset
    Kubernetes controller manager
    Discovers
    Creates
    Creates
    Discovers
    Monitors and manages

    View full-size slide

  24. If you are interested in the code and
    how to set it up:
    https:/
    /github.com/syseleven/
    golem-workshop

    View full-size slide

  25. Writing this YAML files is tedious

    View full-size slide

  26. YAML files are tied to a specific
    version and a specific environment

    View full-size slide

  27. Per Development team

    View full-size slide

  28. Per developer

    View full-size slide

  29. We need to maintain multiple, very
    similar YAML files with slightly
    different versions and configuration

    View full-size slide

  30. "Templating"

    View full-size slide

  31. Great tools because of standardized
    Kubernetes API

    View full-size slide

  32. Allows to install applications

    View full-size slide

  33. So called "charts"

    View full-size slide

  34. $ helm install stable/wordpress \
    --name my-blog \
    --namespace blog

    View full-size slide

  35. Charts can depend on other charts

    View full-size slide

  36. Multiple deployments of one chart
    possible

    View full-size slide

  37. Different release names

    View full-size slide

  38. Different namespaces

    View full-size slide

  39. Configuration with values

    View full-size slide

  40. $ helm install stable/wordpress \
    --name my-blog \
    --namespace blog \
    -f my-config-values.yaml

    View full-size slide

  41. Writing your own charts is fairly
    easy

    View full-size slide

  42. Scaffolding to get started

    View full-size slide

  43. $ helm create quote-svc

    View full-size slide

  44. Helm kubeval

    View full-size slide

  45. Alternatives:
    Kustomize

    View full-size slide

  46. This works now great for production
    or staging or CI

    View full-size slide

  47. Still, for development:

    View full-size slide

  48. Make a code change

    View full-size slide

  49. Build docker image

    View full-size slide

  50. Push docker image

    View full-size slide

  51. Run helm install/upgrade with new
    image version

    View full-size slide

  52. Can this be quicker?

    View full-size slide

  53. Run everything locally

    View full-size slide

  54. docker-compose

    View full-size slide

  55. Duplication of the definition of how
    to run a container

    View full-size slide

  56. Inconsistencies

    View full-size slide

  57. If you have a lot of services, you have
    to run a lot locally

    View full-size slide

  58. Some services locally, some remote

    View full-size slide

  59. Service Discovery

    View full-size slide

  60. Not every service is exposed to the
    Internet

    View full-size slide

  61. Shared resources with other
    developers?

    View full-size slide

  62. Other options?

    View full-size slide

  63. Watches for code changes

    View full-size slide

  64. Rebuilds docker image

    View full-size slide

  65. Deploys to Kubernetes

    View full-size slide

  66. Sets up port-forwarding

    View full-size slide

  67. Can sync changed files directly into a
    running container

    View full-size slide

  68. Alternatives:
    Skaffold
    Garden

    View full-size slide

  69. Debugging containers

    View full-size slide

  70. Most containers do not have all the
    debugging tools included

    View full-size slide

  71. Kubectl debug

    View full-size slide

  72. Debugging network traffic between
    containers

    View full-size slide

  73. Kubectl sniff

    View full-size slide

  74. Another approach

    View full-size slide

  75. Creates a two-way proxy between
    the Kubernetes cluster and you

    View full-size slide

  76. $ telepresence
    T: Starting proxy with method 'vpn-tcp'...
    @fhgbvx65xg|bash-3.2$ curl http://quote-svc/quote | jq '.'
    [
    {
    "ID": 503,
    "title": "stefan sagmeister",
    "content": "...\n",
    "link": "https://quotesondesign.com/stefan-
    sagmeister-2/"
    }
    ]

    View full-size slide

  77. Swap a running deployment in the
    cluster with a local process

    View full-size slide

  78. ... or a locally running docker
    container

    View full-size slide

  79. $ telepresence --swap-deployment quote-svc --namespace
    dev-flow-demo --expose 3000 --run npm run debug
    T: Starting proxy with method 'vpn-tcp',...
    T: Forwarding remote port 3000 to local port 3000....
    > [email protected] debug /Users/bhofmann/forge_test/quote-
    svc
    > nodemon --inspect quote-svc.js
    [nodemon] watching: *.*
    [nodemon] starting `node --inspect quote-svc.js`
    Debugger listening on ws://127.0.0.1:9229/83aa27ac-
    d879-4b50-a228-440354cca791
    quote svc listening on port 3000!

    View full-size slide

  80. Great tooling because of common
    APIs

    View full-size slide

  81. Especially great if you have multiple
    services and don't want to run
    everything locally

    View full-size slide

  82. Test it
    30 days
    For free
    Visit us at our
    booth

    View full-size slide

  83. [email protected]
    https:/
    /twitter.com/BastianHofmann
    http:/
    /speakerdeck.com/u/bastianhofmann
    https:/
    /github.com/syseleven/golem-workshop

    View full-size slide