Top Banner
A Practical Guide forContinuous Delivery with Containers Daniel Bryant @danielbryantuk
54

A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Aug 25, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

A Practical Guide for… Continuous Delivery with Containers

Daniel Bryant

@danielbryantuk

Page 2: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Containers: Expectations versus reality

20/04/2017 @danielbryantuk

“DevOps”

Page 3: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

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

20/04/2017 @danielbryantuk

Page 4: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

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’

20/04/2017 @danielbryantuk

Page 5: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

@danielbryantuk

• Software Developer, CTO at SpectoLabs

• Agile, architecture, CI/CD, DevOps

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

• Leading change through the application of technology and teams

20/04/2017 @danielbryantuk

Page 6: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Continuous Delivery

20/04/2017 @danielbryantuk

Page 7: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Continuous Delivery

• Produce valuable and robust software in short cycles

• Optimising for feedback and learning

• Not (necessarily) Continuous Deployment

20/04/2017 @danielbryantuk

Page 8: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Creation of a build pipeline is mandatory for continuous delivery

20/04/2017 @danielbryantuk

Page 9: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

20/04/2017 @danielbryantuk

Page 10: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

The Impact of containers on CD

20/04/2017 @danielbryantuk

Page 11: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Container technology (and CD)

• OS-level virtualisation • cgroups, namespaces, rootfs

• Package and execute software

• Container image == ‘single binary’

20/04/2017 @danielbryantuk

Page 12: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

20/04/2017 @danielbryantuk

Page 13: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

20/04/2017 @danielbryantuk

Page 14: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Creating a pipeline for containers

20/04/2017 @danielbryantuk

Page 15: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

20/04/2017 @danielbryantuk

Page 16: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

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

20/04/2017 @danielbryantuk

Page 17: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

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

20/04/2017 @danielbryantuk

Page 18: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Please talk to the sysadmin people:

Their operational knowledge is invaluable

20/04/2017 @danielbryantuk

Page 19: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

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

20/04/2017 @danielbryantuk

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

Page 20: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

20/04/2017 @danielbryantuk

Page 21: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Building images with Jenkins

• My report covers this

• Build as usual…

• Build Docker Image • Cloudbees Docker Build and Publish Plugin

• Push image to registry

20/04/2017 @danielbryantuk

Page 22: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Storing in an image registry (DockerHub)

20/04/2017 @danielbryantuk

Page 23: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Lesson learned: Metadata is valuable

• Application metadata • Version / GIT SHA

• Build metadata • Build date • Image name • Vendor

• Quality metadata • QA control • Security audited etc

20/04/2017 @danielbryantuk

Page 24: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

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

20/04/2017 @danielbryantuk

Page 25: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Metadata - Adding Labels at build time

• Docker Labels

• Add key/value data to image

20/04/2017 @danielbryantuk

Page 26: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

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

20/04/2017 @danielbryantuk

Page 27: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Metadata - Adding Labels at runtime

20/04/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 28: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

20/04/2017 @danielbryantuk

Page 29: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Component testing

20/04/2017 @danielbryantuk

Page 30: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Testing: Jenkins Pipeline (as code)

20/04/2017 @danielbryantuk

Page 31: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

20/04/2017 @danielbryantuk

Page 32: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Testing individual containers

20/04/2017 @danielbryantuk

Page 33: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Integration testing

20/04/2017 @danielbryantuk

Page 34: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Introducing Docker Compose

20/04/2017 @danielbryantuk

Page 35: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Docker Compose & Jenkins Pipeline

20/04/2017 @danielbryantuk

Page 36: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

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 (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

20/04/2017 @danielbryantuk | @spoole167 36

Page 37: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Mechanical sympathy: Docker and security

20/04/2017 @danielbryantuk

Page 38: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Containers are not a silver bullet

20/04/2017 @danielbryantuk

Page 39: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Moving to containers: Going all-in?

20/04/2017 @danielbryantuk

OR

Page 40: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

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?

20/04/2017 @danielbryantuk

Page 41: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Whatever you decide…

push it through the pipeline ASAP!

20/04/2017 @danielbryantuk

Page 42: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

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

20/04/2017 @danielbryantuk

Page 43: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

New design patterns

20/04/2017 @danielbryantuk

bit.ly/2efe0TP

Page 45: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

20/04/2017 @danielbryantuk

Page 46: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

20/04/2017 @danielbryantuk

Page 47: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

20/04/2017 @danielbryantuk

Page 48: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

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

20/04/2017 @danielbryantuk

Page 49: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Using containers does not obviate the need for

good architectural practices

20/04/2017 @danielbryantuk

Page 51: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Summary

20/04/2017 @danielbryantuk

Page 52: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

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

20/04/2017 @danielbryantuk

Page 53: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Bedtime reading

20/04/2017 @danielbryantuk

Page 54: A Practical Guide for Continuous Delivery with Containers · •“Building a CD pipeline” by Adrian and Kevin ... •Golang • Statically compiled binary •Python • Virtualenv

Thanks for listening

• Any questions?

• Feel free to contact me • @danielbryantuk

[email protected]

20/04/2017 @danielbryantuk