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

JAXLondon 2017 "Continuous Delivery with Containers and Java"

Jan 21, 2018

Download

Technology

Daniel Bryant
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: JAXLondon 2017 "Continuous Delivery with Containers and Java"

ContinuousDeliverywithContainers:TheGood,theBad,andtheUgly

DanielBryant@danielbryantuk

Page 2: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Containers:Expectationsversusreality

10/10/2017 @danielbryantuk

“DevOps”

Page 3: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Settingthescene…

• Continuousdeliveryisalargetopic• Nobusinessfocustoday(valuestreametc)• PaaSandServerless aresuperinteresting…• ButI’massumingyou’reall-inoncontainers

• Focusingtodayontheprocessandtooling• Nolivecodingtoday• Mini-bookcontainsmoredetails(thanksnginx!)

10/10/2017 @danielbryantuk

bit.ly/2jWDSF7

Page 4: JAXLondon 2017 "Continuous Delivery with Containers and Java"

TL;DR– ContainersandCD

• Containerimagebecomesthebuildpipeline‘singlebinary’

• Addingmetadatatocontainersimagesisvital,butchallenging

• Mustvalidatecontainerconstraints(NFRs)• Cultivatecontainer‘mechanicalsympathy’

10/10/2017 @danielbryantuk

Page 5: JAXLondon 2017 "Continuous Delivery with Containers and Java"

@danielbryantuk

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

• ContinuousDelivery(CI/CD)advocate

• Leadingchangethroughtechnologyandteams

10/10/2017 @danielbryantuk

Page 6: JAXLondon 2017 "Continuous Delivery with Containers and Java"

ContinuousDelivery

10/10/2017 @danielbryantuk

Page 7: JAXLondon 2017 "Continuous Delivery with Containers and Java"

ContinuousDelivery

• Producevaluableandrobustsoftwareinshortcycles

• Optimising forfeedbackandlearning

• Not (necessarily)ContinuousDeployment

10/10/2017 @danielbryantuk

Page 8: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Creationofabuildpipelineismandatoryforcontinuousdelivery

10/10/2017 @danielbryantuk

Page 9: JAXLondon 2017 "Continuous Delivery with Containers and Java"

10/10/2017 @danielbryantuk

Page 10: JAXLondon 2017 "Continuous Delivery with Containers and Java"

TheImpactofcontainersonCD

10/10/2017 @danielbryantuk

Page 11: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Containertechnology(andCD)

• OS-levelvirtualisation• cgroups,namespaces,rootfs

• Packageandexecutesoftware

• Containerimage==‘singlebinary’

10/10/2017 @danielbryantuk

Page 12: JAXLondon 2017 "Continuous Delivery with Containers and Java"

10/10/2017 @danielbryantuk

Page 13: JAXLondon 2017 "Continuous Delivery with Containers and Java"

10/10/2017 @danielbryantuk

Page 14: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Creatingapipelineforcontainers

10/10/2017 @danielbryantuk

Page 15: JAXLondon 2017 "Continuous Delivery with Containers and Java"

10/10/2017 @danielbryantuk

Page 16: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Makeyourdevenvironmentlikeproduction

• Developlocallyorcopy/codeincontainer

• Mustbuild/testcontainerslocally• Perform(atleast)happypathtests

10/10/2017 @danielbryantuk

Page 17: JAXLondon 2017 "Continuous Delivery with Containers and Java"

QuickAside:Running*entire*systemlocally

10/10/2017 @danielbryantuk

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

Page 18: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Makeyourdevenvironmentlikeproduction

• Developlocallyorcopy/codeincontainer

• Mustbuild/testcontainerslocally• Perform(atleast)happypathtests

• Useidenticalbaseimagesfromproduction• Withsameconfiguration

10/10/2017 @danielbryantuk

Page 19: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Lessonlearned:Dockerfile contentissuper important

• OSchoice

• Configuration

• Buildartifacts

• Exposingports

• Java• JDKvsJREandOraclevsOpenJDK?

• Golang• Staticallycompiledbinaryinscratch?

• Python• Virtualenv?

10/10/2017 @danielbryantuk

Page 20: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Pleasetalktothesysadminpeople:Theiroperationalknowledgeisinvaluable

10/10/2017 @danielbryantuk

Page 21: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Differenttestandprodcontainers?

• Create“test”versionofcontainer• FullOS(e.g.Ubuntu)• Testtoolsanddata

• Easytoseeapp/configurationdrift

• Usetestsidecarcontainersinstead

