developing micro-services with kubernetes 24 april 2018 ... · developing micro-services with...

96
Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, @mjbright Slides & source code at https://mjbright.github.io/Talks 1 / 56

Upload: others

Post on 20-May-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Developing Micro-services with Kubernetes

24 April 2018, CodeEurope.pl

Michael Bright, @mjbright

Slides & source code at https://mjbright.github.io/Talks 1 / 56

Page 2: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Michael Bright, @mjbright

Cloud Native Solution Architect

Trainer: Kubernetes, Serverless, Docker, CloudNative

Past researcher, dev, team lead, dev advocate

British, living in France for 25-years

Docker Community Lead, Python User Group

linkedin.com/in/mjbright github.com/mjbright2 / 56

Page 3: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Outline

Monoliths to Micro-services

Micro-service design patterns

Kubernetes

Operations

Demo

Tools

@mjbright 3 / 56

Page 4: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Outline

Monoliths to Micro-services

Micro-service design patterns

Kubernetes

Operations

Demo

Tools

@mjbright 4 / 56

Page 5: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

First ... a bit of history

@mjbright 5 / 56

Page 6: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

First ... a bit of history

Note: But the future is hybrid ...

@mjbright 5 / 56

Page 7: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Monoliths to Micro-servicesMonoliths are deployed, scaled, upgraded, reimplemented as completeunits

web . . . .

Individual µ-service components can be deployed, scaled, upgraded,reimplemented ...

web

@mjbright 6 / 56

Page 8: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Advantages of Micro-servicesSeparation of Concerns - "do one thing well"

@mjbright 7 / 56

Page 9: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Advantages of Micro-servicesSeparation of Concerns - "do one thing well"

Smaller Projects/teams

@mjbright 7 / 56

Page 10: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Advantages of Micro-servicesSeparation of Concerns - "do one thing well"

Smaller Projects/teams

Ease Scaling, Deployment, Testing, Evolution

@mjbright 7 / 56

Page 11: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Advantages of Micro-servicesSeparation of Concerns - "do one thing well"

Smaller Projects/teams

Ease Scaling, Deployment, Testing, Evolution

Loosely coupled components

@mjbright 7 / 56

Page 12: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Advantages of Micro-servicesSeparation of Concerns - "do one thing well"

Smaller Projects/teams

Ease Scaling, Deployment, Testing, Evolution

Loosely coupled components

Allow for composition of new services

@mjbright 7 / 56

Page 13: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Advantages of Micro-servicesSeparation of Concerns - "do one thing well"

Smaller Projects/teams

Ease Scaling, Deployment, Testing, Evolution

Loosely coupled components

Allow for composition of new services

So are they a panacea?

@mjbright 7 / 56

Page 14: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

DisadvantagesGreater complexity

Requires more orchestrationGreater organizational complexityMonitoring, debugging is more difficult

@mjbright 8 / 56

Page 15: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

DisadvantagesGreater complexity

Requires more orchestrationGreater organizational complexityMonitoring, debugging is more difficult

More network communication

Network error handlingPerformance

@mjbright 8 / 56

Page 16: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

DisadvantagesGreater complexity

Requires more orchestrationGreater organizational complexityMonitoring, debugging is more difficult

More network communication

Network error handlingPerformance

Still requires best practices

Behaviour and Test-Driven DevelopmentCI/CDDocumentation of interfaces/APIsStable interfaces/APIs

@mjbright 8 / 56

Page 17: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Outline

Monoliths to Micro-services

Micro-service design patterns

Kubernetes

Operations

Demo

Tools

@mjbright 9 / 56

Page 18: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Architecture Design PatternsStandard Component Patterns

@mjbright 10 / 56

Page 19: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Architecture Design PatternsStandard Component Patterns

Fine-grained SOA - Micro-services(!)

@mjbright 10 / 56

Page 20: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Architecture Design PatternsStandard Component Patterns

