oreilly/nginx 2016: "continuous delivery with containers: the trials and tribulations"

53
Continuous Delivery for Containerized Applications: The Trials and Tribulations Daniel Bryant @danielbryantuk

Upload: daniel-bryant

Post on 24-Jan-2018

7.883 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Continuous Delivery for Containerized Applications:The Trials and Tribulations

Daniel Bryant

@danielbryantuk

Page 2: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Setting the scene…

• Continuous delivery is a large topic

• Focusing on the process and tooling• No live coding today

• Mini-book contains more details

• “Building a CD pipeline” by Adrian and Kevin

15/12/2016 @danielbryantuk

Page 3: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

TL;DR – Containers and CD

• Container image becomes the build pipeline ‘single binary’

• Adding metadata to containers images is vital

• Must validate container constraints (NFRs)• Cultivate containerised ‘mechanical sympathy’

15/12/2016 @danielbryantuk

Page 4: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

@danielbryantuk

• Chief Scientist at OpenCredo, CTO at SpectoLabs

• Agile, architecture, CI/CD, DevOps

• Java, Go, JS, microservices, cloud, containers

• Leading change through the application of technology and teams

15/12/2016 @danielbryantuk

Page 5: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Continuous Delivery

15/12/2016 @danielbryantuk

Page 6: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Continuous Delivery

• Produce valuable and robust software in short cycles

• Optimising for feedback and learning

• Not (necessarily) Continuous Deployment

15/12/2016 @danielbryantuk

Page 7: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Creation of a build pipeline is mandatory for continuous delivery

15/12/2016 @danielbryantuk

Page 8: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

15/12/2016 @danielbryantuk

Page 9: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

The Impact of containers on CD

15/12/2016 @danielbryantuk

Page 10: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Container technology (and CD)

• OS-level virtualisation• cgroups, namespaces, rootfs

• Package and execute software

• Container image == ‘single binary’

15/12/2016 @danielbryantuk

Page 11: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

15/12/2016 @danielbryantuk

Page 12: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

15/12/2016 @danielbryantuk

Page 13: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Creating a pipeline for containers

15/12/2016 @danielbryantuk

Page 14: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

15/12/2016 @danielbryantuk

Page 15: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Make your dev environment like production

• Develop locally or copy/code in container

• Use base images from production

• Must build/test containers locally• Perform (at least) happy path tests

• All tests should be runnable locally

15/12/2016 @danielbryantuk

Page 16: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Lesson learned: Dockerfile content is super important

• OS choice

• Configuration

• Build artifacts

• Exposing ports

• Java• JDK vs JRE and Oracle vs OpenJDK

• Golang• Statically compiled binary

• Python• Virtualenv

15/12/2016 @danielbryantuk

Page 17: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Please talk to the sysadmin people:

Their operational knowledge is invaluable

15/12/2016 @danielbryantuk

Page 18: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Different prod and test containers?

• Create “test” version of container• Full OS (e.g. Ubuntu)

• Test tools and data

• Easy to see app/configuration drift

• Use test sidecar containers instead

• ONTEST proposal by Alexi Ledenev

15/12/2016 @danielbryantuk

http://blog.terranillius.com/post/docker_testing/

Page 19: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

15/12/2016 @danielbryantuk

Page 20: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Building images with Jenkins

• My report covers this

• Build as usual…

• Build Docker Image• Cloudbees Docker Build and Publish Plugin

• Push image to registry

15/12/2016 @danielbryantuk

Page 21: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Storing in an image registry (DockerHub)

15/12/2016 @danielbryantuk

Page 22: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Lesson learned: Metadata is valuable

• Application metadata• Version / GIT SHA

• Build metadata• Build date• Image name• Vendor

• Quality metadata• QA control• Security audited etc

15/12/2016 @danielbryantuk

Page 23: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Metadata – Beware of “latest” Docker Tag

• Beware of the ‘latest’ Docker tag

• “Latest” simply means • the last build/tag that ran without

a specific tag/version specified

• Ignore “latest” tag• Version your tags, every time

• Danielbryantuk/test:2.4.1

15/12/2016 @danielbryantuk

Page 24: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Metadata - Adding Labels at build time

• Docker Labels

• Add key/value data to image

15/12/2016 @danielbryantuk

Page 25: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Metadata - Adding Labels at build time

• Microscaling Systems’ Makefile

• Labelling automated builds on DockerHub (h/t Ross Fairbanks)• Create file /hooks/build

• label-schema.org

• microbadger.com

15/12/2016 @danielbryantuk

