×
Copy
Open
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
@BastianHofmann Creating a fast Kubernetes Development Workflow Bastian Hofmann
Slide 2
Slide 2 text
No content
Slide 3
Slide 3 text
Container orchestration platform
Slide 4
Slide 4 text
Deploy, run and scale your services in isolated containers
Slide 5
Slide 5 text
Very Powerful
Slide 6
Slide 6 text
Large community
Slide 7
Slide 7 text
Lot’s of large company backers
Slide 8
Slide 8 text
No vendor lock in
Slide 9
Slide 9 text
Runs on
Slide 10
Slide 10 text
Your laptop
Slide 11
Slide 11 text
Included in Docker Desktop Clients
Slide 12
Slide 12 text
Bare metal
Slide 13
Slide 13 text
Cloud Providers
Slide 14
Slide 14 text
AWS
Slide 15
Slide 15 text
Azure
Slide 16
Slide 16 text
Google Cloud Platform
Slide 17
Slide 17 text
And if you don't want to install and maintain Kubernetes yourself
Slide 18
Slide 18 text
Managed Kubernetes
Slide 19
Slide 19 text
Google GKE
Slide 20
Slide 20 text
Amazon EKS
Slide 21
Slide 21 text
SysEleven MetaKube
Slide 22
Slide 22 text
Easy upgrades
Slide 23
Slide 23 text
Easy scaling
Slide 24
Slide 24 text
Load Balancing
Slide 25
Slide 25 text
Distributed Persistent Storage
Slide 26
Slide 26 text
Backups
Slide 27
Slide 27 text
Premium support
Slide 28
Slide 28 text
We monitor you cluster, ensure it's working and tell you if something is wrong
Slide 29
Slide 29 text
German company with German datacenters
Slide 30
Slide 30 text
You can focus on what is important
Slide 31
Slide 31 text
But this talk is about how to use Kubernetes
Slide 32
Slide 32 text
Not only for production workloads
Slide 33
Slide 33 text
But in your development workflows
Slide 34
Slide 34 text
Kubernetes has standardized apis
Slide 35
Slide 35 text
More and more integrations
Slide 36
Slide 36 text
Great tools
Slide 37
Slide 37 text
Agenda
Slide 38
Slide 38 text
Introduction to Kubernetes
Slide 39
Slide 39 text
Deployment of a simple application
Slide 40
Slide 40 text
Deployment of a micro-service application
Slide 41
Slide 41 text
Some tools for development with Kubernetes
Slide 42
Slide 42 text
But first
Slide 43
Slide 43 text
Why containers?
Slide 44
Slide 44 text
Services run in isolation
Slide 45
Slide 45 text
Everything needed to run a service in one image
Slide 46
Slide 46 text
Decouple Ops and Dev
Slide 47
Slide 47 text
Make things …
Slide 48
Slide 48 text
Easier to deploy
Slide 49
Slide 49 text
Easier to upgrade system dependencies
Slide 50
Slide 50 text
Easier to scale
Slide 51
Slide 51 text
Easier to develop
Slide 52
Slide 52 text
Kubernetes helps you deploying containers
Slide 53
Slide 53 text
Kubernetes helps you running containers
Slide 54
Slide 54 text
Kubernetes helps you scaling containers
Slide 55
Slide 55 text
Let’s define some core concepts and terminology first
Slide 56
Slide 56 text
Kubernetes Cluster
Slide 57
Slide 57 text
• A docker image built from a Dockerfile that contains everything a service needs to run Image
Slide 58
Slide 58 text
• A container runs a docker image. • Only 1 process can run inside of a container Container
Slide 59
Slide 59 text
• A group of 1 or more containers • Same port space • Ports are not accessible from outside of the pod Pod
Slide 60
Slide 60 text
• Defines and manages how many instances of a pod should run Replica Set
Slide 61
Slide 61 text
• Manages updates and rollbacks of replica sets Deployment
Slide 62
Slide 62 text
• Makes a port of a pod accessible to other pods Service
Slide 63
Slide 63 text
• Makes a service accessible to the outside of Kubernetes Ingress
Slide 64
Slide 64 text
Volumes, ConfigMaps, Secrets, PersistentVolumeClaims, CronJobs, StatefulSets, ...
Slide 65
Slide 65 text
Everything is a resource
Slide 66
Slide 66 text
You interact with Kubernetes by creating, receiving, updating and deleting resources
Slide 67
Slide 67 text
Kubernetes has controllers to listen on these interactions and get the cluster in the desired state
Slide 68
Slide 68 text
kind: Deployment apiVersion: extensions/v1beta1 metadata: name: symfony-demo spec: template: spec: containers: - name: symfony-demo image: symfony-demo:1.1.0 ports: - containerPort: 80
Slide 69
Slide 69 text
$ kubectl create -f deployment.yaml
Slide 70
Slide 70 text
$ kubectl get deployments NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE symfony-demo 1 1 1 1 21h
Slide 71
Slide 71 text
$ kubectl get deployment symfony-demo -o yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: annotations: ... spec: ... template: ... spec: containers: - name: symfony-demo image: symfony-demo:1.1.0
Slide 72
Slide 72 text
$ kubectl delete deployment symfony-demo
Slide 73
Slide 73 text
Practical example
Slide 74
Slide 74 text
Preparations
Slide 75
Slide 75 text
We need a cluster
Slide 76
Slide 76 text
No content
Slide 77
Slide 77 text
No content
Slide 78
Slide 78 text
No content
Slide 79
Slide 79 text
Let’s deploy the symfony demo app
Slide 80
Slide 80 text
https:/ /github.com/symfony/demo
Slide 81
Slide 81 text
Demo
Slide 82
Slide 82 text
Dockerfile
Slide 83
Slide 83 text
Copy our code
Slide 84
Slide 84 text
Build the project
Slide 85
Slide 85 text
Composer install
Slide 86
Slide 86 text
yarn install
Slide 87
Slide 87 text
yarn run build
Slide 88
Slide 88 text
https:/ /docs.docker.com/develop/develop- images/multistage-build/
Slide 89
Slide 89 text
Build the image
Slide 90
Slide 90 text
docker build -t symfony-demo:2.0.0 .
Slide 91
Slide 91 text
Now we have to tell Kubernetes what to do with the image
Slide 92
Slide 92 text
Resources are defined in YAML or JSON
Slide 93
Slide 93 text
Deployment
Slide 94
Slide 94 text
kind: Deployment apiVersion: extensions/v1beta1 metadata: name: symfony-demo spec: template: metadata: labels: app: symfony-demo spec: containers: - name: symfony-demo image: symfony-demo:1.0.0 ports:
Slide 95
Slide 95 text
containers: - name: symfony-demo image: symfony-demo:1.0.0 ports: - containerPort: 80 livenessProbe: httpGet: path: / port: 80 timeoutSeconds: 1 initialDelaySeconds: 10 readinessProbe: httpGet: path: /
Slide 96
Slide 96 text
Many more options configurable
Slide 97
Slide 97 text
Many more options • Setting environment variables • Mounting volumes • Requesting resources • Defining upgrade strategies • Defining command • Configure networking • Configure the scheduler • Listen on lifecycle events • Configure system capabilities for the container • …
Slide 98
Slide 98 text
Service
Slide 99
Slide 99 text
kind: Service apiVersion: v1 metadata: name: symfony-demo spec: ports: - name: http port: 80 targetPort: 80 protocol: TCP selector: app: symfony-demo
Slide 100
Slide 100 text
Ingress
Slide 101
Slide 101 text
kind: Ingress apiVersion: extensions/v1beta1 metadata: name: symfony-demo spec: rules: - host: symfony-demo.local.k8s http: paths: - path: / backend: serviceName: symfony-demo servicePort: 80
Slide 102
Slide 102 text
Creating everything
Slide 103
Slide 103 text
kubectl apply -f deployment/webapp.yaml
Slide 104
Slide 104 text
No content
Slide 105
Slide 105 text
Rolling Deployments
Slide 106
Slide 106 text
kind: Deployment apiVersion: extensions/v1beta1 metadata: name: symfony-demo spec: template: spec: containers: - name: symfony-demo image: symfony-demo:1.1.0 ports: - containerPort: 80
Slide 107
Slide 107 text
kubectl apply -f deployment/webapp.yaml
Slide 108
Slide 108 text
Writing this YAML files is tedious
Slide 109
Slide 109 text
YAML files are tied to a specific version and a specific environment
Slide 110
Slide 110 text
Production
Slide 111
Slide 111 text
Staging
Slide 112
Slide 112 text
Development
Slide 113
Slide 113 text
Per Development team
Slide 114
Slide 114 text
Per branch
Slide 115
Slide 115 text
Per developer
Slide 116
Slide 116 text
Built-in
Slide 117
Slide 117 text
Namespaces
Slide 118
Slide 118 text
Still we'd need to maintain multiple very similar YAML files with slightly different versions and configuration.
Slide 119
Slide 119 text
"Templating"
Slide 120
Slide 120 text
Great tools because of standardized Kubernetes API
Slide 121
Slide 121 text
Helm
Slide 122
Slide 122 text
No content
Slide 123
Slide 123 text
Allows to install applications
Slide 124
Slide 124 text
So called "charts"
Slide 125
Slide 125 text
Writing your own charts if fairly easy
Slide 126
Slide 126 text
Charts can depend on other charts
Slide 127
Slide 127 text
Multiple deployments of one chart possible
Slide 128
Slide 128 text
Different namespaces
Slide 129
Slide 129 text
Different release names
Slide 130
Slide 130 text
Configuration over values
Slide 131
Slide 131 text
No content
Slide 132
Slide 132 text
Different versions
Slide 133
Slide 133 text
Different ingress urls
Slide 134
Slide 134 text
$ helm install stable/wordpress --namespace bastian --name my-wordpress --values dev.yaml --values bastian.yaml
Slide 135
Slide 135 text
Still:
Slide 136
Slide 136 text
Make a code change
Slide 137
Slide 137 text
Build docker image
Slide 138
Slide 138 text
Push docker image
Slide 139
Slide 139 text
Run helm install/upgrade with new image version
Slide 140
Slide 140 text
Can this be quicker?
Slide 141
Slide 141 text
Forge
Slide 142
Slide 142 text
No content
Slide 143
Slide 143 text
Similar templating to helm
Slide 144
Slide 144 text
Services can depend on other services
Slide 145
Slide 145 text
$ forge deploy
Slide 146
Slide 146 text
Supports different profiles
Slide 147
Slide 147 text
$ forge --profile staging deploy
Slide 148
Slide 148 text
$ forge --profile bastian deploy
Slide 149
Slide 149 text
Different profiles can deploy to different namespaces with different ingress hostnames
Slide 150
Slide 150 text
Default profile can be dependent on the branch you are building from
Slide 151
Slide 151 text
You can use the branch name in templates
Slide 152
Slide 152 text
Demo application
Slide 153
Slide 153 text
web quote-svc hello-svc
Slide 154
Slide 154 text
Not all services have an ingress
Slide 155
Slide 155 text
Accessing Kubernetes from the outside
Slide 156
Slide 156 text
web quote-svc hello-svc
Slide 157
Slide 157 text
Getting a shell in a running container
Slide 158
Slide 158 text
$ kubectl exec $POD_NAME -i -t -- /bin/bash
Slide 159
Slide 159 text
Port forwarding through kubectl
Slide 160
Slide 160 text
$ kubectl port-forward pod/$POD_NAME 8080:80
Slide 161
Slide 161 text
$ kubectl port-forward service/$SERVICE_NAME 8080:80
Slide 162
Slide 162 text
Still, if you make a code change you have to commit, push, build, deploy
Slide 163
Slide 163 text
Takes some time
Slide 164
Slide 164 text
What about step debugging?
Slide 165
Slide 165 text
Of course you can run everything locally
Slide 166
Slide 166 text
But you develop only on one service
Slide 167
Slide 167 text
There may be lots of services
Slide 168
Slide 168 text
Telepresence
Slide 169
Slide 169 text
No content
Slide 170
Slide 170 text
Creates a two-way proxy between the Kubernetes cluster and you
Slide 171
Slide 171 text
$ 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/" } ]
Slide 172
Slide 172 text
Swap a running deployment in the cluster with a local process
Slide 173
Slide 173 text
... or a locally running docker container
Slide 174
Slide 174 text
$ 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!
Slide 175
Slide 175 text
Demo
Slide 176
Slide 176 text
Summary
Slide 177
Slide 177 text
Powerful
Slide 178
Slide 178 text
Helpful
Slide 179
Slide 179 text
Great tooling because of common APIs
Slide 180
Slide 180 text
Especially great if you have multiple services and don't want to run everything locally
Slide 181
Slide 181 text
http:/ /speakerdeck.com/ u/bastianhofmann
Slide 182
Slide 182 text
[email protected]
https:/ /twitter.com/BastianHofmann