Fine-grained SOA - Micro-services(!)

Strangler

@mjbright 10 / 56

Page 21: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Architecture Design PatternsStandard Component Patterns

Fine-grained SOA - Micro-services(!)

Strangler

API Gateway

@mjbright 10 / 56

Page 22: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Architecture Design PatternsStandard Component Patterns

Fine-grained SOA - Micro-services(!)

Strangler

API Gateway

Service Mesh

@mjbright 10 / 56

Page 23: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Architecture Design PatternsStandard Component Patterns

Fine-grained SOA - Micro-services(!)

Strangler

API Gateway

Service Mesh

Hybrid Apps

@mjbright 10 / 56

Page 24: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Design Pattern - API GatewayExposes internal APIs via single external entrypoint.

Offload common functionsrate limiting, security, authorisationprotection against DDoSreduces µ-service complexity

@mjbright 11 / 56

Page 25: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Design Pattern - API GatewayExposes internal APIs via single external entrypoint.

Offload common functionsrate limiting, security, authorisationprotection against DDoSreduces µ-service complexity

Hides internal infrastructure detailservice routing, load-balancing

@mjbright 11 / 56

Page 26: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Design Pattern - API GatewayExposes internal APIs via single external entrypoint.

Offload common functionsrate limiting, security, authorisationprotection against DDoSreduces µ-service complexity

Hides internal infrastructure detail

service routing, load-balancing

Prevents general access to internal infrastructure

@mjbright 11 / 56

Page 27: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Design Pattern - API GatewayExposes internal APIs via single external entrypoint.

Offload common functionsrate limiting, security, authorisationprotection against DDoSreduces µ-service complexity

Hides internal infrastructure detail

service routing, load-balancing

Prevents general access to internal infrastructure

Allows to refactor/scale/mock internal implementation

@mjbright 11 / 56

Page 28: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Design Pattern - API GatewayExposes internal APIs via single external entrypoint.

Offload common functionsrate limiting, security, authorisationprotection against DDoSreduces µ-service complexity

Hides internal infrastructure detail

service routing, load-balancing

Prevents general access to internal infrastructure

Allows to refactor/scale/mock internal implementation

Protocol version translation, e.g. REST/https to REST or SOAP/http, *-RPC ...

@mjbright 11 / 56

Page 29: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Design Pattern - API GatewayExposes internal APIs via single external entrypoint.

Offload common functionsrate limiting, security, authorisationprotection against DDoSreduces µ-service complexity

Hides internal infrastructure detail

service routing, load-balancing

Prevents general access to internal infrastructure

Allows to refactor/scale/mock internal implementation

Protocol version translation, e.g. REST/https to REST or SOAP/http, *-RPC ...

Needs to scale, be H.A.

@mjbright 11 / 56

Page 30: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Design Pattern - API Gateway

 

Service 1(REST/http)

API Gateway

Service2(JSON-RPC)

Service3(WAMP)

https://api.com/....

@mjbright 12 / 56

Page 31: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Design Pattern - Service MeshAbstraction above TCP/IP, secure reliable inter-service connectivity.

@mjbright 13 / 56

Page 32: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Design Pattern - Service MeshAbstraction above TCP/IP, secure reliable inter-service connectivity.

Offloads functionality from services in a distributed way.

@mjbright 13 / 56

Page 33: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Design Pattern - Service MeshAbstraction above TCP/IP, secure reliable inter-service connectivity.

Offloads functionality from services in a distributed way.

@mjbright 13 / 56

Page 34: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Design Pattern - Hybrid AppsGloo allows to route between legacy apps, micro-services and serverlessincrementally adding new functionality.

https://medium.com/solo-io/building-hybrid-apps-with-gloo-1eb96579b070

@mjbright 14 / 56

Page 35: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Outline

Monoliths to Micro-services

Micro-service design patterns

Kubernetes

Operations

Demo

Tools

@mjbright 15 / 56

Page 36: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

