Slide 1

Slide 1 text

© 2022 Fujitsu Limited Kenji Kazumura @kkzr 2022.10.26 Make Scalable MicroProfile Application

Slide 2

Slide 2 text

Agenda © 2022 Fujitsu Limited Cloud Native and Scalability Kubernetes AutoScaler MicorProfile Metrics K8S HPA with MicroProfile Metrics Wrap Up 2

Slide 3

Slide 3 text

Who Am I © 2022 Fujitsu Limited Work for Fujitsu • FUJITSU Software Enterprise Application Platform • Launcher Member of Jakarta EE SC Member of JCP Executive Committee Board of Director of Eclipse Foundation 3

Slide 4

Slide 4 text

Agenda © 2022 Fujitsu Limited Cloud Native and Scalability Kubernetes AutoScaler MicorProfile Metrics K8S HPA with MicroProfile Metrics Wrap Up 4

Slide 5

Slide 5 text

Cloud Native (CNCF definition) © 2022 Fujitsu Limited https://github.com/cncf/toc/blob/master/DEFINITION.md Cloud native technologies empower organizations to build and run scalable applications in modern, dynamic environments such as public, private, and hybrid clouds. Containers, service meshes, microservices, immutable infrastructure, and declarative APIs exemplify this approach. 5

Slide 6

Slide 6 text

Jevons Paradox © 2022 Fujitsu Limited https://upload.wikimedia.org/wikipedia/commons/b/b8/Jev onsParadoxA.png technological improvements that increased the efficiency of coal-use led to the increased consumption of coal in a wide range of industries -- Wikipedia https://en.wikipedia.org/wiki/Jevons_paradox 6

Slide 7

Slide 7 text

Step Define thresholds of metrics (When do you want to scale?) General Steps to scale © 2022 Fujitsu Limited Step (if needed) Export metrics (e.g. CPU usage, Memory usage, …) Step Monitor metrics Step Scale your VMs, Containers, Applications 7

Slide 8

Slide 8 text

Step Define thresholds of metrics (When do you want to scale?) General Steps to scale © 2022 Fujitsu Limited Step (if needed) Export metrics (e.g. CPU usage, Memory usage, …) Step Monitor metrics Step Scale your VMs, Containers, Applications 8 Step3 and Step4 are usually required to be automated. Nobody wants to monitor metrics with your own eyes. Nobody wants to scale manually.

Slide 9

Slide 9 text

Agenda © 2022 Fujitsu Limited Cloud Native and Scalability Kubernetes AutoScaler MicorProfile Metrics K8S HPA with MicroProfile Metrics Wrap Up 9

Slide 10

Slide 10 text

Kubernetes Kubernetes is a de fact standard container orchestration tool You can use it in your own infrastructures It is also available as managed service provided by cloud vendors Kubernetes provides automatic scaling methods © 2022 Fujitsu Limited 10

Slide 11

Slide 11 text

Step Define thresholds Steps to scale with Kubernetes © 2022 Fujitsu Limited Step Export metrics Step Monitor metrics Step Scale containers You need to do Kubernetes takes care of Kubernetes takes care of Kubernetes takes care of Iff you use only Node/Pod information e.g. CPU , Memory 11

Slide 12

Slide 12 text

Types of Scalability © 2022 Fujitsu Limited Pod CPU/Core Memory # of Pods Pod Pod Vertical Scale Horizontal Scale 12

Slide 13

Slide 13 text

Kubernetes Pod AutoScaler Vertical Pod AutoScaler (VPA) •need not consider special application design •less reliability Horizontal Pod AutoScaler (HPA) •need design your application to work with multi instances •easy to scale © 2022 Fujitsu Limited 13

Slide 14

Slide 14 text

HPA System Diagram © 2022 Fujitsu Limited Horizontal Pod AutoScaler poll /apis/metrics.k8s.io/v1beta1 Metrics API API Server Metrics Server push Pod poll 14

Slide 15

Slide 15 text

