1.introduction Infra As A Code
1.introduction Infra As A Code
as CODE
Why infrastructure-as-code
matters: a short story.
You are starting a
new project
I know, I’ll use Ruby on Rails!
> gem i n s tal l r a i l s
> gem i n s t a l l r a i l s
Fetching: i18n-0.7.0.gem (100%)
Fetching: json-1.8.3.gem (100%)
B u i ldin g nat i v e exten sions. T h is coul d ta k e a wh i l e . . .
ERROR: Er r o r i n s t a l l i n g r a i l s :
ERROR: Failed t o b u i l d gem n a ti ve extension.
make
s h : 1 : make: not found
Ah, I just need to install make
> sudo a p t- get i n s t a l l make
...
Success!
> gem i n s tal l r a i l s
> gem i n s t a l l r a i l s
Fetching: nokogiri-1.6.7.2.gem (100%)
B u i l d i n g nat i v e exten si o n s . T h is could tak e a w h i le . . .
ERROR: Er r o r i n s t a l l i n g r a i l s :
ERROR: Failed t o b u i l d gem n a ti ve extension.
/usr/bin/ruby1.9.1 extconf.rb
checking i f the C compileraccepts. . . yes
B u i l d i n g nok o g i r i u s ingpackaged l i b r a r i es.
Using m i n i _ p o r t i l e version2 . 0 . 0 . r c 2
checking f o r gzdopen() i n - l z . . . no
z l i b i s missing; necessary f o r b u i l d i n g l i b xm l 2
* * * extconf.rb f a i l e d * * *
Hmm. Time to visit StackOverflow.
> sudo a p t- g e t i n s t a l l zlib1g-dev
...
Success!
> gem i n s tal l r a i l s
> gem i n s t a l l r a i l s
B u i l d i n g nat i v e exten si o n s . T h is could tak e a w h i le . . .
ERROR: Er r o r i n s t a l l i n g r a i l s :
ERROR: Failed t o b u i l d gem n a t i v e extension.
/usr/bin/ruby1.9.1 extconf.rb
checking i f the C compileraccepts. . . yes
B u i l d i n g nok o g i r i u s ingpackaged l i b r a r i es.
Using m i n i _ p o r t i l e version2 . 0 . 0 . r c 2
checking f o r gzdopen() i n - l z . . . yes
checking f o r i c o n v. . . yes
E x t r a c ti n g l i b x m l 2 - 2 . 9 . 2 . t a r. g z i n t o tmp/x86_64-pc-linux-
g n u / p o r t s / l i b x m l 2 / 2 . 9 . 2 . . . OK
* * * extconf.rb f a i l e d * * *
y u never install correctly?
(Spend 2 hours trying random
StackOverflow suggestions)
> gem i n s tal l r a i l s
> gem i n s tal l r a i l s
...
Success!
Finally!
> r a i l s new my- proj e c t
> cd my-project
> rails start
> r a i l s new my-project
> cd my-project
> rails start
| |_ )
_| ( / Amazon Linu x AMI
|\ | |
| |_ )
_| ( / Amazon Linu x AMI
|\ | |
/usr/bin/ruby1.9.1 extconf.rb
Eventually you get it working
Now you urgently have to update
all your Rails installs
> bundle update ra i l s
> bundle update r a i l s
B u i l d i n g nat i v e exten si o n s . T h is could tak e a w h i le . . .
ERROR: Er r o r i n s t a l l i n g r a i l s :
ERROR: Failed t o b u i l d gem n a t i v e extension.
/usr/bin/ruby1.9.1 extconf.rb
checking i f the C compileraccepts. . . yes
B u i l d i n g nok o g i r i u s ingpackaged l i b r a r i es.
Using m i n i _ p o r t i l e version2 . 0 . 0 . r c 2
checking f o r gzdopen() i n - l z . . . yes
checking f o r i c o n v. . . yes
E x t r a c ti n g l i b x m l 2 - 2 . 9 . 2 . t a r. g z i n t o tmp/x86_64-pc-linux-
g n u / p o r t s / l i b x m l 2 / 2 . 9 . 2 . . . OK
* * * extconf.rb f a i l e d * * *
The problem isn’t Rails
> ssh [email protected]
| |_ )
_| ( / Amazon Linu x AMI
|\ | |
< 2K 0 – 25
2K – 6K 0 – 40
64K – 512K 2 – 70
moduleE.func()
http://service.e
1. Isolation
2. Technology agnostic
3. Scalability
Disadvantages of services:
1. Operational overhead
2. Performance overhead
3. I/O, error handling
4. Backwards compatibility
5. Global changes, transactions,
referential integrity all very hard
For more info, see: Splitting Up a
Codebase into Microservices and
Artifacts
For this talk, we’ll use two
example microservices
require ' s i n a t r a '
Virtual Machine
Host OS
Hardware
Virtual Machine
Host OS
Hardware
Host OS Host OS
Hardware Hardware
Host OS Host OS
Hardware Hardware
r e a l 0m0.183s
user 0m0.009s
sys 0m0.014s
EXPOSE 4567
CMD [ " r u b y " , " a p p . r b " ]
EXPOSE 4567
CMD [ " r u b y " , " a p p . r b " ]
(...)
(...)
RUN bundle i n s t a l l
EXPOSE 3000
CMD [ " r a i l s" , " sta r t " ]
sinatra_backend:
image: br i k i s 9 8 /s i n at r a - backend
ports:
- "4567:4567"
sinatra_backend:
image: br i k i s 9 8 /s i n at r a - backend
ports:
- "4567:4567"
1. Maturity
2. Collaboration on Terraform state is
hard (but terragrunt makes it easier)
3. No rollback
4. Poor secrets management
Outline
1. Microservices
2. Docker
3. Terraform
4. Recap
Benefits of infrastructure-as-code:
1. Reuse
2. Automation
3. Version control
4. Code review
5. Testing
6. Documentation
Questions?