We need Orchestration

@mjbright16 / 56

Page 37: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Kubernetes - Architecture

WorkerNode 1

Master Node

WorkerNode 2

WorkerNode 3

@mjbright 17 / 56

Page 38: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Kubernetes - Master Nodes

 etcd Master

Master

Master

API

GUI(dashboard)

CLI(kubectl)

API

Server

Scheduler Controller

@mjbright 18 / 56

Page 39: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Kubernetes - Worker Nodes

Pod

 

Kubelet ContainerEngine

kube-proxy 

flatnetwork 

Pod

Pod

Pod

Pod

Pod

dashboardkube-dnsAdd-ons

@mjbright 19 / 56

Page 40: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Kubernetes - Pods 

same ip, e.g. 192.168.1.20

Containers share some namespaces: - PID, IPC, network , time sharing

A pod houses one or more containers

SidecarMain container

@mjbright 20 / 56

Page 41: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Kubernetes Demo

Master Node

"Worker"

Minikube single-node "tainted"

 

Flask1 Flask2 Flask3

Redis

Ingress

Load Balancer

@mjbright 21 / 56

Page 42: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Kubernetes - Deploying Redis 

kubectl create -f redis-deployment.yaml deployment

ReplicaSet

Pod1

2e76: redis

@mjbright 22 / 56

Page 43: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Kubernetes - Deploying Redis# kubectl run redis --image=redis:latest --port=6379

$ kubectl apply -f redis-deployment.yaml

deployment.extensions "redis" created

$ kubectl get pods

NAME READY STATUS RESTARTS AGE

redis-68595c4d95-rr4pr 0/1 ContainerCreating 0 1s

@mjbright 23 / 56

Page 44: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Kubernetes - Deploying Redis (yaml)apiVersion: extensions/v1beta1

kind: Deployment

metadata:

labels:

run: redis

name: redis

spec:

replicas: 1

selector:

matchLabels:

run: redis

template:

metadata:

labels:

run: redis

spec:

containers:

- image: redis:latest

name: redis

ports:

- containerPort: 6379

@mjbright 24 / 56

Page 45: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Kubernetes - Deploying Flask 

kubectl create -f flask-deployment.yaml deployment

ReplicaSet

Pod2

1f3d: flask:v1

Pod1

2e76: flask:v1

@mjbright 25 / 56

Page 46: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Kubernetes - Deploying Flask# kubectl run flask-app --image=$IMAGE --port=5000

$ kubectl apply -f flask-deployment.yaml

deployment.extensions "flask-app" created

$ kubectl get pods

NAME READY STATUS RESTARTS AGE

flask-app-8577b44db-96cht 0/1 Pending 0 1s

redis-68595c4d95-rr4pr 0/1 ContainerCreating 0 1s

@mjbright 26 / 56

Page 47: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Kubernetes - Deploying Flask (yaml)apiVersion: extensions/v1beta1

kind: Deployment

metadata:

labels:

run: flask-app

name: flask-app

spec:

replicas: 1

selector:

matchLabels:

run: flask-app

template:

metadata:

labels:

run: flask-app

spec:

containers:

- image: mjbright/flask-web:v1

name: flask-app

ports:

- containerPort: 5000

@mjbright 27 / 56

Page 48: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Kubernetes - Exposing Services

Master User

WorkerWorker

pod

pod

pod

pod

ServiceIP:port

@mjbright 28 / 56

Page 49: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Exposing Services (LoadBalancer)

Master User

Worker

pod

pod

IP:port ExternalLoad Balancer

Worker

pod

pod

Service

@mjbright 29 / 56

Page 50: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Exposing Services (NodePort)

Master User

WorkerWorker

pod

pod

pod

pod

IP:port

User connects

to IP/port of one

of the NodesIP:port

Service

@mjbright 30 / 56

Page 51: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Exposing Services (IngressController)

Master User

Worker

pod

pod

Ingressroute

Worker

