128
#JCConf William Yeh

Immutable infrastructure:觀念與實作 (建議)

Embed Size (px)

Citation preview

Page 1: Immutable infrastructure:觀念與實作 (建議)

#JCConf

William Yeh

Page 2: Immutable infrastructure:觀念與實作 (建議)
Page 3: Immutable infrastructure:觀念與實作 (建議)

#JCConf

William Yeh

Page 4: Immutable infrastructure:觀念與實作 (建議)
Page 5: Immutable infrastructure:觀念與實作 (建議)
Page 6: Immutable infrastructure:觀念與實作 (建議)

immutable infrastructure”

Page 7: Immutable infrastructure:觀念與實作 (建議)

immutable infrastructure”

Page 8: Immutable infrastructure:觀念與實作 (建議)

#JCConf

William Yeh

Page 10: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 11: Immutable infrastructure:觀念與實作 (建議)
Page 12: Immutable infrastructure:觀念與實作 (建議)

im‧mutable

Page 13: Immutable infrastructure:觀念與實作 (建議)

im‧mutable

Page 14: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 15: Immutable infrastructure:觀念與實作 (建議)

Entropy

Page 16: Immutable infrastructure:觀念與實作 (建議)

Entropy

Page 17: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 18: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 19: Immutable infrastructure:觀念與實作 (建議)

Q:

Page 20: Immutable infrastructure:觀念與實作 (建議)

7%

A:

lysosomes

Page 21: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 22: Immutable infrastructure:觀念與實作 (建議)
Page 23: Immutable infrastructure:觀念與實作 (建議)
Page 24: Immutable infrastructure:觀念與實作 (建議)
Page 25: Immutable infrastructure:觀念與實作 (建議)
Page 26: Immutable infrastructure:觀念與實作 (建議)
Page 27: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 28: Immutable infrastructure:觀念與實作 (建議)

#JCConf

DNA

Page 29: Immutable infrastructure:觀念與實作 (建議)

#JCConf

DNA

Page 30: Immutable infrastructure:觀念與實作 (建議)

#JCConf

DNA

lysosomes

Page 31: Immutable infrastructure:觀念與實作 (建議)

#JCConf

DNA

lysosomes

Page 32: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 33: Immutable infrastructure:觀念與實作 (建議)

How about computers?

Page 34: Immutable infrastructure:觀念與實作 (建議)

Entropy?

Page 35: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 36: Immutable infrastructure:觀念與實作 (建議)

“HAProxy has been installed on Linux 2.4 systems serving millions of pages every day, and which have only known one reboot in 3 years for a complete OS upgrade.”

Reliability - keeping high-traffic sites online since 2002

Page 37: Immutable infrastructure:觀念與實作 (建議)

“HAProxy has been installed on Linux 2.4 systems serving millions of pages every day, and which have only known one reboot in 3 years for a complete OS upgrade.”

Reliability - keeping high-traffic sites online since 2002

Page 38: Immutable infrastructure:觀念與實作 (建議)

im‧mutable

Page 39: Immutable infrastructure:觀念與實作 (建議)

im‧mutable

Page 40: Immutable infrastructure:觀念與實作 (建議)

im‧mutable

Page 41: Immutable infrastructure:觀念與實作 (建議)

im‧mutable

Page 42: Immutable infrastructure:觀念與實作 (建議)

In OOP and FP, an immutable object is an object whose state cannot be modified after it is created.

immutable objects

JCConf 2015Universal Scalaby Walter Chang

Page 43: Immutable infrastructure:觀念與實作 (建議)

In OOP and FP, an immutable object is an object whose state cannot be modified after it is created.

String s = "ABC";s.toLowerCase();

immutable objects

Page 44: Immutable infrastructure:觀念與實作 (建議)

String s = "ABC";s.toLowerCase();

Why immutable objects?• simpler to understand• inherently thread-safe• offer higher security than mutable objects.

immutable objects

Page 45: Immutable infrastructure:觀念與實作 (建議)

“How to sort in-place using the merge sort algorithm?”

immutable objects algorithms

• Too complex to be reduced to practical program.

• Knuth left this as an exercise (Vol 3, 5.2.5). There do exists in-place merge sort. It must be implemented carefully.

