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

Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

ContinuousDeliverywithContainers:TheGood,theBad,andtheUgly

DanielBryant@danielbryantuk

Page 2: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Containers:Expectationsversusreality

10/10/2017 @danielbryantuk

“DevOps”

Page 3: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Settingthescene…

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

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

10/10/2017 @danielbryantuk

bit.ly/2jWDSF7

Page 4: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

TL;DR– ContainersandCD

• Containerimagebecomesthebuildpipeline‘singlebinary’

• Addingmetadatatocontainersimagesisvital,butchallenging

• Mustvalidatecontainerconstraints(NFRs)• Cultivatecontainer‘mechanicalsympathy’

10/10/2017 @danielbryantuk

Page 5: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

@danielbryantuk

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

• ContinuousDelivery(CI/CD)advocate

• Leadingchangethroughtechnologyandteams

10/10/2017 @danielbryantuk

Page 6: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

ContinuousDelivery

10/10/2017 @danielbryantuk

Page 7: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

ContinuousDelivery

• Producevaluableandrobustsoftwareinshortcycles

• Optimising forfeedbackandlearning

• Not (necessarily)ContinuousDeployment

10/10/2017 @danielbryantuk

Page 8: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Creationofabuildpipelineismandatoryforcontinuousdelivery

10/10/2017 @danielbryantuk

Page 9: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

10/10/2017 @danielbryantuk

Page 10: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

TheImpactofcontainersonCD

10/10/2017 @danielbryantuk

Page 11: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Containertechnology(andCD)

• OS-levelvirtualisation• cgroups,namespaces,rootfs

• Packageandexecutesoftware

• Containerimage==‘singlebinary’

10/10/2017 @danielbryantuk

Page 12: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

10/10/2017 @danielbryantuk

Page 13: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

10/10/2017 @danielbryantuk

Page 14: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Creatingapipelineforcontainers

10/10/2017 @danielbryantuk

Page 15: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

10/10/2017 @danielbryantuk

Page 16: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Makeyourdevenvironmentlikeproduction

• Developlocallyorcopy/codeincontainer

• Mustbuild/testcontainerslocally• Perform(atleast)happypathtests

10/10/2017 @danielbryantuk

Page 17: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

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: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Makeyourdevenvironmentlikeproduction

• Developlocallyorcopy/codeincontainer

• Mustbuild/testcontainerslocally• Perform(atleast)happypathtests

• Useidenticalbaseimagesfromproduction• Withsameconfiguration

10/10/2017 @danielbryantuk

Page 19: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Lessonlearned:Dockerfile contentissuper important

• OSchoice

• Configuration

• Buildartifacts

• Exposingports

• Java• JDKvsJREandOraclevsOpenJDK?

• Golang• Staticallycompiledbinaryinscratch?

• Python• Virtualenv?

10/10/2017 @danielbryantuk

Page 20: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Pleasetalktothesysadminpeople:Theiroperationalknowledgeisinvaluable

10/10/2017 @danielbryantuk

Page 21: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

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: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

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: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Javaspecificstuff…

10/10/2017 @danielbryantuk

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

Page 24: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Hotoffthepress:Modularity

• Createminimalruntimeimages

• “jlink deliversaself-containeddistributionofyourapplicationandtheJVM,readytobeshipped.”

• Benefits:• Reducedfootprint• Performance• Security

10/10/2017 @danielbryantuk

Page 25: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

10/10/2017 @danielbryantuk

Page 26: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

BuildingimageswithJenkins

• Myreportcoversthis

• Buildasusual…

• BuildDockerImage• CloudbeesDockerBuildandPublishPlugin

• Pushimagetoregistry

10/10/2017 @danielbryantuk

Page 27: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Storinginanimageregistry(DockerHub)

10/10/2017 @danielbryantuk

Page 28: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

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: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Lessonlearned:Metadataisvaluable

• Applicationmetadata• Version/GITSHA

• Buildmetadata• Builddate• Imagename• Vendor

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

10/10/2017 @danielbryantuk

Page 30: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Metadata- AddingLabelsatbuildtime

• DockerLabels

• Addkey/valuedatatoimage

10/10/2017 @danielbryantuk

Page 31: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Metadata- AddingLabelsatbuildtime

• Microscaling Systems’Makefile

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

• label-schema.org• microbadger.com

10/10/2017 @danielbryantuk

Page 32: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

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: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

LizRice(andAqua)totherescue!

10/10/2017 @danielbryantuk