pod

pod

Service

@mjbright 31 / 56

Page 52: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Exposing Redis Service (LoadBalancer)# kubectl expose deployment redis --type=LoadBalancer

$ kubectl apply -f redis-service.yaml

service "redis" created

$ kubectl get svc

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5h

redis LoadBalancer 10.101.158.201 <pending> 6379:31218/TCP 1s

@mjbright 32 / 56

Page 53: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Exposing Redis Service (LoadBalancer)apiVersion: v1

kind: Service

metadata:

labels:

run: redis

name: redis

spec:

ports:

- port: 6379

protocol: TCP

targetPort: 6379

selector:

run: redis

type: LoadBalancer

@mjbright 33 / 56

Page 54: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Exposing Flask Service (LoadBalancer)# kubectl expose deployment flask-app --type=LoadBalancer

$ kubectl apply -f flask-service.yaml

service "flask-app" created

$ kubectl get svc

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

flask-app LoadBalancer 10.103.154.19 <pending> 5000:32201/TCP 1s

kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5h

redis LoadBalancer 10.101.158.201 <pending> 6379:31218/TCP 2s

@mjbright 34 / 56

Page 55: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Exposing Flask Service (LoadBalancer)apiVersion: v1

kind: Service

metadata:

labels:

run: flask-app

name: flask-app

spec:

ports:

- port: 5000

protocol: TCP

targetPort: 5000

selector:

run: flask-app

type: LoadBalancer

@mjbright 35 / 56

Page 56: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Exposing Services (Ingress)$ minikube addons enable ingress

ingress was successfully enabled

$ kubectl apply -f misc/ingress-definition.yaml

ingress.extensions "ingress-definitions" created

$ sudo vi /etc/hosts

...

192.168.99.100 minikube.test flaskapp.test

@mjbright 36 / 56

Page 57: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Exposing Services (Ingress)apiVersion: extensions/v1beta1

kind: Ingress

metadata:

name: ingress-definitions

annotations:

nginx.ingress.kubernetes.io/rewrite-target: /

spec:

backend:

serviceName: default-http-backend

servicePort: 80

rules:

- host: minikube.test

http:

paths:

- path: /

backend:

serviceName: k8sdemo

servicePort: 8080

- host: flaskapp.test

http:

paths:

- path: /flask

backend:

serviceName: flask-app

servicePort: 5000

@mjbright 37 / 56

Page 58: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Exposing Services (Ingress)$ minikube service list

|-------------|----------------------|-----------------------------|

| NAMESPACE | NAME | URL |

|-------------|----------------------|-----------------------------|

| default | flask-app | http://192.168.99.100:32201 |

| default | k8sdemo | http://192.168.99.100:31280 |

| default | redis | http://192.168.99.100:31218 |

| kube-system | kubernetes-dashboard | http://192.168.99.100:30000 |

|-------------|----------------------|-----------------------------|

$ curl http://192.168.99.100:31280

$ curl http://minikube.test/k8sdemo

@mjbright 38 / 56

Page 59: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Exposing Services (Ingress)$ minikube service list

|-------------|----------------------|-----------------------------|

| NAMESPACE | NAME | URL |

|-------------|----------------------|-----------------------------|

| default | flask-app | http://192.168.99.100:32201 |

| default | k8sdemo | http://192.168.99.100:31280 |

| default | redis | http://192.168.99.100:31218 |

| kube-system | kubernetes-dashboard | http://192.168.99.100:30000 |

|-------------|----------------------|-----------------------------|

$ curl http://192.168.99.100:32201

[flask-app-8577b44db-kbwpn] Redis counter value=214

$ curl http://flaskapp.test/flask

[flask-app-8577b44db-kbwpn] Redis counter value=215

@mjbright 39 / 56

Page 60: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Outline

Monoliths to Micro-services

Micro-service design patterns

Kubernetes

Operations

Demo

Tools

@mjbright 40 / 56