http://stackoverflow.com/q/2571049/714426

Page 46: Immutable infrastructure:觀念與實作 (建議)

CTAS: Create Table As Select

immutable objects algorithms

• Faster than ALTER TABLE.

• … with some constraints… Google it!

http://stackoverflow.com/q/2571049/714426

databases

Page 47: Immutable infrastructure:觀念與實作 (建議)

DHH (David Heinemeier Hansson)Creator of Rails.

immutable objects algorithms databases applications

Page 48: Immutable infrastructure:觀念與實作 (建議)

immutable objects algorithms

http://smalltalk.xdite.net/posts/302780-bos-rewrite-from-dhh

databases applications

Page 49: Immutable infrastructure:觀念與實作 (建議)

immutable objects algorithms

http://smalltalk.xdite.net/posts/302780-bos-rewrite-from-dhh

databases applications

Page 50: Immutable infrastructure:觀念與實作 (建議)

immutable

infrastructure

immutable objects algorithms databases applications

Page 51: Immutable infrastructure:觀念與實作 (建議)

immutable

infrastructure

immutable objects algorithms databases applications

Page 52: Immutable infrastructure:觀念與實作 (建議)

Let’s talk about

immutable objects algorithms databases applications Java

hot swap? hot deploy?

Page 53: Immutable infrastructure:觀念與實作 (建議)

immutable objects algorithms databases applications Java

hot swap since JDK 1.4

Page 54: Immutable infrastructure:觀念與實作 (建議)

immutable objects algorithms databases applications Java

hot swap in JRebel

Page 55: Immutable infrastructure:觀念與實作 (建議)

immutable objects algorithms databases applications Java

hot swap in OSGi

Page 56: Immutable infrastructure:觀念與實作 (建議)

immutable objects algorithms databases applications Java

Christian PostaPrincipal Middleware Specialist/Architect at Red Hat, open-source enthusiast, committer on Apache ActiveMQ, Apache Camel, Fabric8, HawtIO, blogging, Family, India Pale Ale.

http://blog.christianposta.com/immutable/immutable-infrastructure-and-the-jvm-part-i/

Page 57: Immutable infrastructure:觀念與實作 (建議)

immutable objects algorithms databases applications Java

• Don’t hotdeploy/redeploy/migrate your Java services in production at runtime.

Christian PostaPrincipal Middleware Specialist/Architect at Red Hat, open-source enthusiast, committer on Apache ActiveMQ, Apache Camel, Fabric8, HawtIO, blogging, Family, India Pale Ale.

http://blog.christianposta.com/immutable/immutable-infrastructure-and-the-jvm-part-i/

Page 58: Immutable infrastructure:觀念與實作 (建議)

immutable objects algorithms databases applications Java

• Don’t hotdeploy/redeploy/migrate your Java services in production at runtime.

• Do have a very strong focus on your delivery pipeline/automation/testing to quickly make changes to your system.

Christian PostaPrincipal Middleware Specialist/Architect at Red Hat, open-source enthusiast, committer on Apache ActiveMQ, Apache Camel, Fabric8, HawtIO, blogging, Family, India Pale Ale.

http://blog.christianposta.com/immutable/immutable-infrastructure-and-the-jvm-part-i/

Page 59: Immutable infrastructure:觀念與實作 (建議)

Infra

Infra

Page 60: Immutable infrastructure:觀念與實作 (建議)

immutable infrastructure”

Page 61: Immutable infrastructure:觀念與實作 (建議)

immutable

infrastructure

defin

ition

Page 62: Immutable infrastructure:觀念與實作 (建議)

http://www.slideshare.net/jpetazzo/containerization-new-virtualization-docker-separation-operational-concerns

Jérôme Petazzoni

defin

ition

Page 63: Immutable infrastructure:觀念與實作 (建議)

http://www.slideshare.net/jpetazzo/containerization-new-virtualization-docker-separation-operational-concerns

Jérôme Petazzoni

defin

ition

Page 64: Immutable infrastructure:觀念與實作 (建議)

http://www.slideshare.net/jpetazzo/containerization-new-virtualization-docker-separation-operational-concerns

Jérôme Petazzoni

defin

ition

Page 65: Immutable infrastructure:觀念與實作 (建議)