• ONTESTproposalbyAlexiLedenev

10/10/2017 @danielbryantuk

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

Page 22: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Dockermulti-stagebuilds

10/10/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: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Javaspecificstuff…

10/10/2017 @danielbryantuk

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

Page 24: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Hotoffthepress:Modularity

• Createminimalruntimeimages

• “jlink deliversaself-containeddistributionofyourapplicationandtheJVM,readytobeshipped.”

• Benefits:• Reducedfootprint• Performance• Security

10/10/2017 @danielbryantuk

Page 25: JAXLondon 2017 "Continuous Delivery with Containers and Java"

10/10/2017 @danielbryantuk

Page 26: JAXLondon 2017 "Continuous Delivery with Containers and Java"

BuildingimageswithJenkins

• Myreportcoversthis

• Buildasusual…

• BuildDockerImage• CloudbeesDockerBuildandPublishPlugin

• Pushimagetoregistry

10/10/2017 @danielbryantuk

Page 27: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Storinginanimageregistry(DockerHub)

10/10/2017 @danielbryantuk

Page 28: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Metadata– Bewareof“latest”DockerTag

• Bewareofthe‘latest’Dockertag

• “Latest”simplymeans• thelastbuild/tagthatranwithoutaspecifictag/versionspecified

• Ignore“latest”tag• Versionyourtags,everytime• danielbryantuk/test:2.4.1

10/10/2017 @danielbryantuk

Page 29: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Lessonlearned:Metadataisvaluable

• Applicationmetadata• Version/GITSHA

• Buildmetadata• Builddate• Imagename• Vendor

• Qualitymetadata• QAcontrol,signedbinaries,ephemeralsupport• Securityprofiles(AppArmor),Securityauditedetc

10/10/2017 @danielbryantuk

Page 30: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Metadata- AddingLabelsatbuildtime

• DockerLabels

• Addkey/valuedatatoimage

10/10/2017 @danielbryantuk

Page 31: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Metadata- AddingLabelsatbuildtime

• Microscaling Systems’Makefile

• LabellingautomatedbuildsonDockerHub (h/tRossFairbanks)• Createfile‘/hooks/build’

• label-schema.org• microbadger.com

10/10/2017 @danielbryantuk

Page 32: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Metadata- AddingLabelsatruntime

10/10/2017 @danielbryantuk

$ docker run -d --labeluk.co.danielbryant.lbname=frontdoor nginx

• Can’docker commit’,butcreatesnewimage

• Notpossibletoupdaterunningcontainer

• DockerProposal:Updatelabels #21721

Page 33: JAXLondon 2017 "Continuous Delivery with Containers and Java"

LizRice(andAqua)totherescue!

10/10/2017 @danielbryantuk

github.com/aquasecurity/manifesto

Page 34: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Externalregistrywithmetadatasupport

10/10/2017 @danielbryantuk

Page 35: JAXLondon 2017 "Continuous Delivery with Containers and Java"

10/10/2017 @danielbryantuk

Page 36: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Componenttesting

10/10/2017 @danielbryantuk

Page 37: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Testing:JenkinsPipeline(ascode)

10/10/2017 @danielbryantuk

Page 38: JAXLondon 2017 "Continuous Delivery with Containers and Java"

10/10/2017 @danielbryantuk

Page 39: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Testingindividualcontainers

10/10/2017 @danielbryantuk

Page 40: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Integrationtesting

10/10/2017 @danielbryantuk

Page 41: JAXLondon 2017 "Continuous Delivery with Containers and Java"

IntroducingDockerCompose

10/10/2017 @danielbryantuk

Page 42: JAXLondon 2017 "Continuous Delivery with Containers and Java"

DockerCompose&JenkinsPipeline

10/10/2017 @danielbryantuk

Page 43: JAXLondon 2017 "Continuous Delivery with Containers and Java"

EphemeralKubernetesClusters

• Kubernaut (WIP)

• Managesapoolofclusters

• ”Claim”afreshcluster

• UseHelmtoinstalldependencies

10/10/2017 @danielbryantuk

Page 44: JAXLondon 2017 "Continuous Delivery with Containers and Java"

TestingNFRsinthebuildpipeline

• PerformanceandLoadtesting• Gatling/jmeter• Flood.io

• Securitytesting• Findsecbugs /OWASPDependencycheck• Bdd-security(OWASPZAP)/Arachni• Gauntlt /Serverspec• DockerBenchforSecurity/CoreOSClair

10/10/2017 @danielbryantuk