Page 61: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

OperationsH.A.

Scaling

Rolling Upgrade

Strategies

Health Checks

@mjbright 41 / 56

Page 62: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Operations - achieving High AvailabilityAchieved through running multiple instances across multiple nodes of thedata center

resilience to node outages

resilience to pod outages or poor response times

@mjbright 42 / 56

Page 63: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Operations - Scaling# kubectl scale deploy flask-app --replicas=4

$ kubectl edit -f flask-deploy.yaml

...

spec:

replicas: 4

@mjbright 43 / 56

Page 64: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Operations - Rolling UpgradesSeveral strategies exist

recreate   - terminate old version before releasing new one

@mjbright 44 / 56

Page 65: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Operations - Rolling UpgradesSeveral strategies exist

recreate   - terminate old version before releasing new one

ramped   - gradually release a new version on a rolling update fashion

@mjbright 44 / 56

Page 66: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Operations - Rolling UpgradesSeveral strategies exist

recreate   - terminate old version before releasing new one

ramped   - gradually release a new version on a rolling update fashion

blue/green   - release new version alongside old version then switch

@mjbright 44 / 56

Page 67: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Operations - Rolling UpgradesSeveral strategies exist

recreate   - terminate old version before releasing new one

ramped   - gradually release a new version on a rolling update fashion

blue/green   - release new version alongside old version then switch

canary   - release new version to subset of users, proceed to full rollout

@mjbright 44 / 56

Page 68: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Operations - Rolling UpgradesSeveral strategies exist

recreate   - terminate old version before releasing new one

ramped   - gradually release a new version on a rolling update fashion

blue/green   - release new version alongside old version then switch

canary   - release new version to subset of users, proceed to full rollout

a/b testing   - release new version to subset of users in a precise way

(HTTP headers, cookie, weight, etc.).

@mjbright 44 / 56

Page 69: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Operations - Rolling UpgradeRamped

# kubectl set image deploy flask-app flask-app=mjbright/flask-web:v2

$ kubectl edit -f flask-deploy.yaml$ kubectl rollout status deployment/flask-app

...

spec:

containers:

- image: mjbright/flask-web:v2

@mjbright 45 / 56

Page 70: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Outline

Monoliths to Micro-services

Micro-service design patterns

Kubernetes

Operations

Demo

Tools

@mjbright 46 / 56

Page 71: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Demo

Master Node

"Worker"

Minikube single-node "tainted"

 

Flask1 Flask2 Flask3

Redis

Ingress

Load Balancer

@mjbright 47 / 56

Page 72: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Outline

Monoliths to Micro-services

Micro-service design patterns

Kubernetes

Operations

Demo

Tools

@mjbright 48 / 56

Page 73: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

ToolsTools

Helm (use to install tools)PrometheusSquashGlooIstio / Service Meshes / Envoy

@mjbright 49 / 56

Page 74: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryGetting started with Micro-services

@mjbright 50 / 56

Page 75: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryGetting started with Micro-services

If migrating monolith, take small steps

@mjbright 50 / 56

Page 76: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryGetting started with Micro-services

If migrating monolith, take small steps

Secure your services behind firewall/API gw

@mjbright 50 / 56

Page 77: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryGetting started with Micro-services

If migrating monolith, take small steps

Secure your services behind firewall/API gw

Services must use public APIs only

@mjbright 50 / 56

Page 78: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryGetting started with Micro-services

If migrating monolith, take small steps

Secure your services behind firewall/API gw

Services must use public APIs only

Choose "best" technology for each component

@mjbright 50 / 56

Page 79: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryGetting started with Micro-services

If migrating monolith, take small steps

Secure your services behind firewall/API gw

Services must use public APIs only

Choose "best" technology for each component

Transform technology and your organization

@mjbright 50 / 56

Page 80: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryGetting started with Micro-services

If migrating monolith, take small steps

Secure your services behind firewall/API gw

