Slide 1

Slide 1 text

@shahiddev Shahid Iqbal | Freelance consultant @shahiddev Solving microservice challenges using Kubernetes

Slide 2

Slide 2 text

@shahiddev Very brief intro Freelance hands-on consultant working on Azure, .NET & Kubernetes .NET developer/Architect for 10+ yrs & Microsoft MVP Based in the UK and working globally Co-organiser of the MK.net meetup in the UK @shahiddev on Twitter https://www.linkedin.com/in/shahiddev/ https://blog.headforcloud.com https://sessionize.com/shahid-iqbal

Slide 3

Slide 3 text

@shahiddev Agenda Technical challenges introduced by moving to microservices Addressing those challenges with various cloud native technologies

Slide 4

Slide 4 text

@shahiddev Not covering How to decompose your monolith to microservices Deep dive into creating containers Deep dive into Kubernetes concepts

Slide 5

Slide 5 text

@shahiddev Audience participation

Slide 6

Slide 6 text

@shahiddev Microservices “ Microservice architecture, is an approach to application development in which a large application is built as a suite of modular components or services. ... These services are built around business capabilities and independently deployable by fully automated deployment machinery.” https://searchmicroservices.techtarget.com/definition/microservices

Slide 7

Slide 7 text

@shahiddev Benefits of microservices architecture Independent scaling of services Smaller/less risky deployments Reduced cognitive load for development teams Easier to distribute work across dev teams …

Slide 8

Slide 8 text

@shahiddev Starting with a well structured monolith Monolith admin Reporting Registration Calendar

Slide 9

Slide 9 text

@shahiddev admin Reg Calendar Reports Decompose to microservices Monolith admin Reporting Registration Calendar microservices

Slide 10

Slide 10 text

@shahiddev Decomposing the monolith Monolith admin Reporting Registration Calendar

Slide 11

Slide 11 text

@shahiddev Evolution towards microservices architecture Monolith Registration Calendar admin Reporting

Slide 12

Slide 12 text

@shahiddev Evolution towards microservices architecture Monolith Registration Calendar admin reporting

Slide 13

Slide 13 text

@shahiddev Evolution towards microservices architecture admin reporting Reg Calendar

Slide 14

Slide 14 text

@shahiddev Evolution towards microservices architecture admin reporting Reg Calendar Front end

Slide 15

Slide 15 text

@shahiddev Evolution towards microservices architecture admin reporting Reg Calendar Front end

Slide 16

Slide 16 text

@shahiddev New problems we’ve introduced Multiple deployments – consistency Added infrastructure and environment complexity Multiple points of failure/latency Debugging applications Networking & traffic routing Difficulty tracing/logging across those services Security concerns – multiple services

Slide 17

Slide 17 text

@shahiddev Containers to the rescue?

Slide 18

Slide 18 text

@shahiddev What are containers? Package encapsulating your application and it’s dependencies Artefact from your CI system instead of binaries/deployment packages Provide isolation and consistent behaviour across environments “Lightweight VMs” – quick start up times Portable – work anywhere that supports the container runtime

Slide 19

Slide 19 text

@shahiddev Managing multiple containers

Slide 20

Slide 20 text

@shahiddev Container orchestrators to the rescue?

Slide 21

Slide 21 text

@shahiddev What is Kubernetes? Open source container orchestrator Helps you run container based applications by managing the containers across multiple nodes

Slide 22

Slide 22 text

@shahiddev What is container orchestration?

Slide 23

Slide 23 text

@shahiddev Kubernetes features Container orchestration Config and secrets management Self healing Autoscaling Service discovery & load balancing Basic traffic management (Ingress) Many more….

Slide 24

Slide 24 text

@shahiddev Host name based routing using Ingress Node 1 Node 2 Node 3 app1 svc app:app1 app:app1 app:app2 cluster app:app2 Load Balancer app2 svc Ingress controller Public IP app1.mydomain.com Host: app1.mydomain.com

Slide 25

Slide 25 text

