Professional Documents
Culture Documents
JTC01
Microservices and Docker
Basic
Concepts
Niklaus Hirt
DevOps Architect / Cloud Architect
nikh@ch.ibm.com
Welcome to the
Kubernetes
Workshop Series
2
Housekeeping
Questions:
In Slack # (not in Webex!)
Adressed at the end of the Module
Additional questions: unmute to speak
3
Who am I?
Niklaus Hirt
Passionate about tech for over 35 years
• High-school in Berne
• Degree in Computer Science at EPFL
• ELCA
• CAST
• IBM
nikh@ch.ibm.com
@nhirt
4
Agenda – Microservices and Docker - Basic Concepts
5
Sources and
documentation will be
available here:
https://github.com/niklaushirt/k8s_training_public
https://github.com/niklaushirt/training
6
Kubernetes Workshop Series
00
Prepare the Labs
Session Objectives
Attendees will run their own Personal
Training Environment (PTE) in the VM.
8
JTC90 Lab Setup
9
Accessing your Personal Training Environment
Dismiss Update
10
Accessing your Personal Training Environment
11
Accessing your Personal Training Environment
Start Terminal
12
Accessing your Personal Training Environment
13
Accessing your Personal Training Environment
When completed, your PTE and Kubernetes Dashboard will open automatically
15
JTC90 Lab Setup
EVERYBODY
Task 1: Download Training VM
OK
Task 2: Setup VMWare / VirtualBox
Task 3: Start Training VM
Task 4: Login / ?
Check
16
Accessing your Personal Training Environment
Name will be shown
!
The Complete Button
might not show instantly
depending on the course
settings
18
Following your progress
Course title
19
Instructor Dashboard
Remaining Time for the Lab
20
QUESTIONS?
Kubernetes Workshop Series
01
Microservices
disruption
dɪsˈrʌpʃn/
noun
23
Disruption is new reality
disruption
dɪsˈrʌpʃn/
noun
Most
enterprises Co-existence between
are here
legacy and cloud-native
Cloud Native
Time
Legacy
Microservices
Coexistence
New features
to existing
applications 25
How do you achieve digital
transformation?
26
Microservices
27
Microservices architecture
Simplistically, microservices architecture is about breaking down large silo
applications into more manageable, fully decoupled pieces
UI UI
Data
Business Microservice Microservice
Access
Logic
Layer
DB DB DB DB
28
Example application using
microservices
29
Microservices – key tenets
32
Cloud-Native Application Goals
Horizontal scaling
• Application runs in multiple runtimes spread across
multiple hosts (VIII)
Immutable deployment
• A runtime is not patched, it’s replaced (IX)
• A runtime is stateless (VI)
• Shared functionality in backing services ( IV)
Elasticity
• Automatic scale-out and scale-in to maintain performance
• Achieved via containerization
Pay-as-you-go charging model
• Pay for what you use
https://12factor.net/
33
7
13. Observable
Apps should provide visibility about current health and metrics
14. Schedulable
Apps should provide guidance on expected resource constraints
missing
15. Upgradable
Apps must upgrade data formats from prior generations
16. Least privileged
Apps should provide guidance on expected resource constraints
factors
17. Auditable
Apps should provide appropriate audit logs for compliance needs
18. Access Control (Identity, Network, Scope, Certificates)
Protect app and resources from the world
19. Measurable
Apps usage should be measurable for quota or chargebacks
https://medium.com/@ssriva/7-missing-factors-from-12-factor-application-2a3e1169bd9d
34
That said….
35
Microservices
are
hard
36
Microservices, when
implemented incorrectly,
can make poorly written
applications even more
dysfunctional
37
..but we’re
getting ahead
of ourselves
38
QUESTIONS?
Kubernetes Workshop Series
02
Docker
Everybody Loves Containers
41
Microservices implementation with Containers
Development Operations
• Worries about what’s “inside” the container • Worries about what’s “outside” the container
• Code • Logging
• Libraries • Remote Access
• Package Manager • Monitoring
• Apps • Network Config
• Data
• All containers start, stop, copy, attach, migrate,
• All Linux servers look the same etc… the same way
cgroups warden
2007 2011 2014 2018
https://en.wikipedia.org/wiki/LXC
43
VMs vs. Containers
44
VMs vs. Containers
45
Advantages of Containers
46
Docker Components
Container
Smallest compute unit
Container
47
Docker Components
Containers
are created from
Images
Image Container
48
Docker Components
As many Containers
as needed can be created from
Images
Container
Image Container
Container
Container
49
Docker Components
Image Registry
myregistry/webapp
webapp:latest
webapp:v2.0 Image
webapp:v1.1
webapp:v1.0
Image Container
.
.
webapp:2.0
.
Image
myregistry/mongodb
mongodb:latest
mongodb:v2.0
mongodb:v1.1 Image
mongodb:v1.0
50
Docker Components
Image Image
A read-only snapshot of a container stored in Docker Hub to be used as a template for building containers
Container
The standard unit in which the application service resides or transported
SaaS Enterprise
Docker Hub/Registry
Available in SaaS or Enterprise to deploy anywhere you choose
Stores, distributes, and shares container images
Docker Engine
A program that creates, ships, and runs application containers
Runs on any physical and virtual machine or server locally, in private or public cloud. Client communicates
with Engine to execute commands
51
Docker Basics – Build
Registry
Dockerfile Local
Docker
Engine
Config
52
Docker Basics – Build - Dockerfile
Dockerfile
• Text based file describing:
• Previous Layer
• Environment Variables
Image
• Commands used to populate
data/software/frameworks/etc…
• Command to run when executed
53
Docker Basics – Build - Dockerfile Base Image from:
• hub.docker.com
• A text file that builds an image using Docker directives • quay.io
• your own
• FROM
• RUN # Pull base image Run commands
• COPY FROM tomcat:8-jre8
• ENTRYPOINT apt-get, yum, chown, mv, cp, …
• LABEL # Maintainer
MAINTAINER "youremailaddress"
• ENV
• ARG # Run command Set environment variables
• USER
• EXPOSE
RUN apt-get update && apt-get -y upgrade Can be overriden when running
# Set variables
ENV myName John Doe
Add assets to the image
# Copy to images tomcat path
ADD web.xml /usr/local/tomcat/conf/ Jar, sources, golang app, …
ADD yourwarfile.war /usr/local/tomcat/webapps/
Docker Layers
Inheritance
cmd
• Build on the work of those who came before you
# Pull base image expose 80
FROM tomcat:8-jre8
tomcat:8-jre8
56
Docker Basics – Run
Registry
Dockerfile Local
Docker
Engine
Config
Docker Engine
OS
57
Docker Basics – Run
Docker Layers
Writable
Inheritance expose 80
tomcat:8-jre8
58
Docker Basics – Run
Docker run
• Local (containerd)
Image Container
59
Docker Basics – Run – CMD vs ENTRYPOINT
https://phoenixnap.com/kb/docker-cmd-vs-entrypoint
60
Docker Basics – Store, Retrieve & Run with registry
Registry
Dockerfile Local Docker
Docker Docker pull
Engine Registry
Docker Docker Docker
Code
build push run
Config
Docker Engine
OS
61
Docker Basics – Store & Retrieve
Docker Registry
• Private Local
• Public Docker Hub
• Private Shared
docker images
Docker Engine
myregistry/webapp
webapp:latest
webapp:v2.0
webapp:v1.1
webapp:v1.0
myregistry/mongodb
Image Image mongodb:latest
mongodb:v2.0
mongodb:v1.1
Image Image mongodb:v1.0
62
Docker Basics – Store & Retrieve with registry
myregistry/webapp
webapp:latest
webapp:v2.0 Image
webapp:v1.1
Docker Engine webapp:v1.0 Docker Engine
.
docker push myregistry/myimage:1.0.0
. docker pull myregistry/myimage:latest
. Image
myregistry/mongodb
mongodb:latest
mongodb:v2.0
mongodb:v1.1 Image
mongodb:v1.0
63
Docker Basics – Registries
64
Docker Recap
65
QUESTIONS?
Kubernetes Workshop Series
03
Let‘s get real
Microservice transformations – The good, the bad, the ugly
The good
Source: https://caylent.com/microservices-good-bad-ugly/ 68
Microservice transformations – The good, the bad, the ugly
The bad
• Added management complexity
• Expertise required to maintain a microservice-based application
• No or reduced benefits if application doesn’t need scaling or cloud
transformation
• Needs more robust testing in order to cover all APIs
Source: https://caylent.com/microservices-good-bad-ugly/ 69
Microservice transformations – The good, the bad, the ugly
• May require high initial investment to run for Dev, deployment and Ops
overhead
• Higher initial operational and monitoring costs through shift in paradigms
• Non-uniform application design and architecture through free choice of
technologies
• Overload of documentation for every individual component app
Source: https://caylent.com/microservices-good-bad-ugly/ 70
Microservices, when
implemented incorrectly,
can make poorly written
applications even
more dysfunctional
71
Microservices – breaking down the monolith beast
Source: https://www.simplethread.com/youre-not-actually-building-microservices/
72
Databases
73
Microservices – Database refactoring
Simplistically, microservices architecture is about breaking down large silo
applications into more manageable, fully decoupled pieces
UI UI
Data
Business Microservice Microservice
Access
Logic
Layer
DB DB DB DB
Source: https://martinfowler.com/bliki/BoundedContext.html 75
Microservices – Bounded Context
Opportunity
Customer
Ticket
Pipeline Territiory
Product
Defect
Sales Person
Product Version
Source: https://martinfowler.com/bliki/BoundedContext.html 76
Microservices – Bounded Context
Support Domain
Opportunity
Customer Customer
Ticket
Pipeline Territiory
Product Product
Defect
Sales Person
Product Version
Sales Domain
Source: https://martinfowler.com/bliki/BoundedContext.html 77
Microservices – Bounded Context
Support Domain
Opportunity DB DB
Opportunity CustomerCustomer
Customer
Ticket
Pipeline Territory
Territiory
Defect
Sales
DB Sales Person DB DB
Person
Product Version
Sales Domain
Source: https://martinfowler.com/bliki/BoundedContext.html 78
Microservices – Database refactoring
Common mistake
Rest API Rest API Rest API Rest API Rest API Rest API Rest API
Microservice
Component
Silo
Component Microservice Microservice
Component Component
Challenges
• Inability to deploy your service changes independently through
tight coupling.
• Schema changes need to be coordinated amongst all the services
• Difficult to scale individual services
• All your services have to use a relational database even when a
no-SQL datastore would bring benefits
• Difficult to improve application performance (DB/Table size)
Source: https://dzone.com/articles/breaking-the-monolithic-database-in-your-microserv
80
Microservices – Database refactoring
Data Isolation
Each microservice must keep its own data. One typical error that happens in the beginning of a microservice
transformation is the use of a centralized database, the same way it was used in the monolithic application. This creates a
single point of failure and dependency between the microservices.
Rest API Rest API Rest API Rest API Rest API Rest API Rest API
Customer
Details
Silo
Component Customer Customer
Address Accounts
Data Isolation
Each microservice must keep its own data. One typical error that happens in the beginning of a microservice
transformation is the use of a centralized database, the same way it was used in the monolithic application. This creates a
single point of failure and dependency between the microservices.
Rest API Rest API Rest API Rest API Rest API Rest API Rest API
Customer
Details
Silo
Component Customer Customer
Address Accounts
Benefits
• Avoid unexpected data modification – the API enforces consitency
• Make changes to our system without blocking progress
of other parts of the system
• Store the data in a project-owned databases, using the
appropriate technology
• Make changes to the schema/databases at our leisure
• Become much more scalable, fault tolerant, and flexible
Source: https://blog.christianposta.com/microservices/the-hardest-part-about-microservices-data/
83
Microservices – per-service database
Drawbacks
• Costly to refactor
• Introduces latency
• Needs robust transaction handling by the service (cost!)
• More difficult to debug
• More difficult to operationalize
• More difficult to test (needs well designed API tests)
Source: https://blog.christianposta.com/microservices/the-hardest-part-about-microservices-data/
84
Event Driven
Architecture
85
Microservices – one step further
Event-Driven Architecture
• Common pattern to maintain data consistency
across different services. Get Customer Details
• Avoid waiting for ACID transactions to complete
• Makes your application more available and
Address Queue Account Queue
performant
• Provides loose coupling between services Rest API
Customer
Details
Customer Customer
Address Accounts
Source: https://dzone.com/articles/breaking-the-monolithic-database-in-your-microserv
86
Microservices
Good or bad idea?
87
Microservices – reasons not to use them
Some thoughts
• If speed is your goal, microservices aren't the solution (MVP, doesn’t have to scale)
• Applications that require tight integration between individual components
and services (real-time processing, …)
• At what point is it in its lifecycle? Mission-critical?
• A moderately large, moderately complex application being maintained by a
relatively small development and operations team
• Not all applications are large enough to break down into microservices
Source: https://blog.christianposta.com/microservices/when-not-to-do-microservices/
88
Microservices – reasons not to use them
Source: https://www.simplethread.com/youre-not-actually-building-microservices/
89
Microservices – reasons not to use them
Source: https://blog.runscope.com/posts/5-reasons-not-to-use-microservices
90
Microservices – reasons not to use them
https://docs.google.com/spreadsheets/d/1vjnjAII_8TZBv2XhFHra7kEQzQpOHSZpFIWDjynYYf0/edit?pli=1#gid=0
91
QUESTIONS?
Everybody Loves Containers
93
Everyone’s container journey starts with one container….
94
At first the growth is easy to handle….
95
Pets vs Cattle
But soon you have many applications, many instances…
96
But more on
this next week…..
Kubernetes Workshop Series
04
Docker - Hands-On
Starting Course JTC01 Docker
Name will be shown
100
READY
SET
GO!!!!
Duration: 60 mins
101
QUESTIONS?
Kubernetes – Some Reading Tips
https://kubernetes-security.info/
103
Sources and
documentation will be
available here:
https://github.com/niklaushirt/k8s_training_public
https://github.com/niklaushirt/training
104
See you next week!
• Same place
• Same time
Kubernetes Workshop
Series
Kubernetes
Niklaus Hirt
nikh@ch.ibm.com
@nhirt
106
THANK YOU!!!!
107