Services must use public APIs only

Choose "best" technology for each component

Transform technology and your organization

Automate, automate, automate ...

@mjbright 50 / 56

Page 81: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryGetting started with Kubernetes

@mjbright 51 / 56

Page 82: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryGetting started with Kubernetes

Start by learning Docker principles

@mjbright 51 / 56

Page 83: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryGetting started with Kubernetes

Start by learning Docker principles

Experiment by Dockerizing some applications

@mjbright 51 / 56

Page 84: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryGetting started with Kubernetes

Start by learning Docker principles

Experiment by Dockerizing some applications

Learn about Container Orchestration

@mjbright 51 / 56

Page 85: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryGetting started with Kubernetes

Start by learning Docker principles

Experiment by Dockerizing some applications

Learn about Container Orchestration

Hands-on with Kubernetes online or Minikube(*)

@mjbright 51 / 56

Page 86: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryMicro-services offer new deployment

possibilities

@mjbright 52 / 56

Page 87: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryMicro-services offer new deployment

possibilities

- ease of deployment

@mjbright 52 / 56

Page 88: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryMicro-services offer new deployment

possibilities

- ease of deployment

- ease of scaling

@mjbright 52 / 56

Page 89: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryMicro-services offer new deployment

possibilities

- ease of deployment

- ease of scaling

- ease of upgrades

@mjbright 52 / 56

Page 90: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryMicro-services offer new deployment

possibilities

- ease of deployment

- ease of scaling

- ease of upgrades

- "Best in Class" polyglot implementation

@mjbright 52 / 56

Page 91: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryMicro-services offer new deployment

possibilities

- ease of deployment

- ease of scaling

- ease of upgrades

- "Best in Class" polyglot implementation

Hybrid approaches will be adopted

@mjbright 52 / 56

Page 92: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

SummaryMicro-services offer new deployment

possibilities

- ease of deployment

- ease of scaling

- ease of upgrades

- "Best in Class" polyglot implementation

Hybrid approaches will be adopted

- combining container-based micro-services, VMs, Serverless ...

@mjbrightSlides & source code at https://mjbright.github.io/Talks 52 / 56

Page 93: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Thank you !

Questions ?Michael Bright, @mjbright

linkedin.com/in/mjbright github.com/mjbright

Training classes available

Slides & source code at https://mjbright.github.io/Talks 53 / 56

Page 94: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Resources

Download https://github.com/kubernetes/minikube/releases

Documentation https://kubernetes.io/docs/getting-started-guides/minikube/

Hello Minikubehttps://kubernetes.io/docs/tutorials/stateless-application/hello-minikube/

@mjbrightSlides & source code at https://mjbright.github.io/Talks 54 / 56

Page 95: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Resources - ArticlesMartin Fowler https://martinfowler.com/articles/microservices.html

MuleSoft, "The top 6Microservices Patterns"

https://www.mulesoft.com/lp/whitepaper/api/top-microservices-patterns

FullStack Python https://www.fullstackpython.com/microservices.html

Idit Levinehttps://medium.com/solo-io/building-hybrid-apps-with-gloo-1eb96579b070

SSolahttps://medium.com/@ssola/building-microservices-with-python-part-i-5240a8dcc2fb

Deploymenthttp://container-solutions.com/kubernetes-deployment-strategies/

@mjbrightSlides & source code at https://mjbright.github.io/Talks 55 / 56

Page 96: Developing Micro-services with Kubernetes 24 April 2018 ... · Developing Micro-services with Kubernetes 24 April 2018, CodeEurope.pl Michael Bright, ... CI/CD Documentation of interfaces/APIs

Resources - BooksPublisher Title, Author

O'Reilly"Building Microservices", Sam Newman,July 2015

PacktPub"Python Microservices Development",Tarek Ziade, July 2017

@mjbrightSlides & source code at https://mjbright.github.io/Talks 56 / 56