devoxx 2017 "continuous delivery with containers: the good, the bad, and the ugly"

68
Continuous Delivery with Containers: The Good, the Bad, and the Ugly Daniel Bryant @danielbryantuk

Upload: daniel-bryant

Post on 21-Jan-2018

2.374 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Continuous Delivery with Containers:The Good, the Bad, and the Ugly

Daniel Bryant

@danielbryantuk

Page 2: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Containers: Expectations versus reality

08/11/2017 @danielbryantuk

“DevOps”

Page 3: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Setting the scene…

• Continuous delivery is a large topic• No business focus today (value stream etc)

• PaaS and Serverless are super interesting…

• But I’m assuming you’re all-in on containers

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

• Mini-book contains more details (thanks nginx!)

08/11/2017 @danielbryantuk

bit.ly/2jWDSF7

Page 4: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

TL;DR – Containers and CD

• Container image becomes the build pipeline ‘single binary’

• Adding metadata to containers images is vital, but challenging

• Must validate container constraints on system quality attributes (NFRs)• Cultivate container ‘mechanical sympathy’

08/11/2017 @danielbryantuk

Page 5: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

@danielbryantuk

• Independent Technical Consultant, CTO at SpectoLabs

• Architecture, DevOps, Java, microservices, cloud, containers

• Continuous Delivery (CI/CD) advocate

• Leading change through technology and teams

08/11/2017 @danielbryantuk

Page 6: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

@danielbryantuk

08/11/2017 @danielbryantuk

Page 7: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Continuous Delivery

08/11/2017 @danielbryantuk

Page 8: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Continuous Delivery

• Produce valuable and robust software in short cycles

• Optimising for feedback and learning

• Not (necessarily) Continuous Deployment

08/11/2017 @danielbryantuk

Page 9: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Creation of a build pipeline is mandatory for continuous delivery

08/11/2017 @danielbryantuk

Page 10: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

Feedback: - Was our initial

hypothesis proven?- How can we improve

business, architecture and ops?

Page 11: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

The impact of containers on CD

08/11/2017 @danielbryantuk

Page 12: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Container technology (and CD)

• OS-level virtualisation• cgroups, namespaces, rootfs

• Package and execute software

• Container image == ‘single binary’

08/11/2017 @danielbryantuk

Page 13: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

Page 14: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

Page 15: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Microservices multiply the challenges

08/11/2017 @danielbryantuk

Page 16: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Creating a pipeline for containers

08/11/2017 @danielbryantuk

Page 17: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

Page 18: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Make your dev environment like production

• Develop locally or copy/code in container

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

• Use identical base images from production• With same configuration

08/11/2017 @danielbryantuk

Page 19: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

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 in scratch?

• Python• Virtualenv?

08/11/2017 @danielbryantuk

Page 20: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Please talk to the sysadmin people:

Their operational knowledge is invaluable

08/11/2017 @danielbryantuk

Page 21: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Different test and prod 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

08/11/2017 @danielbryantuk

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

Page 22: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Docker multi-stage builds

08/11/2017 @danielbryantuk

http://blog.alexellis.io/mutli-stage-docker-builds/https://github.com/moby/moby/pull/31257https://github.com/moby/moby/pull/32063

Page 23: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Java specific stuff…

08/11/2017 @danielbryantuk

github.com/oracle/docker-images/tree/master/OracleJava jdk.java.net/9/ea

Page 24: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Hot off the press: Modularity

• Create minimal runtime images

• “jlink delivers a self-contained distribution of your application and the JVM, ready to be shipped.”

• Benefits:• Reduced footprint• Performance• Security

08/11/2017 @danielbryantuk

Page 25: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

Page 26: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Building images with Jenkins

• My report covers this

• Build as usual…

• Build Docker Image• Cloudbees Docker Build and Publish Plugin

• Push image to registry

08/11/2017 @danielbryantuk

Page 27: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Storing in an image registry (DockerHub)

08/11/2017 @danielbryantuk

Page 28: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

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

08/11/2017 @danielbryantuk

Page 29: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Lesson learned: Metadata is valuable

• Application metadata• Version / GIT SHA

• Build metadata• Build date• Image name• Vendor

• Quality metadata• QA control, signed binaries, ephemeral support• Security profiles (AppArmor), Security audited etc

08/11/2017 @danielbryantuk

Page 30: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Metadata - Adding Labels at build time

• Docker Labels

• Add key/value data to image

08/11/2017 @danielbryantuk

Page 31: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

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

08/11/2017 @danielbryantuk

Page 32: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Metadata - Adding Labels at runtime

08/11/2017 @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 33: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Liz Rice (and Aqua) to the rescue!