@shahiddev Host name based routing using Ingress Node 1 Node 2 Node 3 app1 svc app:app1 app:app1 app:app2 cluster app:app2 Load Balancer app2 svc Ingress controller Public IP app2.mydomain.com Host: app2.mydomain.com

Slide 26

Slide 26 text

@shahiddev Scaling our applications in Kubernetes 2 types of application level scaling Horizontal scaling (adding more instances) - HPA Vertical scaling (increasing resources allocated to existing instance) – VPA Cluster autoscaler (CA) Increase number of nodes in your cluster to increase compute capacity Virtual Node “serverless” scaling of Kubernetes

Slide 27

Slide 27 text

@shahiddev Auto scaling triggers Horizontal scaling can be based on metrics from application V1 HPA uses CPU/Memory V2 HPA (beta) can scale from almost any metric including external metrics (e.g. queue depth) VPA CPU/Memory usage of application Cluster autoscaler based on applications waiting to be scheduled due to insufficient cluster resources

Slide 28

Slide 28 text

@shahiddev Virtual Kubelet/Node

Slide 29

Slide 29 text

@shahiddev Virtual Kubelet implementations Azure Container Instances AWS Fargate Hashicorp Nomad Service Fabric Mesh Azure IoT Edge …others

Slide 30

Slide 30 text

@shahiddev Azure Container Instances “Serverless” containers No infrastructure required Per sec billing for running container Good for: Testing images Short lived containers Bursting for sudden spikes Price reductions -> competitive price vs PaaS/VMs

Slide 31

Slide 31 text

@shahiddev Bursting load using virtual node Bursting to ACI to continue scaling beyond cluster capacity ACI

Slide 32

Slide 32 text

@shahiddev Virtual node public preview

Slide 33

Slide 33 text

@shahiddev DEMO VIRTUAL NODE SCALING

Slide 34

Slide 34 text

@shahiddev Scale to zero Out of the box Kubernetes unable to scale applications to zero instances Desirable to scale certain microservices to zero instances Message handlers “functions” style applications

Slide 35

Slide 35 text

@shahiddev KEDA – Kubernetes Event Driven Autoscaler Open source project led by Microsoft and RedHat Allows for Kubernetes deployments to be auto scaled based on events Scale up from zero -> n instances Scale down from n -> zero instances Deploy functions (e.g. Azure Functions) and replicate behaviour found in managed cloud platforms Combine with Virtual node to utilise FaaS alongside traditional microservices using consistent platform for managing

Slide 36

Slide 36 text

@shahiddev Operating Kubernetes Cluster Managed Kubernetes providers help reduce the operational complexity of running Kubernetes yourself Google Kubernetes Engine Azure Kubernetes Service

Slide 37

Slide 37 text

@shahiddev Problem checklist ☹ ☹ Multiple deployments – consistency More infrastructure and environment complexity Multiple points of failure Debugging applications Networking & traffic routing Tracing/logging across those services Security concerns – multiple services

Slide 38

Slide 38 text

@shahiddev Tooling to the rescue? Azure Dev Spaces Kustomize

Slide 39

Slide 39 text

@shahiddev From code to Kubernetes Write code Push code to repository Build containers Push container to registry Create/update deployment “package” Deploy “package” to K8s Continuous Integration Deployment Local development

Slide 40

Slide 40 text

@shahiddev Working with dependent services Frontend Service A Service B 1. Mock/stub out dependent services 2. Run all dependent services on my local machine 3. Run everything on remote cluster 4. Run dependent services on remote cluster

Slide 41

Slide 41 text

@shahiddev AKS cluster Azure Dev Spaces Frontend Service A Service B laptop app.mydomain.com Service A V2 Shahid.s.app.mydomain.com

Slide 42

Slide 42 text

@shahiddev Shahid dev space Default dev space Azure Dev Spaces Frontend Service A Service B app.mydomain.com Service A V2 shahid.s.app.mydomain.com AKS cluster

Slide 43

Slide 43 text