http://www.slideshare.net/jpetazzo/containerization-new-virtualization-docker-separation-operational-concerns

Jérôme Petazzoni

defin

ition

Page 66: Immutable infrastructure:觀念與實作 (建議)

WHY immutable infra?

Page 67: Immutable infrastructure:觀念與實作 (建議)

WHY immutable infra?• Simplify change management• hard to keep or restore “desired state” in-place

Page 68: Immutable infrastructure:觀念與實作 (建議)

WHY immutable infra?• Simplify change management• hard to keep or restore “desired state” in-place

• Enforce dev/prod parity• configure & test infra before deployed to

production environment

Page 69: Immutable infrastructure:觀念與實作 (建議)

WHY immutable infra?• Simplify change management• hard to keep or restore “desired state” in-place

• Enforce dev/prod parity• configure & test infra before deployed to

production environment• Reason about apps at a higher level • … than just the deployable packages containing

the code (JAR/WAR/zip/MSI/whatever)

Page 70: Immutable infrastructure:觀念與實作 (建議)

WHY NOT immutable infra?

Page 71: Immutable infrastructure:觀念與實作 (建議)

WHY NOT immutable infra?• Cost of “out of place” may be too high• vs

Page 72: Immutable infrastructure:觀念與實作 (建議)

WHY NOT immutable infra?• Cost of “out of place” may be too high• vs

• DevOps maturity level• Orchestration and

resource allocationprimitivesare required

Page 73: Immutable infrastructure:觀念與實作 (建議)
Page 74: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 75: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 76: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 77: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 78: Immutable infrastructure:觀念與實作 (建議)
Page 79: Immutable infrastructure:觀念與實作 (建議)

Golden imagePhenix server

Page 80: Immutable infrastructure:觀念與實作 (建議)

VM image

Golden imagePhenix server

Page 81: Immutable infrastructure:觀念與實作 (建議)

VM imageContainer image

Golden imagePhenix server

Page 82: Immutable infrastructure:觀念與實作 (建議)

VM imageContainer imageUnikernel image

Golden imagePhenix server

Page 83: Immutable infrastructure:觀念與實作 (建議)

VM image Container imageUnikernel image

• VM/IaaS provider specific

• VM/IaaS provider agnostic• Ansible: https://github.com/ansible/ansible• Packer: https://www.packer.io/• Otto: https://ottoproject.io/

Page 84: Immutable infrastructure:觀念與實作 (建議)

VM imageContainer image

Unikernel image

• Docker ecosystem• docker cli• Docker Hub• CI: Jenkins, Travis CI, CircleCI…

• Pre-Docker tools• Packer: https://www.packer.io/

Page 85: Immutable infrastructure:觀念與實作 (建議)

VM imageContainer image

Unikernel image

Page 86: Immutable infrastructure:觀念與實作 (建議)

VM

Page 87: Immutable infrastructure:觀念與實作 (建議)

VM Docker

Page 88: Immutable infrastructure:觀念與實作 (建議)

Docker

Page 89: Immutable infrastructure:觀念與實作 (建議)

Container per VMDockerHyper: https://hyper.sh/

Page 90: Immutable infrastructure:觀念與實作 (建議)

Container per VMHyper: https://hyper.sh/

Page 91: Immutable infrastructure:觀念與實作 (建議)

Container per VMHyper: https://hyper.sh/

UnikernelBoxfuse: https://boxfuse.com

Page 92: Immutable infrastructure:觀念與實作 (建議)

Container per VMHyper: https://hyper.sh/

UnikernelBoxfuse: https://boxfuse.com

Unikernels are constructed by using “library operating systems,” from which the developer selects only the minimal set of services required for an application to run.

These sealed, fixed-purpose images run directly on a hypervisor without an intervening guest OS such as Linux.

Page 93: Immutable infrastructure:觀念與實作 (建議)

UnikernelBoxfuse: https://boxfuse.com

Container per VM

Page 94: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 95: Immutable infrastructure:觀念與實作 (建議)

VM imageContainer image

Unikernel image

new unikernel approach

Page 96: Immutable infrastructure:觀念與實作 (建議)

VM imageContainer image

Unikernel image

new unikernel approach