Agenda © 2022 Fujitsu Limited Cloud Native and Scalability Kubernetes AutoScaler MicorProfile Metrics K8S HPA with MicroProfile Metrics Wrap Up 15

Slide 16

Slide 16 text

Export monitoring data (aka Telemetry) • Access metrics endpoints (e.g. http://example.com/metrics) 3 types of metrics • Base metrics • Application metrics • Vendor Specific metrics Provide Java APIs • Programmers can export their data by API Will be integrate into MicroProfile OpenTelemtry ? MicroProfile Metrics © 2022 Fujitsu Limited https://download.eclipse.org/microprofile/microprofile-metrics-4.0/microprofile-metrics-spec-4.0.html 16

Slide 17

Slide 17 text

Code Example © 2022 Fujitsu Limited import org.eclipse.microprofile.metrics.Counter; import org.eclipse.microprofile.metrics.annotation.Metric; @Path(“eclipsecon") @RequestScoped public class LoginService { @Inject @Metric(name="LoginCounter", absolute=true) Counter counter; 17

Slide 18

Slide 18 text

Code Example © 2022 Fujitsu Limited @GET @Path("login") public String increment() { counter.inc(); return "number of login is " + counter.getCount() + "¥n"; } @GET @Path("logout") public String decrement() { if (counter.getCount() > 0) counter.inc(-1); return "number of login is " + counter.getCount() + "¥n"; } 18

Slide 19

Slide 19 text

Demo © 2022 Fujitsu Limited https://microprofile.io/compatible/5-0/ Access MP Metrics endpoint Use Launcher • MicroProfile 5.0 implementation • https://github.com/fujitsu/launcer 19

Slide 20

Slide 20 text

Agenda © 2022 Fujitsu Limited Cloud Native and Scalability Kubernetes AutoScaler MicorProfile Metrics K8S HPA with MicroProfile Metrics Wrap Up 20

Slide 21

Slide 21 text

HPA scenarios © 2022 Fujitsu Limited login do some work monitor CPU/memory usage scale login do some work monitor # of login users scale Use default API and Metrics server Use external API and MP Metrics 21

Slide 22

Slide 22 text

HPA /w MP Metrics © 2022 Fujitsu Limited Horizontal Pod AutoScaler poll /apis/external.metrics.k8s.io/v1beta1 External Metrics API API Server push Pod poll Prometheus Server Prometheus Adapter poll 22

Slide 23

Slide 23 text

Step • create your application pod and deployment of K8S • set Prometheus scraping information Steps to build HPA systems © 2022 Fujitsu Limited Step • create external API for your MP application metric using Prometheus Adapter Step • set HPA configuration # of replicas, metrics name, target threshold, and so on 23

Slide 24

Slide 24 text

Demo (before scale out) © 2022 Fujitsu Limited ・・・ Login Application (K8S cluster) Total # of Logins Pod #2 Pod #1 counter compare threshold (when scale?) http counter HPA 24

Slide 25

Slide 25 text

Demo (after scale out) © 2022 Fujitsu Limited ・・・ Login Application (K8S cluster) Total # of Logins Pod #2 Pod #1 counter compare threshold (when scale?) Pod #3 add extra pod http counter counter HPA 25

Slide 26

Slide 26 text

Agenda © 2022 Fujitsu Limited Cloud Native and Scalability Kubernetes AutoScaler MicorProfile Metrics K8S HPA with MicroProfile Metrics Wrap Up 26

Slide 27

Slide 27 text

⚫ Scalability is one of important keys of Cloud Native applications ⚫ Kubernets provides scaling mechanism • pods and nodes metrics can be used as default • but they are not always enough ⚫ MP Metrics provides standard way to handle metrics ⚫ Collaboration of K8S and MP Metrics produces values • flexible scalability according to application metrics • easy to scale your MP applications Wrap Up © 2022 Fujitsu Limited 27

Slide 28

Slide 28 text

© 2022 Fujitsu Limited 28

Slide 29

Slide 29 text

Thank you © 2022 Fujitsu Limited