@BastianHofmannCreating a fastKubernetes Development WorkflowBastian Hofmann
View Slide
Container orchestration platform
Deploy, run and scale your servicesin isolated containers
No vendor lock in
Runs on
Your laptop
Bare metal
Cloud Providers
And if you don't want to install andmaintain Kubernetes yourself
Managed Kubernetes
Standardized APIs
It works the same everywhere*
It works the same everywhere**mostly
This talk is abouthow to use Kubernetes
Not only for production workloads
But in your development workflows
Goal:Development environment as closeto production as possible
Kubernetes' standardized API makesthis easier
Agenda
Deployment of a micro-serviceapplication
Some tools to help with localdevelopment of this application onKubernetes
Let's have a look at the sampleapplication
OpenStack Cloud LoadBalancerNGINX Ingress Controller NGINX Ingress Controller NGINX Ingress Controllerweb-application web-applicationMySQL PrimaryMySQL Secondaryquote-svcquote-svchello-svchello-svc
external-dns to create DNS entriesautomatically
cert-manager to retrieveLet's Encrypt certificatesautomatically
Database is managed by an Operator
MySQL Operator MySQLClusterMySQL podsMySQL statefulsetKubernetes controller managerDiscoversCreatesCreatesDiscoversMonitors and manages
If you are interested in the code andhow to set it up:https://github.com/syseleven/golem-workshop
Demo
Writing this YAML files is tedious
YAML files are tied to a specificversion and a specific environment
Production
Staging
Development
Per Development team
Per branch
Per developer
We need to maintain multiple, verysimilar YAML files with slightlydifferent versions and configuration
"Templating"
Great tools because of standardizedKubernetes API
Helm
Allows to install applications
So called "charts"
$ helm install stable/wordpress \--name my-blog \--namespace blog
Charts can depend on other charts
Multiple deployments of one chartpossible
Different release names
Different namespaces
Configuration with values
$ helm install stable/wordpress \--name my-blog \--namespace blog \-f my-config-values.yaml
Writing your own charts is fairlyeasy
Scaffolding to get started
$ helm create quote-svc
Helm lint
Helm kubeval
Helm test
Alternatives:Kustomize
This works now great for productionor staging or CI
Still, for development:
Make a code change
Build docker image
Push docker image
Run helm install/upgrade with newimage version
Can this be quicker?
Run everything locally
docker-compose
Duplication of the definition of howto run a container
Inconsistencies
If you have a lot of services, you haveto run a lot locally
Some services locally, some remote
Service Discovery
Not every service is exposed to theInternet
Shared resources with otherdevelopers?
Other options?
Tilt
$ tilt up
Watches for code changes
Rebuilds docker image
Deploys to Kubernetes
Sets up port-forwarding
Can sync changed files directly into arunning container
Alternatives:SkaffoldGarden
Debugging containers
Most containers do not have all thedebugging tools included
Kubectl debug
Debugging network traffic betweencontainers
Kubectl sniff
Another approach
Creates a two-way proxy betweenthe Kubernetes cluster and you
$ telepresenceT: 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/"}]
Swap a running deployment in thecluster with a local process
... or a locally running dockercontainer
$ telepresence --swap-deployment quote-svc --namespacedev-flow-demo --expose 3000 --run npm run debugT: 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-440354cca791quote svc listening on port 3000!
Summary
Powerful
Great tooling because of commonAPIs
Especially great if you have multipleservices and don't want to runeverything locally
Test it30 daysFor freeVisit us at ourbooth
[email protected]https://twitter.com/BastianHofmannhttp://speakerdeck.com/u/bastianhofmannhttps://github.com/syseleven/golem-workshop