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 Slide

  2. View Slide

  3. Container orchestration platform

    View Slide

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

    View Slide

  5. No vendor lock in

    View Slide

  6. Runs on

    View Slide

  7. Your laptop

    View Slide

  8. Bare metal

    View Slide

  9. Cloud Providers

    View Slide

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

    View Slide

  11. Managed Kubernetes

    View Slide

  12. View Slide

  13. Standardized APIs

    View Slide

  14. It works the same everywhere*

    View Slide

  15. It works the same everywhere*
    *mostly

    View Slide

  16. This talk is about
    how to use Kubernetes

    View Slide

  17. Not only for production workloads

    View Slide

  18. But in your development workflows

    View Slide

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

    View Slide

  20. Kubernetes' standardized API makes
    this easier

    View Slide

  21. Agenda

    View Slide

  22. Deployment of a micro-service
    application

    View Slide

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

    View Slide

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

    View Slide

  25. View Slide

  26. 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 Slide

  27. external-dns to create DNS entries
    automatically

    View Slide

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

    View Slide

  29. Database is managed by an Operator

    View Slide

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

    View Slide

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

    View Slide

  32. Demo

    View Slide

  33. Writing this YAML files is tedious

    View Slide

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

    View Slide

  35. Production

    View Slide

  36. Staging

    View Slide

  37. Development

    View Slide

  38. Per Development team

    View Slide

  39. Per branch

    View Slide

  40. Per developer

    View Slide

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

    View Slide

  42. "Templating"

    View Slide

  43. Great tools because of standardized
    Kubernetes API

    View Slide

  44. Helm

    View Slide

  45. View Slide

  46. Allows to install applications

    View Slide

  47. So called "charts"

    View Slide

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

    View Slide

  49. Charts can depend on other charts

    View Slide

  50. Multiple deployments of one chart
    possible

    View Slide

  51. Different release names

    View Slide

  52. Different namespaces

    View Slide

  53. Configuration with values

    View Slide

  54. View Slide

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

    View Slide

  56. Demo

    View Slide

  57. Writing your own charts is fairly
    easy

    View Slide

  58. Scaffolding to get started

    View Slide

  59. $ helm create quote-svc

    View Slide

  60. Helm lint

    View Slide

  61. Helm kubeval

    View Slide

  62. Helm test

    View Slide

  63. Demo

    View Slide

  64. Alternatives:
    Kustomize

    View Slide

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

    View Slide

  66. Still, for development:

    View Slide

  67. Make a code change

    View Slide

  68. Build docker image

    View Slide

  69. Push docker image

    View Slide

  70. Run helm install/upgrade with new
    image version

    View Slide

  71. Can this be quicker?

    View Slide

  72. Run everything locally

    View Slide

  73. docker-compose

    View Slide

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

    View Slide

  75. Inconsistencies

    View Slide

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

    View Slide

  77. Some services locally, some remote

    View Slide

  78. Service Discovery

    View Slide

  79. Not every service is exposed to the
    Internet

    View Slide

  80. Shared resources with other
    developers?

    View Slide

  81. Other options?

    View Slide

  82. Tilt

    View Slide

  83. $ tilt up

    View Slide

  84. Watches for code changes

    View Slide

  85. Rebuilds docker image

    View Slide

  86. Deploys to Kubernetes

    View Slide

  87. Sets up port-forwarding

    View Slide

  88. Can sync changed files directly into a
    running container

    View Slide

  89. Demo

    View Slide

  90. Alternatives:
    Skaffold
    Garden

    View Slide

  91. Debugging containers

    View Slide

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

    View Slide

  93. Kubectl debug

    View Slide

  94. Debugging network traffic between
    containers

    View Slide

  95. Kubectl sniff

    View Slide

  96. Demo

    View Slide

  97. Another approach

    View Slide

  98. View Slide

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

    View Slide

  100. $ 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 Slide

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

    View Slide

  102. ... or a locally running docker
    container

    View Slide

  103. $ 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 Slide

  104. Demo

    View Slide

  105. Summary

    View Slide

  106. Powerful

    View Slide

  107. Great tooling because of common
    APIs

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide