continuous delivery the hard way with kubernetes · continuous delivery the hard way with...

62
Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden

Upload: others

Post on 22-May-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Continuous Delivery the hard way with Kubernetes

Luke Marsden, Developer Experience@lmarsden

Page 2: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Agenda1. Why should I deliver continuously? 2. Kubernetes primer 3. GitLab primer 4. “OK, so we’ve got these pieces, how are we

going to put them together?” 5. Let’s iterate on a design! 6. Conclusions

Page 3: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Agenda1. Why should I deliver continuously? 2. Kubernetes primer 3. GitLab primer 4. “OK, so we’ve got these pieces, how are we

going to put them together?” 5. Let’s iterate on a design! 6. Conclusions

Page 4: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Why should I continuously deliver?• Microservices • Conway’s law • Scaling project, scaling team • Velocity!

Page 5: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Kubernetes: all you need to know

Pods containers

ServicesDeployments

Container Image

Docker container image, contains your application code in an isolated environment.

Pod A set of containers, sharing network namespace and local volumes, co-scheduled on one machine. Mortal. Has pod IP. Has labels.

Deployment Specify how many replicas of a pod should run in a cluster. Then ensures that many are running across the cluster. Has labels.

Service Names things in DNS. Gets virtual IP. Two types: ClusterIP for internal services, NodePort for publishing to outside. Routes based on labels.

Page 6: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

GitLab primer

• Or you can use GitHub, Travis, Circle, Docker Hub, Quay.io, GCR…

CI system Docker registry

GitLab

Version controlled code

Version controlled code

Page 7: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

These are the things that we’ve got

Version controlled code

CI system

Docker registry

Kubernetes clusterCode

Docker image

Kubernetes YAML

Page 8: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

These are the things that we’ve got

Version controlled code

CI system

Docker registry

Kubernetes clusterCode

Docker image

Kubernetes YAML

git git + shell dockerregistryAPI

kubernetesAPI

Page 9: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

These are the things that we’ve got

Version controlled code

CI system

Docker registry

Kubernetes clusterCode

Docker image

Kubernetes YAML

Page 10: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

V1Initial deploy (manually)

Page 11: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V1 architecture

Version controlled code

CI system

Docker registry

Kubernetes cluster

Page 12: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V1 architecture

Version controlled code

CI system

Docker registry

Kubernetes clusterkubectl apply -f service.yaml

Page 13: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

V1Deploy update (with CI system)

Page 14: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V1 architecture

Version controlled code

CI system

Docker registry

Kubernetes cluster

Code

Docker image

Page 15: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V1 architecture

Version controlled code

CI system

Docker registry

Kubernetes clustergit push

master

Page 16: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V1 architecture

Version controlled code

CI system

Docker registry

Kubernetes clusterdocker build

:a1b2c3

Page 17: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V1 architecture

Version controlled code

CI system

Docker registry

Kubernetes clusterdocker push

:a1b2c3

Page 18: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V1 architecture

Version controlled code

CI system

Docker registry

Kubernetes clusterkubectl set image

:a1b2c3

Page 19: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

V1Rollback

Page 20: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V1 architecture

Version controlled code

CI system

Docker registry

Kubernetes cluster

Page 21: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V1 architecture

Version controlled code

CI system

Docker registry

Kubernetes cluster

git checkout master git revert HEAD git push

Page 22: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V1 architecture

Version controlled code

CI system

Docker registry

Kubernetes clusterdocker build

:b2c3d4

Page 23: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V1 architecture

Version controlled code

CI system

Docker registry

Kubernetes clusterdocker push

:b2c3d4

Page 24: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V1 architecture

Version controlled code

CI system

Docker registry

Kubernetes clusterkubectl set image

:b2c3d4

Page 25: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Demo!

Page 26: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Downsides• Building & pushing containers is slow (disk I/O,

network), shouldn’t need to this when rolling back • Branch per environment required per microservice

(explosion of branches, hard to manage & scale) • Only a matter of time until you get a git merge mess

• Better to decouple version of code at HEAD from version deployed…

Page 27: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled configuration

• users service • code for users service • Kubernetes YAML

• orders service • code for orders

service • Kubernetes YAML

• config repo • Kubernetes YAML

for users • Kubernetes YAML

for orders