@shahiddev Azure Dev Spaces Works with VS Code and Visual Studio First class support for .NET Core, NodeJS & Java Limited support for other languages Use it to dev/test applications on AKS even if you deploy prod to other Kubernetes clusters GA as of May 6th 2019 https://docs.microsoft.com/en-us/azure/dev-spaces/

Slide 44

Slide 44 text

@shahiddev DEMO AZURE DEV SPACES

Slide 45

Slide 45 text

@shahiddev Problem checklist ☹ Multiple deployments – consistency More infrastructure and environment complexity Multiple points of failure Debugging applications Networking & traffic routing Tracing/logging across those services Security concerns – multiple services

Slide 46

Slide 46 text

@shahiddev Service mesh to the rescue?

Slide 47

Slide 47 text

@shahiddev What is a Service mesh? “A service mesh is a dedicated infrastructure layer for handling service-to-service communication. It’s responsible for the reliable delivery of requests through the complex topology of services that comprise a modern, cloud native application.” https://blog.buoyant.io/2017/04/25/whats-a-service-mesh-and-why-do-i-need-one/

Slide 48

Slide 48 text

@shahiddev What is Istio? Open source project being led by Lyft, IBM & Google Runs on top of Kubernetes (and other platforms) to extend capabilities Provides: • Network error handling (retry, circuit breakers, timeouts) • Rate limiting • Traffic shifting • Fault injection • Service to service communication security & policies • Distributed tracing of requests

Slide 49

Slide 49 text

@shahiddev Istio architecture Data plane Management plane

Slide 50

Slide 50 text

@shahiddev Deploying Istio to your cluster and applications Cluster • Istio can be installed in Kubernetes using Helm • Using a number of Custom Resource Definitions (CRDs) to extend behaviour Application • Envoy proxy can be automatically injected into your applications during deployment • Generate updated manifest files using Istioctl

Slide 51

Slide 51 text

@shahiddev Securing service to service communications Products Product reviews Product ratings Product details

Slide 52

Slide 52 text

@shahiddev Securing service to service communications Products Product reviews Product ratings Product details

Slide 53

Slide 53 text

@shahiddev Traffic shifting Products Product reviews Product ratings Product details

Slide 54

Slide 54 text

@shahiddev Traffic shifting Products Product reviews V1 Product ratings Product details Product reviews V2 User=Jason Jason

Slide 55

Slide 55 text

@shahiddev Canary deployments Products Product reviews V1 Product ratings Product details Product reviews V2 10% 90%

Slide 56

Slide 56 text

@shahiddev Observability and metrics • Metrics collected in Prometheus • Built in Grafana dashboards to display service level metrics • Distributed tracing using Jaegar

Slide 57

Slide 57 text

@shahiddev Demo Application Products Product reviews V1 Product ratings Product details Product reviews V2 No stars

Slide 58

Slide 58 text

@shahiddev DEMO ISTIO

Slide 59

Slide 59 text

@shahiddev Problem checklist Multiple deployments – consistency More infrastructure and environment complexity Multiple points of failure Debugging applications Networking & traffic routing Tracing/logging across those services Security concerns – multiple services

Slide 60

Slide 60 text

@shahiddev Summary Cloud native technologies can help alleviate technical complexity caused by adopting microservices Complexity is rarely removed, just shifted (and hopefully becomes someone else's problem) Don’t be peer pressured into adopting microservices Developer tooling for Kubernetes is an area of rapid innovation Service meshes can help with service to service communications But you don’t always need them!

Slide 61

Slide 61 text

@shahiddev Where can I go to learn more? http://www.katacoda.com https://katacoda.com/courses/istio/ https://bit.ly/k8s-ndc https://istio.io

Slide 62

Slide 62 text

@shahiddev Shahid Iqbal | Freelance consultant @shahiddev Thank you! Slides: https://bit.ly/k8s-microservices Video: https://bit.ly/k8s-microservices-video @shahiddev on Twitter https://www.linkedin.com/in/shahiddev/ https://blog.headforcloud.com