Page 45: JAXLondon 2017 "Continuous Delivery with Containers and Java"

DelayingNFRstothe‘LastResponsibleMoment’

• Newsflash!• Sometimesthelastresponsiblemomentisup-front!

• Containers/microservices don’tmakethiseasier• Sometimesmoredifficult…

10/10/2017 @danielbryantuk

Page 46: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Mechanicalsympathy:DockerandJava

• WatchforJVMcgroup/taskset awareness• getAvailableProcessors()mayincorrectlyreportthenumberofcpus inDocker(JDK-8140793)• Runtime.availableProcessors()ignoresLinuxtaskset command(JDK-6515172)• Default fork/jointhreadpoolsizes(andothers)isbasedfromhostCPUcount

• Setcontainermemoryappropriately• JVMrequirements=Heapsize(Xmx)+Metaspace +JVMoverhead• Accountfornativethreadrequirementse.g.threadstacksize(Xss)

• Entropy• Hostentropycansoonbeexhaustedbycryptooperations

10/10/2017 @danielbryantuk 46

Page 47: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Deployment

10/10/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 48: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Observabilityiscoretocontinuousdelivery

10/10/2017 @danielbryantuk

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

Page 49: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Containersarenotasilverbullet

10/10/2017 @danielbryantuk

Page 50: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Movingtocontainers:Goingall-in?

10/10/2017 @danielbryantuk

OR

Page 51: JAXLondon 2017 "Continuous Delivery with Containers and Java"

ShouldIbuildmyowncontainerplatform?

Probablynot(UnlessyouareGoogle,AWSorIBM)

Whateveryoudecide…pushitthroughapipelineASAP!

10/10/2017 @danielbryantuk

Page 52: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Usingcontainersdoesnotobviatetheneedforgoodarchitecturalpractices

10/10/2017 @danielbryantuk

Page 53: JAXLondon 2017 "Continuous Delivery with Containers and Java"

10/10/2017 @danielbryantuk

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

Page 54: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Summary

10/10/2017 @danielbryantuk

Page 55: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Insummary

• Continuousdeliveryisvitallyimportantinmodernarchitectures/ops

• Containerimagesmustbethe(single)sourceoftruthwithinpipeline• Andmetadataaddedasappropriate…

• Mechanicalsympathyisimportant(assertpropertiesinthepipeline)• Notalldevelopersareoperationallyaware

• Thetoolingisnowbecomingstable/mature• Weneedtore-applyexistingCDpracticeswithnewtechnologies/tooling

10/10/2017 @danielbryantuk

Page 56: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Bedtimereading

10/10/2017 @danielbryantuk

Page 57: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Thanksforlistening

• Anyquestions?

• Feelfreetocontactme• @danielbryantuk• [email protected]

10/10/2017 @danielbryantuk

bit.ly/2jWDSF7

Comingsoon!

Page 58: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Bonusslides(forextracontext)

10/10/2017 @danielbryantuk

Page 59: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Containerise anexisting(monolithic)app?

• For

• Weknowthemonolithwell

• Allowshomogenizationofthepipelineanddeploymentplatform

• Canbeademonstrablewinfortechandthebusiness

• Against

• Canbedifficult(100+linescripts)

• Oftennotdesignedforoperationwithincontainers,norcloudnative

• Puttinglipstickonapig?

10/10/2017 @danielbryantuk

Page 60: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Keylessonslearned

• Conductanarchitecturalreview• ArchitectureforDevelopers,bySimonBrown• ArchitectureInterview,bySusanFowler

• Lookfordataingress/egress• Filesystemaccess

• Supportresourceconstraints/transience• Optimise forquickstartupandshutdown• Evaluateapproachtoconcurrency• Storeconfiguration(secrets)remotely

10/10/2017 @danielbryantuk

Page 61: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Newdesignpatterns

10/10/2017 @danielbryantuk

bit.ly/2efe0TP

Page 62: JAXLondon 2017 "Continuous Delivery with Containers and Java"

Microservices…

Containersandmicroservices arecomplementary

Testinganddeploymentchange

10/10/2017 @danielbryantuk

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

Page 63: JAXLondon 2017 "Continuous Delivery with Containers and Java"

10/10/2017 @danielbryantuk

Page 64: JAXLondon 2017 "Continuous Delivery with Containers and Java"

10/10/2017 @danielbryantuk

Page 65: JAXLondon 2017 "Continuous Delivery with Containers and Java"

10/10/2017 @danielbryantuk