Page 97: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 98: Immutable infrastructure:觀念與實作 (建議)

VM imageContainer imageUnikernel image

Page 99: Immutable infrastructure:觀念與實作 (建議)

VM imageContainer imageUnikernel image

Page 100: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 101: Immutable infrastructure:觀念與實作 (建議)

deployment

Page 102: Immutable infrastructure:觀念與實作 (建議)

deployment

Page 103: Immutable infrastructure:觀念與實作 (建議)

deployment

• Rolling upgrade• Blue/green deployment• Canary deployment

Page 104: Immutable infrastructure:觀念與實作 (建議)

deployment

https://www.safaribooksonline.com/library/view/continuous-delivery/9780134389363/

Page 105: Immutable infrastructure:觀念與實作 (建議)

deployment

• Cluster management• Service discovery• Orchestration

Page 106: Immutable infrastructure:觀念與實作 (建議)

deployment

• Pets vs cattle• Docker ecosystem is easier…

• Kubernetes• Mesos• …

Page 107: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 108: Immutable infrastructure:觀念與實作 (建議)

DevOps

deployment

Page 109: Immutable infrastructure:觀念與實作 (建議)

DevOps

deployment

VM imageContainer imageUnikernel image

Page 110: Immutable infrastructure:觀念與實作 (建議)

deployment

VM imageContainer imageUnikernel image

DevOps

IT workflow automation

Page 111: Immutable infrastructure:觀念與實作 (建議)

deployment

VM imageContainer imageUnikernel image

DevOps

JCConf 2015,

Abola Lee

IT workflow automation

Page 112: Immutable infrastructure:觀念與實作 (建議)

deployment

VM imageContainer imageUnikernel image

DevOps

JCConf 2015,

Abola Lee

IT workflow automation• Platform-specific tools

• AWS CodeDeploy• Google Cloud Deployment Manager• IBM BlueMix

Page 113: Immutable infrastructure:觀念與實作 (建議)

deployment

VM imageContainer imageUnikernel image

DevOps

JCConf 2015,

Abola Lee

IT workflow automation• Platform-specific tools

• AWS CodeDeploy• Google Cloud Deployment Manager• IBM BlueMix

• Ansible

Page 114: Immutable infrastructure:觀念與實作 (建議)

deployment

VM imageContainer imageUnikernel image

DevOps

JCConf 2015,

Abola Lee

IT workflow automation• Platform-specific tools

• AWS CodeDeploy• Google Cloud Deployment Manager• IBM BlueMix

• Ansible• CI SaaS

• Travis CI, CircleCI, etc.

Page 115: Immutable infrastructure:觀念與實作 (建議)

deployment

VM imageContainer imageUnikernel image

DevOps

JCConf 2015,

Abola Lee

IT workflow automation• Platform-specific tools

• AWS CodeDeploy• Google Cloud Deployment Manager• IBM BlueMix

• Ansible• CI SaaS

• Travis CI, CircleCI, etc.• Atlas (and others from HashiCorp)

Page 116: Immutable infrastructure:觀念與實作 (建議)
Page 117: Immutable infrastructure:觀念與實作 (建議)

Entropy

Page 118: Immutable infrastructure:觀念與實作 (建議)

#JCConf

Page 119: Immutable infrastructure:觀念與實作 (建議)

#JCConf

DNA

Page 120: Immutable infrastructure:觀念與實作 (建議)

#JCConf

DNA

Page 121: Immutable infrastructure:觀念與實作 (建議)

#JCConf

DNA

lysosomes

Page 122: Immutable infrastructure:觀念與實作 (建議)

#JCConf

DNA

lysosomes

Page 123: Immutable infrastructure:觀念與實作 (建議)

#JCConf

VM imageContainer imageUnikernel image

Page 124: Immutable infrastructure:觀念與實作 (建議)

#JCConf

VM imageContainer imageUnikernel image

Page 125: Immutable infrastructure:觀念與實作 (建議)

#JCConf

deployment

VM imageContainer imageUnikernel image

Page 126: Immutable infrastructure:觀念與實作 (建議)

#JCConf

deployment

VM imageContainer imageUnikernel image

Page 127: Immutable infrastructure:觀念與實作 (建議)

#JCConf