• Version controlled config should be the source of truth for your whole app (all the microservices)

Page 28: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

V2Put all the yamels

in one place

Page 29: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V2 architecture

Version controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Code

Docker image

Kubernetes YAML

Have the CI system update the yamels automatically for you

Page 30: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V2 architecture

Version controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Code

Docker image

Kubernetes YAML

Have the CI system update the yamels automatically for you

Page 31: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V2 architecture

Version controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Code

Docker image

Kubernetes YAML

Have the CI system update the yamels automatically for you

Page 32: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V2 architecture

Version controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Code

Docker image

Kubernetes YAML

Have the CI system update the yamels automatically for you

Page 33: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V2 architecture

Version controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Code

Docker image

Kubernetes YAML

Have the CI system update the yamels automatically for you

Page 34: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V2 architecture

Version controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Code

Docker image

Kubernetes YAML

Have the CI system update the yamels automatically for you

Page 35: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V2 architecture

Version controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Code

Docker image

Kubernetes YAML

Have the CI system update the yamels automatically for you

Page 36: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V2 architecture

Version controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Code

Docker image

Kubernetes YAML

Have the CI system update the yamels automatically for you

Page 37: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Now you can recreate your production environment from the central YAML repository even if your entire production cluster gets deleted

Page 38: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Demo!

Page 39: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Downsides• The CI system is responsible for a lot now (design smell – overloaded) • You can only trigger the CI system by pushing code (we wanted to be able

to rollback without pushing code) • If you rollback out of band (directly with kubectl), you have to

remember to update the central configuration repo as well • Parallel builds can tread on eachothers’ toes, not atomic: race between git

checkout and git push (need a global lock) • Scripting updates of yamels can be a pain… it mangles your yamels • Developers start asking for more release management features (rollback,

pinning, automation for some envs and manual gating for others, and your once-simple script keeps growing…)

Page 40: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Decoupling versions from releasesCode versions (branches, tags) Environments & releases

• users service • master • feature_A • feature_B

• orders service • master • feature_A • feature_B

• …

• production • users -> master @ t1 • orders -> master @ t1

• staging • orders -> master @ t2

• orders -> master @ t2

conflating per-service code branches with environments in each repo is a hack, and doesn’t scale well

Page 41: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

V3Refactor architecture

Add “release manager”

Page 42: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

Page 43: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

Page 44: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

Page 45: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

Page 46: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

Page 47: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

Page 48: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

Page 49: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

Page 50: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

V3Rollback doesn’t go via CI

Page 51: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

rollback!

Page 52: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

rollback!

Page 53: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

rollback!

Page 54: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

rollback!

Page 55: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Version controlled code

V3 architectureVersion controlled code

CI system

Docker registry

Kubernetes cluster

Version controlled config

Release manager

Code

Docker image

Kubernetes YAML

push

imagepush

config

pull image

listimages

pull, modify, push config

push code

policy

rollback!

Page 56: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

What does the release manager do?• Watches for changes in a container registry (output of CI

system) • Makes commits for you to version controlled configuration

(understands Kubernetes YAML) • Depending on release policy (per environment), either push

changes continuously or permit manually gated releases • Allows releases to be rolled back by changing a pointer • Releases can be “locked” as a social cue

Page 57: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Different environments can have different release policies(no tight coupling between individual microservices repos

and what’s released)

Page 58: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Demo!

Page 59: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

This is how we deploy Weave Cloud

Weave Cloud helps devops iterate faster with: • observability &

monitoring • continuous delivery • container networks &

firewalls

Weave Flux is a release manager for Kubernetes

Page 60: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Other topics

• Kubernetes 101 • How do I monitor this stuff? (Prometheus) • Network policy for isolating & firewalling different

microservices

We have talks & trainings on all these topics in the Weave user group!

Page 61: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Join the Weave user group! meetup.com/pro/Weave/

Come hang out on Slack! weave.works/help

Page 62: Continuous Delivery the hard way with Kubernetes · Continuous Delivery the hard way with Kubernetes Luke Marsden, Developer Experience @lmarsden. Agenda ... pinning, automation for

Thanks! Questions?

We are hiring!DX in San Francisco

Engineers in London & SF

weave.works/weave-company/hiring

Check out Flux on GitHub: github.com/weaveworks/flux