Page 26: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Metadata - Adding Labels at runtime

15/12/2016 @danielbryantuk

$ docker run -d --label

uk.co.danielbryant.lbname=frontdoor nginx

• Can ’docker commit’, but creates new image

• Not possible to update running container

• Docker Proposal: Update labels #21721

Page 27: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

15/12/2016 @danielbryantuk

Page 28: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Component testing

15/12/2016 @danielbryantuk

Page 29: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Testing: Jenkins Pipeline (as code)

15/12/2016 @danielbryantuk

Page 30: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

15/12/2016 @danielbryantuk

Page 31: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Testing individual containers

15/12/2016 @danielbryantuk

Page 32: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Integration testing

15/12/2016 @danielbryantuk

Page 33: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Introducing Docker Compose

15/12/2016 @danielbryantuk

Page 34: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Docker Compose & Jenkins Pipeline

15/12/2016 @danielbryantuk

Page 35: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Mechanical sympathy: Docker and Java

• Watch for cgroup limits (and cgroup awareness)• getAvailableProcessors issue (bugs.openjdk.java.net/browse/JDK-8140793)

• Default fork/join thread pool sizes (based from host CPU count)

• Set container memory appropriately • JVM requirements = Heap size (Xmx) + Metaspace + JVM overhead

• Account for native thread requirements e.g. thread stack size (Xss)

• Entropy • Host entropy can soon be exhausted by crypto operations

15/12/2016 @danielbryantuk | @spoole167 35

Page 36: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Mechanical sympathy: Docker and security

15/12/2016 @danielbryantuk

Page 37: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Containers are not a silver bullet

15/12/2016 @danielbryantuk

Page 38: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Containers: Expectations versus reality

15/12/2016 @danielbryantuk

“DevOps”

Page 39: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Containerise an existing (monolithic) app?

• For

• We know the monolith well

• Allows homogenization of the pipeline and deployment platform

• Can be a demonstrable win for tech and the business

• Against

• Can be difficult (100+ line scripts)

• Often not designed for operation within containers, nor cloud native

• Putting lipstick on a pig?

15/12/2016 @danielbryantuk

Page 40: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Whatever you decide…

push it through the pipeline ASAP!

15/12/2016 @danielbryantuk

Page 41: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Key lessons learned

• Conduct an architectural review • Architecture for Developers, by Simon Brown• Architecture Interview, by Susan Fowler

• Look for data ingress/egress• File system access

• Support resource constraints/transience• Optimise for quick startup and shutdown • Evaluate approach to concurrency• Store configuration (secrets) remotely

15/12/2016 @danielbryantuk

Page 42: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

New design patterns

15/12/2016 @danielbryantuk

bit.ly/2efe0TP

Page 43: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Microservices…

Containers and microservices are complementary

Testing and deployment change

15/12/2016 @danielbryantuk

https://specto.io/blog/recipe-for-designing-building-testing-microservices.html

Page 44: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

15/12/2016 @danielbryantuk

Page 45: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

15/12/2016 @danielbryantuk

Page 46: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

15/12/2016 @danielbryantuk

Page 47: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Microservice architectural impact on CD

• Application decomposition• Bounded context

• Change cadence

• Risk

• Performance

• Scalability

• Team location

h/t Matthew Skelton, Adam Tornhill

• Worth knowing about:• Consumer-based contracts

• Service virtualisation

• Synthetic transactions and semantic monitoring

15/12/2016 @danielbryantuk

Page 48: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Using containers does not obviate the need for

good architectural practices

15/12/2016 @danielbryantuk

Page 49: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

15/12/2016 @danielbryantuk

https://speakerdeck.com/caseywest/containercon-north-america-cloud-anti-patterns

Page 50: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Summary

15/12/2016 @danielbryantuk

Page 51: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

In summary

• Continuous delivery is vitally important in modern architectures/ops

• Container images must be the (single) source of truth within pipeline

• Mechanical sympathy is important (assert properties in the pipeline)• We’re now bundling more responsibility into our artifact (e.g. an OS)• Not all developers are operationally aware

• The tooling is now becoming stable/mature• We need to re-apply old CD practices with new technologies/tooling

15/12/2016 @danielbryantuk

Page 52: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Bedtime reading

15/12/2016 @danielbryantuk

Page 53: OReilly/Nginx 2016: "Continuous Delivery with Containers: The Trials and Tribulations"

Thanks for listening

• Any questions?

• Feel free to contact me• @danielbryantuk

[email protected]

15/12/2016 @danielbryantuk