Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Running Microservices Successfully
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Bastian Hofmann
August 11, 2018
Programming
98
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Running Microservices Successfully
Bastian Hofmann
August 11, 2018
More Decks by Bastian Hofmann
See All by Bastian Hofmann
Monitoring in Kubernetes with Prometheus and Grafana
bastianhofmann
0
360
Creating a fast Kubernetes Development Workflow
bastianhofmann
0
150
Highly available cross-region deployments with Kubernetes
bastianhofmann
1
170
From source to Kubernetes in 30 minutes
bastianhofmann
0
200
Introduction to Kubernetes
bastianhofmann
1
140
CI/CD with Kubernetes
bastianhofmann
0
250
Creating a fast Kubernetes Development Workflow
bastianhofmann
1
290
Deploying your first Micro-Service application to Kubernetes
bastianhofmann
2
210
Creating a fast Kubernetes Development Workflow
bastianhofmann
0
280
Other Decks in Programming
See All in Programming
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
1k
GitHubCopilotCLIのスラッシュコマンドを自作してみる
htkym
0
100
霧の中の代数的エフェクト
funnyycat
1
410
どこまでゆるくて許されるのか
tk3fftk
0
520
Prismを使った型安全な暗号化_関数型まつり2026
_fhhmm
0
150
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
9.2k
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
400
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
0
250
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
1
240
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
220
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
270
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
247
13k
Evolving SEO for Evolving Search Engines
ryanjones
0
240
Building Adaptive Systems
keathley
44
3.1k
Building Applications with DynamoDB
mza
96
7.1k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
410
The Spectacular Lies of Maps
axbom
PRO
1
870
Prompt Engineering for Job Search
mfonobong
0
380
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
550
WCS-LA-2024
lcolladotor
0
740
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
It's Worth the Effort
3n
188
29k
Transcript
@BastianHofmann Running Microservices Successfully Bastian Hofmann
Microservices
Monolith
http:/ /blog.philipphauer.de/microservices-nutshell-pros-cons/ Monolith Microservices
" Microservices are great for turning method calls in to
distributed computing problems https:/ /twitter.com/tenderlove/status/1027591532847816704
Challenges
Performance
Latency
Operational overhead
Monitoring
Learning Curves
Code Reuse
Maintenance
Benefits
Enforces stricter separation of concerns
Diverse technology stacks
Independent scaling
Independent development
Independent deployments
There are good reasons to split off functionality into independent
services
How to run Microservices without shooting yourself in the foot
Let's talk about • Deploying • Running • Configuring •
Discovering • Monitoring • Scaling
A lot of this is also useful for monoliths
https:/ /www.flickr.com/photos/npobre/2601582256/
Let's define our requirements
Deployment
How to get the services on our servers?
Diverse technology stacks
The same approach for every service
Fast deployments
Automation
One Click Deployment
Fast rollbacks
Availability
Zero Downtime Deployments
Running the service
How do I stop and start a service and ensure
it keeps running?
Diverse technology stacks
Diverse system dependencies
The same approach for every service
Configuration Management
How do I synchronize configuration over services?
Config file on disk
[ "db_user": "user", "db_pw": "pw", "serviceA": "serviceA.local:8018" ]
Duplication
Inconsistencies
Security
Cycling of credentials
Service Discovery
How does one service know where another service is?
Load balancing?
Service/Server down?
Health checks
Monitoring
How do I know how my application is behaving?
Distributed Systems
We want to measure
Latency
Availability
Throughput
We want all logs aggregated and searchable
Scaling
How can I cope with growing traffic?
Reacting to changes in traffic?
You have to take care about a lot of things
when doing Microservices!
There are tools that can help us with this
None
Container orchestration platform
Deploy, run and scale your services in isolated containers
Very Powerful
Large community
Lot’s of large company backers
Compared to other cloud technoligies
No vendor lock in
Runs on
AWS
Azure
Google Cloud Platform
Bare metal
Your laptop
SysEleven
Learning curve
Why containers?
Services run in isolation
Everything needed to run a service in one image
Decouple Ops and Dev
Make things …
Easier to deploy
Easier to upgrade system dependencies
Easier to scale
Easier to develop
Leaner than Virtual Machines
None
FROM php:7.2-apache WORKDIR /var/www/html RUN apt-get update -y && \
apt-get install -y --no-install-recommends curl \ rm -rf /var/lib/apt/lists/* ENV TMP_DIR /tmp COPY . /var/www/html/ EXPOSE 80 ENTRYPOINT [“apache2”, “-DFOREGROUND”]
docker build -t symfony-demo:2.0.0 .
docker run -p 8080:80 symfony-demo:2.0.0
Kubernetes helps you running containers
Let’s define some core Kubernetes concepts
Kubernetes Cluster
• A physical server • Containers get distributed automatically Node
• A docker image built from a Dockerfile that contains
everything a service needs to run Image
• A container runs a docker image. • Only 1
process can run inside of a container Container
• A group of 1 or more containers • Same
port space • Ports are not accessible from outside of the pod Pod
• Defines and manages how many instances of a pod
should run Replica Set
• Manages updates and rollbacks of replica sets Deployment
• Makes a port of a pod accessible to other
pods Service
• Makes a service accessible to the outside of Kubernetes
Ingress
• Configuration that can be mounted inside of a container
ConfigMap
• Volumes can be mounted into a container to access
a ConfigMap, Secret or a folder on the host Volumes
Example
PHP-FPM NGINX ISTIO STATSD MEM CACHED MONGO ROUTER PHP Application
POD
PHP-FPM NGINX ISTIO STATSD MEM CACHED MONGO ROUTER PHP Application
POD ReplicaSet: 2 instances PHP-FPM NGINX ISTIO STATSD MEM CACHED MONGO ROUTER PHP Application POD
PHP-FPM NGINX ISTIO STATSD MEM CACHED MONGO ROUTER ReplicaSet: 2
instances PHP-FPM NGINX ISTIO STATSD MEM CACHED MONGO ROUTER CONFIG WEB :80 PHP Application POD PHP Application POD
PHP-FPM NGINX ISTIO STATSD MEM CACHED MONGO ROUTER ReplicaSet: 2
instances PHP-FPM NGINX ISTIO STATSD MEM CACHED MONGO ROUTER CONFIG WEB :80 https://php-app.k8s.foo.com:443/ PHP Application POD PHP Application POD
Let’s deploy the symfony demo app
https:/ /github.com/symfony/demo
First we need a Kubernetes cluster
None
None
None
None
kubectl
$ kubectl get pods
NAME READY STATUS RESTARTS AGE kubernetes-dashboard-5b5bf59977-t9xb9 1/1 Running 2 9d
nginx-ingress-controller-5549f5597c-97kcw 0/1 Running 2 9d nginx-ingress-default-backend-564d9d9477-tmnnr 1/1 Running 4 9d mysql-556c9b5bcb-5jdrt 1/1 Running 1 8d symfony-demo-5b75f5fc6-c7wr9 1/1 Running 0 8d symfony-demo-5b75f5fc6-jg8n4 1/1 Running 23 8d
Demo
Creating a Docker image
PHP
Copy our code
Build the project
Composer install
yarn install
yarn run build
Building the image
docker build -t symfony-demo:2.0.0 .
Now we have to tell Kubernetes what to do with
the image
Resources are defined in YAML or JSON
Deployment
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:
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: /
Many more options configurable
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 • …
Service
kind: Service apiVersion: v1 metadata: name: symfony-demo spec: ports: -
name: http port: 80 targetPort: 80 protocol: TCP selector: app: symfony-demo
Ingress
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
Creating everything
kubectl apply -f deployment/webapp.yaml
None
Rolling Deployments
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
kubectl apply -f deployment/webapp.yaml
Rollback
$ kubectl rollout undo deployments symfony-deom --to- revision=1
Configuration
Should not be included in the docker image
ConfigMap
Key/Value Store
kind: ConfigMap apiVersion: v1 metadata: name: special-config data: special-key: value
bool-value: true
Can be accessed in a pod through environment variables
spec: containers: - name: test-container image: k8s.gcr.io/busybox command: [ "/bin/sh",
"-c", "env" ] env: - name: SPECIAL_KEY valueFrom: configMapKeyRef: name: special-config key: special-key
spec: containers: - name: test-container image: k8s.gcr.io/busybox command: [ "/bin/sh",
"-c", "env" ] envFrom: - configMapRef: name: special-config
Can be accessed through volumes
spec: containers: - name: test-container image: k8s.gcr.io/busybox command: [ "/bin/sh",
"-c", "ls /etc/config/" ] volumeMounts: - name: config-volume mountPath: /etc/config volumes: - name: config-volume configMap: name: special-config
Service Discovery
Within a pod
Shared port namespace
Separate file systems
Separate process spaces
Network wise everything behaves like localhost
Between pods
You have to expose ports with services
kind: Service apiVersion: v1 metadata: name: symfony-demo spec: ports: -
name: http port: 80 targetPort: 80 protocol: TCP selector: app: symfony-demo
Every service has a virtual IP address
$ kubectl get service symfony-demo NAME TYPE CLUSTER-IP PORT(S) AGE
symfony-demo ClusterIP 10.106.119.24 80/TCP 6d
Discoverable in other containers by
Environment Variables
SYMFONY_DEMO_SERVICE_HOST=10.106.119.24 SYMFONY_DEMO_SERVICE_PORT=80
DNS
$ nslookup symfony-demo Server: 10.0.0.10 Address 1: 10.0.0.10 Name: symfony-demo
Address 1: 10.106.119.24
$ curl http://symfony-demo
Service Mesh
Istio https:/ /istio.io/
LinkerD https:/ /linkerd.io/
PHP-FPM NGINX ISTIO STATSD MEM CACHED MONGO ROUTER PHP Application
POD
PHP-FPM NGINX ISTIO STATSD MEM CACHED MONGO ROUTER PHP Application
POD NodeJS ISTIO NodeJS Service POD NodeJS ISTIO NodeJS Service POD
PHP-FPM NGINX ISTIO STATSD MEM CACHED MONGO ROUTER PHP Application
POD NodeJS ISTIO NodeJS Service POD NodeJS ISTIO NodeJS Service POD
PHP-FPM NGINX ISTIO STATSD MEM CACHED MONGO ROUTER PHP Application
POD NodeJS ISTIO NodeJS Service POD NodeJS ISTIO NodeJS Service POD
PHP-FPM NGINX ISTIO STATSD MEM CACHED MONGO ROUTER PHP Application
POD NodeJS ISTIO NodeJS Service POD NodeJS ISTIO NodeJS Service POD
Benefits
Advanced routing
Prefer service in current namespace, fall back to default namespace
A/B Testing https:/ /medium.com/vamp-io/a-b-testing-on-kubernetes-with-istio-0-8-6323efa2b4e2
Canary deployments https:/ /istio.io/blog/2017/0.1-canary/
Circuit Breakers https:/ /istio.io/docs/tasks/traffic-management/circuit-breaking/
Security https:/ /istio.io/blog/2017/0.1-auth/
Advanced monitoring
None
Profiling
None
Monitoring
Metrics-Server
Takes metrics from Kubernetes and stores them in a monitoring
solution
e.g. Prometheus
Combine with metrics of other components
Service Mesh
Your services
Grafana for displaying the data
None
None
Logging
kubectl logs
$ kubectl logs symfony-demo-5b75f5fc6-c7wr9
One interface
Easy to pipe into central log management system
Scaling
Manual Scaling
kubectl scale --replicas=3 deployment/my-app
AutoScaling
https:/ /kubernetes.io/docs/user-guide/ horizontal-pod-autoscaling/
Summary
Powerful
Helpful
Together with the whole Eco-System
And Docker
Kubernetes helps you to run microservices successfully
By standardizing Deployment, Scaling, Configuration, Monitoring, Service Discovery, Health Checks,
...
http:/ /speakerdeck.com/ u/bastianhofmann
Vielen Dank für Ihre Aufmerksamkeit!