08/11/2017 @danielbryantuk

github.com/aquasecurity/manifesto

Page 34: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

External registry with metadata support

08/11/2017 @danielbryantuk

Page 35: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

Page 36: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Component testing

08/11/2017 @danielbryantuk

Page 37: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Testing: Jenkins Pipeline (as code)

08/11/2017 @danielbryantuk

Page 38: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

Page 39: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Testing individual containers

08/11/2017 @danielbryantuk

Page 40: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Integration testing

08/11/2017 @danielbryantuk

Page 41: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Introducing Docker Compose

08/11/2017 @danielbryantuk

Page 42: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Docker Compose & Jenkins Pipeline

08/11/2017 @danielbryantuk

Page 43: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Ephemeral Kubernetes Clusters

• Kubernaut (WIP)

• Manages a pool of clusters

• ”Claim” a fresh cluster

• Use Helm to install dependencies

08/11/2017 @danielbryantuk

Page 44: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Testing NFRs in the build pipeline

• Performance and Load testing • Gatling / jmeter

• Flood.io

• Security testing • Findsecbugs / OWASP Dependency check

• Bdd-security (OWASP ZAP) / Arachni

• Gauntlt / Serverspec

• Docker Bench for Security / CoreOS Clair

08/11/2017 @danielbryantuk

Page 45: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

www.owasp.org/index.php/OWASP_Dependency_Check

Page 46: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

github.com/arminc/clair-scanner

Page 47: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Delaying NFRs to the ‘Last Responsible Moment’

Newsflash!

Sometimes the

last responsible moment

is up-front

Modern platforms/architectures don’t necessarily make this easier

08/11/2017 @danielbryantuk

Page 48: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Mechanical sympathy: Docker and Java

• Watch for JVM cgroup/taskset awareness• getAvailableProcessors() may incorrectly report the number of cpus in Docker (JDK-8140793)

• Runtime.availableProcessors() ignores Linux taskset command (JDK-6515172)

• Default fork/join thread pool sizes (and others) is 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 and /dev/random blocks• -Djava.security.egd=file:/dev/./urandom (notes on this)

08/11/2017 @danielbryantuk 48

Page 49: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Deployment

08/11/2017 @danielbryantuk

skillsmatter.com/skillscasts/10668-looking-forward-to-daniel-bryant-talk

docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.deploy-existing-version.html

Page 50: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Observability is core to continuous delivery

08/11/2017 @danielbryantuk

www.infoq.com/articles/monitoring-containers-at-scale

Page 51: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Containers are not a silver bullet

08/11/2017 @danielbryantuk

Page 52: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Moving to containers: Going all-in?

08/11/2017 @danielbryantuk

OR

Page 53: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Should I build my own container platform?

Probably not

(Unless you are Google, AWS or IBM)

Whatever you decide…

push it through a pipeline ASAP!

08/11/2017 @danielbryantuk

Page 54: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Using containers does not get rid of the need for

good architectural practices

08/11/2017 @danielbryantuk

Page 55: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

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

Page 56: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Summary

08/11/2017 @danielbryantuk

Page 57: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

In summary

• Continuous delivery is vitally important in modern architectures/ops

• Container images must be the (single) source of truth within pipeline• And metadata added as appropriate…

• Mechanical sympathy is important (assert properties in the pipeline)• Not all developers are operationally aware

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

08/11/2017 @danielbryantuk

Page 58: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Bedtime reading

08/11/2017 @danielbryantuk

Page 59: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Thanks for listening!

• Book signing in 10 mins!• Follow me to the O’Reilly table

• Feel free to contact me• @danielbryantuk

[email protected]

08/11/2017 @danielbryantuk

bit.ly/2jWDSF7

Coming soon!

Page 60: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Bonus slides (for extra context)

08/11/2017 @danielbryantuk

Page 61: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

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?

08/11/2017 @danielbryantuk

Page 62: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

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

08/11/2017 @danielbryantuk

Page 63: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

New design patterns

08/11/2017 @danielbryantuk

bit.ly/2efe0TP

Page 64: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Microservices…

Containers and microservices are complementary

Testing and deployment change

08/11/2017 @danielbryantuk

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

Page 65: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

Page 66: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

Page 67: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

08/11/2017 @danielbryantuk

Page 68: Devoxx 2017 "Continuous Delivery with Containers: The Good, the Bad, and the Ugly"

Quick Aside: Running *entire* system locally

08/11/2017 @danielbryantuk

https://news.ycombinator.com/item?id=13960107https://opencredo.com/working-locally-with-microservices/https://www.datawire.io/telepresence/ | https://hoverfly.io/