github.com/aquasecurity/manifesto

Page 34: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Externalregistrywithmetadatasupport

10/10/2017 @danielbryantuk

Page 35: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

10/10/2017 @danielbryantuk

Page 36: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Componenttesting

10/10/2017 @danielbryantuk

Page 37: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Testing:JenkinsPipeline(ascode)

10/10/2017 @danielbryantuk

Page 38: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

10/10/2017 @danielbryantuk

Page 39: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Testingindividualcontainers

10/10/2017 @danielbryantuk

Page 40: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Integrationtesting

10/10/2017 @danielbryantuk

Page 41: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

IntroducingDockerCompose

10/10/2017 @danielbryantuk

Page 42: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

DockerCompose&JenkinsPipeline

10/10/2017 @danielbryantuk

Page 43: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

EphemeralKubernetesClusters

• Kubernaut (WIP)

• Managesapoolofclusters

• ”Claim”afreshcluster

• UseHelmtoinstalldependencies

10/10/2017 @danielbryantuk

Page 44: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

TestingNFRsinthebuildpipeline

• PerformanceandLoadtesting• Gatling/jmeter• Flood.io

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

10/10/2017 @danielbryantuk

Page 45: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

DelayingNFRstothe‘LastResponsibleMoment’

• Newsflash!• Sometimesthelastresponsiblemomentisup-front!

• Containers/microservices don’tmakethiseasier• Sometimesmoredifficult…

10/10/2017 @danielbryantuk

Page 46: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

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: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

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: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Observabilityiscoretocontinuousdelivery

10/10/2017 @danielbryantuk

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

Page 49: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Containersarenotasilverbullet

10/10/2017 @danielbryantuk

Page 50: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Movingtocontainers:Goingall-in?

10/10/2017 @danielbryantuk

OR

Page 51: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

ShouldIbuildmyowncontainerplatform?

Probablynot(UnlessyouareGoogle,AWSorIBM)

Whateveryoudecide…pushitthroughapipelineASAP!

10/10/2017 @danielbryantuk

Page 52: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Usingcontainersdoesnotobviatetheneedforgoodarchitecturalpractices

10/10/2017 @danielbryantuk

Page 53: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

10/10/2017 @danielbryantuk

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

Page 54: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Summary

10/10/2017 @danielbryantuk

Page 55: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Insummary

• Continuousdeliveryisvitallyimportantinmodernarchitectures/ops

• Containerimagesmustbethe(single)sourceoftruthwithinpipeline• Andmetadataaddedasappropriate…

• Mechanicalsympathyisimportant(assertpropertiesinthepipeline)• Notalldevelopersareoperationallyaware

• Thetoolingisnowbecomingstable/mature• Weneedtore-applyexistingCDpracticeswithnewtechnologies/tooling

10/10/2017 @danielbryantuk

Page 56: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Bedtimereading

10/10/2017 @danielbryantuk

Page 57: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Thanksforlistening

• Anyquestions?

• Feelfreetocontactme• @danielbryantuk• [email protected]

10/10/2017 @danielbryantuk

bit.ly/2jWDSF7

Comingsoon!

Page 58: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Bonusslides(forextracontext)

10/10/2017 @danielbryantuk

Page 59: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Containerise anexisting(monolithic)app?

• For

• Weknowthemonolithwell

• Allowshomogenizationofthepipelineanddeploymentplatform

• Canbeademonstrablewinfortechandthebusiness

• Against

• Canbedifficult(100+linescripts)

• Oftennotdesignedforoperationwithincontainers,norcloudnative

• Puttinglipstickonapig?

10/10/2017 @danielbryantuk

Page 60: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Keylessonslearned

• Conductanarchitecturalreview• ArchitectureforDevelopers,bySimonBrown• ArchitectureInterview,bySusanFowler

• Lookfordataingress/egress• Filesystemaccess

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

10/10/2017 @danielbryantuk

Page 61: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Newdesignpatterns

10/10/2017 @danielbryantuk

bit.ly/2efe0TP

Page 62: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

Microservices…

Containersandmicroservices arecomplementary

Testinganddeploymentchange

10/10/2017 @danielbryantuk

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

Page 63: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

10/10/2017 @danielbryantuk

Page 64: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

10/10/2017 @danielbryantuk

Page 65: Continuous Delivery with Containers: The Good ... - JAX London · Mechanical sympathy: Docker and Java • Watch for JVM cgroup/taskset awareness • getAvailableProcessors() may

10/10/2017 @danielbryantuk