B u i l d a 1 2 F a c t
- r
M i c r
- s
e r v i c e i n a n H
- u
r
A n d r e w R
- u
s e : O p e n L i b e r t y D e v e l
- p
e r f
- r
M i c r
- P
r
- f
l e a n d C D I , I B M @a z q u e l t
B u i l d a 1 2 F a c t o r M i c r o s e r v - - PowerPoint PPT Presentation
B u i l d a 1 2 F a c t o r M i c r o s e r v i c e i n a n H o u r A n d r e w R o u s e : O p e n L i b e r t y D e v e l o p e r f o r M i c r o P r o f l e a n d
A n d r e w R
s e : O p e n L i b e r t y D e v e l
e r f
M i c r
r
l e a n d C D I , I B M @a z q u e l t
C
t e n t s
B a s i c c
c e p t s
1 2 f a c t
a p p s D e mo
c r e a t i n g a 1 2 f a c t
mi c r
e r v i c e u s i n g M i c r
r
l e
1 2 F a c t
s i n a n u t s h e l l
– A me t h
y – B e s t P r a c t i c e s – M a n i f e s t
t t p s : / / 1 2 f a c t
. n e t / b y H e r
u
Wh y 1 2 f a c t
?
e f n e t h e c
t r a c t b e t w e e n a p p l i c a t i
s a n d i n f r a s t r u c t u r e
Application Infrastructure
T H E F A C T O R S
1 .C
e b a s e 2 .D e p e n d e n c i e s 3 .C
f g 4 .B a c k i n g S e r v i c e s 5 .B u i l d , R e l e a s e , R u n 6 .P r
e s s e s 7 .P
t b i n d i n g 8 .C
c u r r e n c y 9 .D i s p
a b i l i t y 1 . D e v / P r
p a r i t y 1 1 . L
s 1 2 . A d mi n P r
e s s e s
Wh y 1 2 f a c t
?
I n t h e mo d e r n e r a , s
t w a r e i s c
n l y d e l i v e r e d a s a s e r v i c e : c a l l e d w e b a p p s ,
s
t w a r e
s
e r v i c e . T h e t w e l v e
a c t
a p p i s a me t h
y f
b u i l d i n g s
t w a r e
s
e r v i c e a p p s t h a t : U s e d e c l a r a t i v e f
ma t s f
s e t u p a u t
t i
, t
n i mi z e t i me a n d c
t f
n e w d e v e l
e r s j
n i n g t h e p r
e c t ; H a v e a c l e a n c
t r a c t w i t h t h e u n d e r l y i n g
e r a t i n g s y s t e m,
f e r i n g ma x i mu m p
t a b i l i t y b e t w e e n e x e c u t i
e n v i r
me n t s ; A r e s u i t a b l e f
d e p l
me n t
mo d e r n c l
d p l a t f
ms ,
v i a t i n g t h e n e e d f
s e r v e r s a n d s y s t e ms a d mi n i s t r a t i
; M i n i mi z e d i v e r g e n c e b e t w e e n d e v e l
me n t a n d p r
u c t i
, e n a b l i n g c
t i n u
s d e p l
me n t f
ma x i mu m a g i l i t y ; A n d c a n s c a l e u p w i t h
t s i g n i f c a n t c h a n g e s t
i n g , a r c h i t e c t u r e ,
d e v e l
me n t p r a c t i c e s . T h e t w e l v e
a c t
me t h
y c a n b e a p p l i e d t
p p s w r i t t e n i n a n y p r
r a mmi n g l a n g u a g e , a n d w h i c h u s e a n y c
i n a t i
b a c k i n g s e r v i c e s ( d a t a b a s e , q u e u e , me mo r y c a c h e , e t c ) .
F r
h t t p s : / / 1 2 f a c t
. n e t
I . C
e b a s e
e d i c a t e s ma l l e r t e a ms t
n d i v i d u a l a p p l i c a t i
s
mi c r
e r v i c e s .
l
i n g t h e d i s c i p l i n e
s i n g l e r e p
i t
y f
a n a p p l i c a t i
f
c e s t h e t e a ms t
n a l y z e t h e s e a ms
t h e i r a p p l i c a t i
, a n d i d e n t i f y p
e n t i a l mo n
i t h s t h a t s h
l d b e s p l i t
f i n t
c r
e r v i c e s . “ O n e c
e b a s e t r a c k e d i n r e v i s i
c
t r
, ma n y d e p l
s . ”
s e a s i n g l e s
r c e c
e r e p
i t
y f
a s i n g l e a p p l i c a t i
( 1 : 1 r e l a t i
) .
. g . u s e a c e n t r a l g i t r e p
I I . D e p e n d e n c i e s
A c l
d
a t i v e a p p l i c a t i
d
s n
r e l y
t h e p r e
x i s t e n c e
d e p e n d e n c i e s i n a d e p l
me n t t a r g e t . D e v e l
e r T
s d e c l a r e a n d i s
a t e d e p e n d e n c i e s
a v e n a n d G r a d l e d e c l a r e J a v a l i b r a r y d e p e n d e n c i e s
k e r f l e d e c l a r e s d e p e n d e n c i e s
O S a n d
h e r t
s
a c h mi c r
e r v i c e d e c l a r e s i t s
n d e p e n d e n c i e s “ E x p l i c i t l y d e c l a r e a n d i s
a t e d e p e n d e n c i e s ”
I I I . C
f g
“ S t
e c
f g i n t h e e n v i r
me n t ”
h a n g i n g c
f g s h
l d n
n e e d t
e p a c k a g e y
r a p p l i c a t i
s e K u b e r n e t e s c
f g ma p s a n d s e c r e t s f
c
t a i n e r s e r v i c e s , r a t h e r t h a n v a l u e s s p e c i f e d i n t h e a p p
c
t a i n e r i ma g e
s e M i c r
r
l e C
f g t
n j e c t t h e c
f g p r
e r t i e s i n t
h e mi c r
e r v i c e s
App Password=blah
I V . B a c k i n g s e r v i c e s
“ T r e a t b a c k i n g s e r v i c e s a s a t t a c h e d r e s
r c e s ”
Application My SQL Amazon S3 Twitter
V . B u i l d , r e l e a s e , r u n
“ S t r i c t l y s e p a r a t e b u i l d a n d r u n s t a g e s ”
r c e c
e i s u s e d i n t h e b u i l d s t a g e . C
f g u r a t i
d a t a i s a d d e d t
e f n e a r e l e a s e s t a g e t h a t c a n b e d e p l
e d . A n y c h a n g e s i n c
e
c
f g w i l l r e s u l t i n a n e w b u i l d / r e l e a s e
e e d s t
e c
s i d e r e d i n C I p i p e l i n e
I B M
r b a n C
e D e p l
B M C l
d C
t i n u
s D e l i v e r y S e r v i c e A z u r e
i s u a l S t u d i
e a m S e r v i c e s ( V S T S ) ( i n c l u d e s g i t )
b A p p f
C
t a i n e r s f e a t u r e
A z u r e A p p S e r v i c e A WS
WS C
e B u i l d
WS C
e D e p l
WS C
e P i p e l i n e ( n
y e t i n t e g r a t e d w i t h E K S )
V I . P r
e s s e s
“ E x e c u t e t h e a p p a s
e
mo r e s t a t e l e s s p r
e s s e s ” ➢S t a t e l e s s a n d s h a r e
h i n g ➢A n y p e r s i s t e n c e u s e s a b a c k i n g s e r v i c e
–
D a t a b a s e
–
S h a r e d c a c h e
–
M e s s a g e q u e u e
V I I . P
t b i n d i n g
“ E x p
t s e r v i c e s v i a p
t b i n d i n g ”
p p l i c a t i
s a r e f u l l y s e l f
t a i n e d a n d e x p
e s e r v i c e s
l y t h r
g h p
t s . P
t a s s i g n me n t i s d
e b y t h e e x e c u t i
e n v i r
me n t
n g r e s s / s e r v i c e d e f n i t i
k 8 s ma n a g e s ma p p i n g
p
t s
s e M P C
f g t
n j e c t p
t s t
c r
e r v i c e s t
n e c t u p mi c r
e r v i c e s
P
t = 8
@I n j e c t @C
f g P r
e r t y ( n a me = ” p
t ” , d e f a u l t V a l u e = “ 9 8 ” )
V I I I . C
c u r r e n c y
“ S c a l e
t v i a t h e p r
e s s mo d e l ”
p p l i c a t i
s u s e p r
e s s e s i n d e p e n d e n t f r
e a c h
h e r t
c a l e
t ( a l l
i n g f
l
d b a l a n c i n g )
e c
s i d e r e d i n a p p l i c a t i
d e s i g n
l
d a u t
c a l i n g s e r v i c e s : [ a u t
s c a l i n g b u i l t i n t
8 s
u i l d mi c r
e r v i c e s
I X . D i s p
a b i l i t y
“ M a x i mi z e r
u s t n e s s w i t h f a s t s t a r t u p a n d g r a c e f u l s h u t d
n ”
r
e s s e s s t a r t u p f a s t .
r
e s s e s s h u t d
n g r a c e f u l l y w h e n r e q u e s t e d .
r
e s s e s a r e r
u s t a g a i n s t s u d d e n d e a t h
n s u r e y
w
’ t l
e d a t a i f p a r t
y
r s y s t e m d i e s
s e M i c r
r
l e F a u l t T
e r a n c e t
k e c a l l s t
h e r s e r v i c e s r e s i l i e n t
X . D e v / p r
p a r i t y
“ K e e p d e v e l
me n t , s t a g i n g , a n d p r
u c t i
a s s i mi l a r a s p
s i b l e ”
e v e l
me n t a n d p r
u c t i
a r e a s c l
e a s p
s i b l e ( i n t e r ms
c
e , p e
l e , a n d e n v i r
me n t s )
a n u s e h e l m t
e p l
i n r e p e a t a b l e ma n n e r
s e ( n a me ) s p a c e s f
i s
a t i
s i mi l a r s e t u p s
X I . L
s
“ T r e a t l
s a s e v e n t s t r e a ms ”
p p w r i t e s a l l l
s t
t d
t
s e a s t r u c t u r e d
t p u t f
me a n i n g f u l l
s s u i t a b l e f
a n a l y s i s . E x e c u t i
e n v i r
me n t h a n d l e s r
t i n g a n d a n a l y s i s i n f r a s t r u c t u r e
X I I . A d mi n p r
e s s e s
“ R u n a d mi n / ma n a g e me n t t a s k s a s
e
f p r
e s s e s ”
i n g : s t a n d a r d k 8 s t
i n g l i k e “ k u b e c t l e x e c ”
K u b e r n e t e s J
s
l s
e c
s i d e r e d i n s
u t i
/ a p p l i c a t i
d e s i g n
e x a mp l e , i f a n a p p l i c a t i
n e e d s t
g r a t e d a t a i n t
d a t a b a s e , p l a c e t h i s t a s k i n t
s e p a r a t e c
e n t i n s t e a d
a d d i n g i t t
h e ma i n a p p l i c a t i
c
e a t s t a r t u p
T H E F A C T O R S
1 .C
e b a s e 2 .D e p e n d e n c i e s 3 .C
f g 4 .B a c k i n g S e r v i c e s 5 .B u i l d , R e l e a s e , R u n 6 .P r
e s s e s 7 .P
t b i n d i n g 8 .C
c u r r e n c y 9 .D i s p
a b i l i t y 1 . D e v / P r
p a r i t y 1 1 . L
s 1 2 . A d mi n P r
e s s e s
D E M O
1 .C r e a t e a R E S T a p p ( s t a t e l e s s , i n
e c
e b a s e ) 2 .D e c l a r e
r d e p e n d e n c i e s u s i n g M a v e n a n d D
k e r f l e
– I
n c l u d i n g O p e n L i b e r t y 3 .R e l e a s e a n d R u n b y d e p l
i n g w i t h c
f g t
u b e r n e t e s 4 .U p d a t e
r a p p t
a l l a n
h e r s e r v i c e 5 .D e p l
a g a i n w i t h s c a l i n g
1
Codebase
2
Deps
3
Config
4
Backing Service
5
Build Release Run
6
Stateless
7
Port Binding
8
Scaling
9
Disposability
10
Prod, Dev, Staging
11
Logs
12
Admin Processes
R e f e r e n c e s
e s a mp l e t
e mo n s t r a t e 1 2
a c t
a p p
t t p s : / / g i t h u b . c
A z q u e l t / 1 2 f a c t
e p l
me n t
t t p s : / / g i t h u b . c
A z q u e l t / 1 2 f a c t
p p
t t p s : / / g i t h u b . c
A z q u e l t / 1 2 f a c t
p p
t t p : / / mi c r
r
l e . i
t t p : / /
e n l i b e r t y . i
e s p e c i a l l y g u i d e s )
t t p s : / / w w w . 1 2 f a c t
. n e t /
microservice Infrastructure K8s
1 2 f a c t
a p p
s e M i c r
r
l e a n d K 8 s t
u i l d a mi c r
e r v i c e = > 1 2 f a c t
a p p
microservice Infrastructure K8s
M i c r
r
l e C
f g
Wh y ?
– C
f g u r e M i c r
e r v i c e w i t h
t r e p a c k i n g t h e a p p l i c a t i
H
?
– S p e c i f y t h e c
f g u r a t i
i n c
f g u r a t i
s
r c e s – A c c e s s c
f g u r a t i
v i a
r
r a mma t i c l
u p Config config = ConfigProvider.getConfig(); config.getValue(“myProp”, String.class);
D I I n j e c t i
@Inject @ConfigProperty(name="my.string.property") String myProp;
M i c r
r
l e C
f g
S t a t i c C
f g D y n a mi c C
f g
@Inject @ConfiProperty(name="myStaticProp") private Strini staticProp; @Inject @ConfiProperty(name="myDynamicProp") private Provider<Strini> dynamicProp;
mi c r
r
l e
f g . p r
e r t i e s
my S t a t i c P r
= d e f a u l t S V a l u e my D y n a mi c P r
= d e f a u l t D V a l u e
J a v a O p t i
s
my S t a t i c P r
= c u s t
V a l u e
my D y n a mi c P r
= c u s t
V a l u e
e r r i d e s
M i c r
r
l e F a u l t T
e r a n c e
A s
u t i
t
u i l d a r e s i l i e n t mi c r
e r v i c e R e t r y
C i r c u i t B r e a k e r
B u l k H e a d
T i me
t
F a l l b a c k
B a c k u p : U s i n g I B M C l
d P r i v a t e
C
e b a s e S
r c e : G i t h u b E n t e r p r i s e , g i t h u b I ma g e s : a n y r e g i s t r y , I B M C l
d p r i v a t e r e g i s t r y D e p e n d e n c i e s D e p e n d e n c y ma n a g e me n t
l a n g u a g e e n v i r
me n t ; c
t a i n e r b u i l d p r
e s s f
r e p e a t a b l e i n c l u s i
d e p e n d e n c i e s C
fi g k 8 s c
f g ma p s a n d s e c r e t s B a c k i n g s e r v i c e s U s e c
f g u r a t i
( s e e p r e v i
s f a c t
) t
e f n e t a r g e t s e r v e r a s u s e d b y a p p l i c a t i
B u i l d , r e l e a s e , r u n U r b a n C
e D e p l
U r b a n C
e R e l e a s e P l u s k 8 s me c h a n i s ms w i t h C I t
i n g P r
e s s e s T
e c
s i d e r e d i n a p p l i c a t i
d e s i g n P
t b i n d i n g A p p l i c a t i
n e e d s t
x p
e p
t s . I n g r e s s / s e r v i c e d e f n i t i
k 8 s ma n a g e s ma p p i n g
p
t s C
c u r r e n c y A p p d e s i g n ( [ a u t
s c a l i n g b u i l t i n t
8 s ) D i s p
a b i l i t y A p p d e s i g n D e v / p r
p a r i t y C a n u s e h e l m t
e p l
i n s a me w a y . N a me s p a c e s f
i s
a t i
s i mi l a r a r e a s L
s E L K a s p a r t
I C P (
R Y O ) A d mi n p r
e s s e s A p p d e s i g n ; s t a n d a r d k 8 s t
i n g l i k e “ k u b e c t l e x e c ”
K u b e r n e t e s J
s
B u i l d a 1 2 F a c t
M i c r
e r v i c e i n a n H
r
A n d r e w R
s e : O p e n L i b e r t y D e v e l
e r f
M i c r
r
l e a n d C D I , I B M @a z q u e l t
1
C
t e n t s
B a s i c c
c e p t s
1 2 f a c t
a p p s D e mo
c r e a t i n g a 1 2 f a c t
mi c r
e r v i c e u s i n g M i c r
r
l e
1 2 F a c t
s i n a n u t s h e l l
– A me t h
y – B e s t P r a c t i c e s – M a n i f e s t
t t p s : / / 1 2 f a c t
. n e t / b y H e r
u
Wh y 1 2 f a c t
?
e f n e t h e c
t r a c t b e t w e e n a p p l i c a t i
s a n d i n f r a s t r u c t u r e
Application Infrastructurerequired (Kubernetes, Database selection, etc…)
application can be resilient without surplus infrastructure
but some are provided from the infrastructure
services of infrastructure to support agile development.
expose endpoints and integrations to be managed autonomously (e.g. Kubenetes asks applications to expose health endpoint)
4
T H E F A C T O R S
1 .C
e b a s e 2 .D e p e n d e n c i e s 3 .C
f g 4 .B a c k i n g S e r v i c e s 5 .B u i l d , R e l e a s e , R u n 6 .P r
e s s e s 7 .P
t b i n d i n g 8 .C
c u r r e n c y 9 .D i s p
a b i l i t y 1 . D e v / P r
p a r i t y 1 1 . L
s 1 2 . A d mi n P r
e s s e s
5
Wh y 1 2 f a c t
?
I n t h e mo d e r n e r a , s
t w a r e i s c
n l y d e l i v e r e d a s a s e r v i c e : c a l l e d w e b a p p s ,
s
t w a r e
s
e r v i c e . T h e t w e l v e
a c t
a p p i s a me t h
y f
b u i l d i n g s
t w a r e
s
e r v i c e a p p s t h a t : U s e d e c l a r a t i v e f
ma t s f
s e t u p a u t
t i
, t
n i mi z e t i me a n d c
t f
n e w d e v e l
e r s j
n i n g t h e p r
e c t ; H a v e a c l e a n c
t r a c t w i t h t h e u n d e r l y i n g
e r a t i n g s y s t e m,
f e r i n g ma x i mu m p
t a b i l i t y b e t w e e n e x e c u t i
e n v i r
me n t s ; A r e s u i t a b l e f
d e p l
me n t
mo d e r n c l
d p l a t f
ms ,
v i a t i n g t h e n e e d f
s e r v e r s a n d s y s t e ms a d mi n i s t r a t i
; M i n i mi z e d i v e r g e n c e b e t w e e n d e v e l
me n t a n d p r
u c t i
, e n a b l i n g c
t i n u
s d e p l
me n t f
ma x i mu m a g i l i t y ; A n d c a n s c a l e u p w i t h
t s i g n i f c a n t c h a n g e s t
i n g , a r c h i t e c t u r e ,
d e v e l
me n t p r a c t i c e s . T h e t w e l v e
a c t
me t h
y c a n b e a p p l i e d t
p p s w r i t t e n i n a n y p r
r a mmi n g l a n g u a g e , a n d w h i c h u s e a n y c
i n a t i
b a c k i n g s e r v i c e s ( d a t a b a s e , q u e u e , me mo r y c a c h e , e t c ) .
F r6
I . C
e b a s e
e d i c a t e s ma l l e r t e a ms t
n d i v i d u a l a p p l i c a t i
s
mi c r
e r v i c e s .
l
i n g t h e d i s c i p l i n e
s i n g l e r e p
i t
y f
a n a p p l i c a t i
f
c e s t h e t e a ms t
n a l y z e t h e s e a ms
t h e i r a p p l i c a t i
, a n d i d e n t i f y p
e n t i a l mo n
i t h s t h a t s h
l d b e s p l i t
f i n t
c r
e r v i c e s . “ O n e c
e b a s e t r a c k e d i n r e v i s i
c
t r
, ma n y d e p l
s . ”
s e a s i n g l e s
r c e c
e r e p
i t
y f
a s i n g l e a p p l i c a t i
( 1 : 1 r e l a t i
) .
Subversion), or any set of repos who share a root commit (in a decentralized system like Git where changes are committed.) Also in Git – scenario of repository per package/service.
multiple repository a d v a n t a g e s :
l e a r
n e r s h i p : t e a m t h a t
n s a s e r v i c e i s c l e a r l y r e s p
s i b l e f
i n d e p e n d e n t l y d e v e l
a n d d e p l
t h e f u l l s t a c k
t h a t s e r v i c e
ma l l e r c
e b a s e : S e p a r a t e r e p
i t
i e s f
a s e r v i c e l e a d s t
ma l l e r c
e b a s e a n d l e s s e r c
l e x i t y d u r i n g c
e me r g e .
a r r
c l
e s : f a s t e r D e v O p s a n d a u t
t e d b u i l d a n d r e l e a s e s a s s ma l l e r c
e b a s e me a n s l e s s c
e d
n l
d / c l
e t i me
mu l t i p l e r e p
i t
y d i s a d v a n t a g e s :
D i f fi c u l t d e v e l
me n t a n d d e b u g g i n g : d e v e l
me n t , c r
s t e a m c
n i c a t i
s a n d s h a r e d c
e s a r e d i f f c u l t t
i n t a i n a n d t h u s d e v e l
me n t a n d d e b u g g i n g c a n b e a n i s s u e A b s t r a c t s t h e k n
l e d g e
t h e p l a t f
m: S i n c e e a c h t e a m i s
l y r e s p
s i b l e f
a s i n g l e s e r v i c e , i n t e g r a t i
b e c
s a n i s s u e a n d k n
l e d g e
t h e p l a t f
m c a n d e c r e a s e M u l t i p l e E v e r y t h i n g : M u l t i p l e d e p e n d e n c i e s , d u p l i c a t i
a n d i n t e g r a t i
s 7
I I . D e p e n d e n c i e s
A c l
d
a t i v e a p p l i c a t i
d
s n
r e l y
t h e p r e
x i s t e n c e
d e p e n d e n c i e s i n a d e p l
me n t t a r g e t . D e v e l
e r T
s d e c l a r e a n d i s
a t e d e p e n d e n c i e s
a v e n a n d G r a d l e d e c l a r e J a v a l i b r a r y d e p e n d e n c i e s
k e r f l e d e c l a r e s d e p e n d e n c i e s
O S a n d
h e r t
s
a c h mi c r
e r v i c e d e c l a r e s i t s
n d e p e n d e n c i e s “ E x p l i c i t l y d e c l a r e a n d i s
a t e d e p e n d e n c i e s ”
I I I . C
f g
“ S t
e c
f g i n t h e e n v i r
me n t ”
h a n g i n g c
f g s h
l d n
n e e d t
e p a c k a g e y
r a p p l i c a t i
s e K u b e r n e t e s c
f g ma p s a n d s e c r e t s f
c
t a i n e r s e r v i c e s , r a t h e r t h a n v a l u e s s p e c i f e d i n t h e a p p
c
t a i n e r i ma g e
s e M i c r
r
l e C
f g t
n j e c t t h e c
f g p r
e r t i e s i n t
h e mi c r
e r v i c e s
App Password=blahD
h e s e ma k e s e n s e ? – H J ( s t r u g g l i n g h
t h e s e
f e r i n g s h e l p p u s h i n g c
fi g u r a t i
s – u b ) L e t ’ s l e a v e t h e m b e c a u s e w e h a v e t h e s p a c e . I ’ m n
r e a l l y a t t a c h e d t
h e m, s
e c a n d e l e t e …
9
I V . B a c k i n g s e r v i c e s
“ T r e a t b a c k i n g s e r v i c e s a s a t t a c h e d r e s
r c e s ”
Application My SQL Amazon S3 Twitterstores, messaging systems, caching systems, security services)
s e c
f g u r a t i
( s e e f a c t
I I I ) t
e f n e t a r g e t s e r v i c e a s u s e d b y a p p l i c a t i
. C
f g u r a t i
d e f n e s a c c e s s t
b a c k i n g s e r v i c e
e s
r c e B i n d i n g s h
l d b e d
e v i a e x t e r n a l c
f g u r a t i
.
t t a c h a n d d e t a c h b a c k i n g s e r v i c e s f r
a n a p p l i c a t i
a t w i l l , w i t h
t r e
e p l
i n g t h e a p p l i c a t i
.
a u l t T
e r a n c e p a t t e r n : a l l
c
e t
t
c
n i c a t i n g w i t h mi s b e h a v i n g b a c k i n g s e r v i c e s , p r
i d i n g a f a l l b a c k p a t h
10
V . B u i l d , r e l e a s e , r u n
“ S t r i c t l y s e p a r a t e b u i l d a n d r u n s t a g e s ”
r c e c
e i s u s e d i n t h e b u i l d s t a g e . C
f g u r a t i
d a t a i s a d d e d t
e f n e a r e l e a s e s t a g e t h a t c a n b e d e p l
e d . A n y c h a n g e s i n c
e
c
f g w i l l r e s u l t i n a n e w b u i l d / r e l e a s e
e e d s t
e c
s i d e r e d i n C I p i p e l i n e
I B M
r b a n C
e D e p l
B M C l
d C
t i n u
s D e l i v e r y S e r v i c e A z u r e
i s u a l S t u d i
e a m S e r v i c e s ( V S T S ) ( i n c l u d e s g i t )
b A p p f
C
t a i n e r s f e a t u r e
A z u r e A p p S e r v i c e A WS
WS C
e B u i l d
WS C
e D e p l
WS C
e P i p e l i n e ( n
y e t i n t e g r a t e d w i t h E K S )
V I . P r
e s s e s
“ E x e c u t e t h e a p p a s
e
mo r e s t a t e l e s s p r
e s s e s ” ➢S t a t e l e s s a n d s h a r e
h i n g ➢A n y p e r s i s t e n c e u s e s a b a c k i n g s e r v i c e
–D a t a b a s e
–S h a r e d c a c h e
–M e s s a g e q u e u e
e n t s a r e s t a t e l e s s a n d s h a r e d
h i n g . S t a t e c a n b e p u t i n a s t a t e f u l b a c k i n g s e r v i c e ( d a t a b a s e )
t a t e l e s s c
e n t s c a n b e r e p l a c e d q u i c k l y i f t h e y f a i l
v
d d e p e n d e n c i e s
s t i c k y s e s s i
s a n d k e e p s e s s i
d a t a i n a p e r s i s t e n t s t
e t
n s u r e t r a f f c c a n b e r
t e d t
h e r p r
e s s e s w i t h
t s e r v i c e d i s r u p t i
e c
s i d e r e d i n a p p l i c a t i
d e s i g n b y t h e d e v e l
e r , n
i n C l
d r
l
t 12
V I I . P
t b i n d i n g
“ E x p
t s e r v i c e s v i a p
t b i n d i n g ”
p p l i c a t i
s a r e f u l l y s e l f
t a i n e d a n d e x p
e s e r v i c e s
l y t h r
g h p
t s . P
t a s s i g n me n t i s d
e b y t h e e x e c u t i
e n v i r
me n t
n g r e s s / s e r v i c e d e f n i t i
k 8 s ma n a g e s ma p p i n g
p
t s
s e M P C
f g t
n j e c t p
t s t
c r
e r v i c e s t
n e c t u p mi c r
e r v i c e s
P
t = 8
@I n j e c t @CV I I I . C
c u r r e n c y
“ S c a l e
t v i a t h e p r
e s s mo d e l ”
p p l i c a t i
s u s e p r
e s s e s i n d e p e n d e n t f r
e a c h
h e r t
c a l e
t ( a l l
i n g f
l
d b a l a n c i n g )
e c
s i d e r e d i n a p p l i c a t i
d e s i g n
l
d a u t
c a l i n g s e r v i c e s : [ a u t
s c a l i n g b u i l t i n t
8 s
u i l d mi c r
e r v i c e s
I X . D i s p
a b i l i t y
“ M a x i mi z e r
u s t n e s s w i t h f a s t s t a r t u p a n d g r a c e f u l s h u t d
n ”
r
e s s e s s t a r t u p f a s t .
r
e s s e s s h u t d
n g r a c e f u l l y w h e n r e q u e s t e d .
r
e s s e s a r e r
u s t a g a i n s t s u d d e n d e a t h
n s u r e y
w
’ t l
e d a t a i f p a r t
y
r s y s t e m d i e s
s e M i c r
r
l e F a u l t T
e r a n c e t
k e c a l l s t
h e r s e r v i c e s r e s i l i e n t
X . D e v / p r
p a r i t y
“ K e e p d e v e l
me n t , s t a g i n g , a n d p r
u c t i
a s s i mi l a r a s p
s i b l e ”
e v e l
me n t a n d p r
u c t i
a r e a s c l
e a s p
s i b l e ( i n t e r ms
c
e , p e
l e , a n d e n v i r
me n t s )
a n u s e h e l m t
e p l
i n r e p e a t a b l e ma n n e r
s e ( n a me ) s p a c e s f
i s
a t i
s i mi l a r s e t u p s
X I . L
s
“ T r e a t l
s a s e v e n t s t r e a ms ”
p p w r i t e s a l l l
s t
t d
t
s e a s t r u c t u r e d
t p u t f
me a n i n g f u l l
s s u i t a b l e f
a n a l y s i s . E x e c u t i
e n v i r
me n t h a n d l e s r
t i n g a n d a n a l y s i s i n f r a s t r u c t u r e
X I I . A d mi n p r
e s s e s
“ R u n a d mi n / ma n a g e me n t t a s k s a s
e
f p r
e s s e s ”
i n g : s t a n d a r d k 8 s t
i n g l i k e “ k u b e c t l e x e c ”
K u b e r n e t e s J
s
l s
e c
s i d e r e d i n s
u t i
/ a p p l i c a t i
d e s i g n
e x a mp l e , i f a n a p p l i c a t i
n e e d s t
g r a t e d a t a i n t
d a t a b a s e , p l a c e t h i s t a s k i n t
s e p a r a t e c
e n t i n s t e a d
a d d i n g i t t
h e ma i n a p p l i c a t i
c
e a t s t a r t u p
T H E F A C T O R S
1 .C
e b a s e 2 .D e p e n d e n c i e s 3 .C
f g 4 .B a c k i n g S e r v i c e s 5 .B u i l d , R e l e a s e , R u n 6 .P r
e s s e s 7 .P
t b i n d i n g 8 .C
c u r r e n c y 9 .D i s p
a b i l i t y 1 . D e v / P r
p a r i t y 1 1 . L
s 1 2 . A d mi n P r
e s s e s
19
D E M O
1 .C r e a t e a R E S T a p p ( s t a t e l e s s , i n
e c
e b a s e ) 2 .D e c l a r e
r d e p e n d e n c i e s u s i n g M a v e n a n d D
k e r f l e
– I
n c l u d i n g O p e n L i b e r t y 3 .R e l e a s e a n d R u n b y d e p l
i n g w i t h c
f g t
u b e r n e t e s 4 .U p d a t e
r a p p t
a l l a n
h e r s e r v i c e 5 .D e p l
a g a i n w i t h s c a l i n g
1
Codebase2
Deps3
Config4
Backing Service5
Build Release Run6
Stateless7
Port Binding8
Scaling9
Disposability10
Prod, Dev, Staging11
Logs12
Admin Processes12 FACTOR BINGO 12 FACTOR BINGO
Not covering 10 or 12 because… We will create a REST app which is *stateless and has *one codebase Declare our *dependencies using maven and a Dockerfile Includes OpenLiberty which will take care of *binding to a port, starting up quickly and shutting down gracefully which is important for *disposability, and will *log to stdout We will then build our app before doing a *release and run by deploying the app with its config to kubernetes Then we’ll update our app to call another service which we’ll treat as an *attached backing service And finally we’ll deploy it again and demonstrate *scaling with Kubernetes Hopefully allowing us to achieve *12 Factor Bingo!
20
R e f e r e n c e s
e s a mp l e t
e mo n s t r a t e 1 2
a c t
a p p
t t p : / / mi c r
r
l e . i
t t p : / /
e n l i b e r t y . i
e s p e c i a l l y g u i d e s )
t t p s : / / w w w . 1 2 f a c t
. n e t /
microservice Infrastructure K8srequired (Kubernetes, Database selection, etc…)
application can be resilient without surplus infrastructure
but some are provided from the infrastructure
services of infrastructure to support agile development.
expose endpoints and integrations to be managed autonomously (e.g. Kubenetes asks applications to expose health endpoint)
21
1 2 f a c t
a p p
s e M i c r
r
l e a n d K 8 s t
u i l d a mi c r
e r v i c e = > 1 2 f a c t
a p p
microservice Infrastructure K8srequired (Kubernetes, Database selection, etc…)
application can be resilient without surplus infrastructure
but some are provided from the infrastructure
services of infrastructure to support agile development.
expose endpoints and integrations to be managed autonomously (e.g. Kubenetes asks applications to expose health endpoint)
22
M i c r
r
l e C
f g
Wh y ?
– C
f g u r e M i c r
e r v i c e w i t h
t r e p a c k i n g t h e a p p l i c a t i
H
?
– S p e c i f y t h e c
f g u r a t i
i n c
f g u r a t i
s
r c e s – A c c e s s c
f g u r a t i
v i a
r
r a mma t i c l
u p Config config = ConfigProvider.getConfig(); config.getValue(“myProp”, String.class);
D I I n j e c t i
@Inject @ConfigProperty(name="my.string.property") String myProp;
23
M i c r
r
l e C
f g
S t a t i c C
f g D y n a mi c C
f g
@Inject @ConfiProperty(name="myStaticProp") private Strini staticProp; @Inject @ConfiProperty(name="myDynamicProp") private Provider<Strini> dynamicProp;
mi c re r r i d e s
M i c r
r
l e F a u l t T
e r a n c e
A s
u t i
t
u i l d a r e s i l i e n t mi c r
e r v i c e R e t r y
C i r c u i t B r e a k e r
B u l k H e a d
T i me
t
F a l l b a c k
B a c k u p : U s i n g I B M C l
d P r i v a t e
C