Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Ultimate Guide to Microservice Architecture on Kubernetes

Nächste SlideShare
Azure dev ops_demo
Azure dev ops_demo
Wird geladen in …3

Hier ansehen

1 von 107 Anzeige

Weitere Verwandte Inhalte

Diashows für Sie (20)

Ähnlich wie Ultimate Guide to Microservice Architecture on Kubernetes (20)


Weitere von kloia (20)

Aktuellste (20)


Ultimate Guide to Microservice Architecture on Kubernetes

  1. 1. Ultimate Guide to Microservice Architecture on Kubernetes Huseyin BABAL Software & DevOps Consultant
  2. 2. Who Am I? Software & DevOps Consultant Ex-Sony and Ex-eBay Engineer (Microservice Transformation Project Architect) Google Developer Expert on Web Technologies Organizer of Docker Istanbul, NodeSchool Istanbul, DevOps Underground meetups
  3. 3. Who we are ? ● Microservice Transition ● DevOps as A Service ● Test Automation as A Service ● Managed Kubernetes
  4. 4. Who we are ?
  5. 5. Customers
  6. 6. Ready to Start ?
  7. 7. Once upon a time while we are in monolithic app days
  8. 8. After switching to Microservice Architecture ...
  9. 9. And yes, the truth is, only the name Microservice Architecture cannot solve your architectural problems. You need to consider applying best practices to Microservices to do it in an efficient way
  10. 10. #1 Try to Reach Glory of REST
  11. 11. Leonard Richardson’s Maturity Model
  12. 12. #2 Use HATEOAS
  13. 13. HATEOAS Hypermedia As The Engine Of Application State
  14. 14. User Model
  15. 15. Article Model
  16. 16. Article Resource
  17. 17. User Resource
  18. 18. Article Controller
  19. 19. User Controller
  20. 20. The Result
  21. 21. Pro Tip If you don’t want to convert models/dtos to resources manually, you can use Resource Assembler.
  22. 22. #3 Distributed Configuration
  23. 23. Why Not Project Specific Configs? ● Sensitive data walks around Git ● Unable to inherit common properties like spring.main.banner-mode=OFF
  24. 24. How to Centralized Config? ● Consul can be used to keep config data as Key/Value ● Create a project for just keeping project configurations. ● Git2Consul for sync configuration to Consul
  25. 25. Architecture Git2Consull Daemon Config Project Git push new config change Polling Sync configs to Consul User
  26. 26. Spring Boot Config
  27. 27. Spring Boot Config (Test)
  28. 28. Git2Consul npm install -g git2consul Create a file called git2consul.json and add necessary config git2consul --endpoint <consul_host> --port 8500 --config-file git2consul.json
  29. 29. Git2Consul Config File
  30. 30. Pro Tip By default, Spring Boot refreshes its context on config change on Consul. This may cause down time problems, so disable config change watching with following.
  31. 31. #4 Client Code Generation
  32. 32. How? You can either use Swagger to generate your client code on any supported language, or feign client with a little annotation and client side load balancing with Ribbon.
  33. 33. Feign Client
  34. 34. Swagger Doc
  35. 35. Swagger Doc Now you are able to access; http://your_api/swagger-ui.html for api documentation http://your_api/v2/api-docs for json specification of API doc.
  36. 36. Swagger Codegen
  37. 37. Pro Tip The best place to generate api client is while Jenkins build section. ● If you are deploying a feature to non-prod environment you can generate client library with snapshot version and push to nexus. ● If you are deploying a feature to prod environment, you can generate client with stable and push to nexus artifactory
  38. 38. #5 k8s Warm-up
  39. 39. Project Structure
  40. 40. deployment.yml
  41. 41. service.yml
  42. 42. Kubectl configuration Kubectl is a client app for k8s api server in order to manage k8s cluster. If you use minikube, your kubectl will be automatically configured, and it is different for other cloud providers.
  43. 43. Simple deployment git clone <http://project> cd <project> kubectl apply -f k8s
  44. 44. Event Service (LB) Pod-1 Pod-2 Pod-3 Internet
  45. 45. #6 CI / CD
  46. 46. Build Test Deploy Cloud Provider
  47. 47. Slack Notifications
  48. 48. Deployment Script
  49. 49. Deployment Types ● Rolling Update ● Canary Deployment ● Blue / Green Deployment
  50. 50. Rolling Update Deployment resource on k8s uses RollingUpdate strategy by default. Within this strategy, pods deployed one by one instead of taking entire service down.
  51. 51. Canary Deployment You deploy an experimental feature and allow small amount of request traffic to this deployment. You increment the size of traffic and after a while, canary replaces the production one
  52. 52. After a while... You confirmed that, the feature on canary deployment works, replace prod image with canary one and delete canary deployment
  53. 53. Blue & Green Deployment In this strategy, there will be 2 environments with same properties except application version. The current version will be called blue and new version will be green. Just update ingress rules to redirect traffic to green deployment.
  54. 54. #7 Monitoring
  55. 55. Monitor Everything
  56. 56. Prometheus Prometheus is capable of collecting metrics from known sources like cAdvisor. Prometheus is mainly used for collecting metrics and alert manager to notify you on any kind of problem
  57. 57. Prometheus Operator Hopefully, CoreOS team developed a project called prometheus operator to collect k8s specific metrics automatically. https://github.com/coreos/prometheus-operator
  58. 58. Getting Started You can install Prometheus with Helm charts
  59. 59. Visualization Prometheus lets us to keep track of external services by using some endpoint via exporters. To visualize metrics, we will use grafana.
  60. 60. Alert Manager
  61. 61. #8 Logging
  62. 62. Spring Boot Logging
  63. 63. Logging Types ● Node Level Logging ● Cluster Level Logging
  64. 64. Node Level Logging
  65. 65. Cluster-Level Logging
  66. 66. You can use several technology to send your logs to logging backend. It can be Graylog, ELK, etc...
  67. 67. logz.io
  68. 68. Kubernetes Setup You can run a daemonset to send your logs to logz.io as stated here: https://github.com/DanielBerman/k8s_logging_files/blob/master/logging_logz/daemons et-logz.yaml
  69. 69. #9 APM & Service Mesh
  70. 70. Why to Monitor Service Metrics? Beautiful graphs and dashboard fetched from log resources may not be helpful for you every time when you face a difficult issue. You may need to see your service insights to find the root cause.
  71. 71. Tools Can Be Used NewRelic, AppDynamics, DynaTrace, Zipkin can be suggestion for your APM monitoring. However, in a containerized microservices world, you may need to have a tool that works in real-time and has some AI capabilities.
  72. 72. Instana Instana is an AI Powered Application and Infrastructure Monitoring
  73. 73. #10 API GATEWAY
  74. 74. Microservice Patterns? In most cases, we have foundation services to access data, and aggregation layer to aggregate data to serve specific clients. According to my experience, you can handle microservice division in two ways. (There are many more, but those two are general)
  75. 75. Aggregation Layer Service 1 Service 2 Service 3 DB 1 DB 2 DB 3 Cache 1 Cache 1 Cache 1 Aggregation Service Load Balancer
  76. 76. Aggregation Layer When client wants to get data that contains data from multiple services, it consults to endpoint on aggregation layer. GET /users/1 User Response = Data(Service1) + Data(Service2) + Data(Service3)
  77. 77. Proxy Pattern In this pattern, you can use API Gateway to proxy requests to downstream microservices. Kong, and Tyk are the more popular options for API Gateway
  78. 78. Service 2 Service 1 Service 3 Service 5 Service 6 Service 4 Service 7 Load Balancer
  79. 79. ● Proxy ~3000 req/sec with 65 ms latency ● Proxy ~2000 rew/sec with 85ms latency including key validation, security check, quota management ● 2-Core 2GB Virtual Server
  80. 80. #11 Event Sourcing & CQRS
  81. 81. CRUD Nature In services, we always try to change a state of a resource at one time in one transaction. When more instance needed, we started to use distributed transactions by applying 2- Phase-Commit protocol in Extended Architecture (a.k.a XA). Whenever you do a change current state of an entity, old transaction logs gone.
  82. 82. Event Sourcing Instead of saving current state of entity, save state-changing events belongs to entity in a time series format You can replay events within event store, even you can reproduce a bug if exists on your production! There is no update to past state of an entity, instead of use an updated event entity in new row.
  83. 83. Product Events Product(‘Computer’, 1000 USD) Product(‘Laptop’, 1000 USD) Product(‘Laptop’, 900 USD) ProductMetadataUpdateEvent ProductPriceUpdateEvent
  84. 84. How? You can use Apache Kafka, Cassandra, etc … to keep you revents to make them available to any kind of consumer. Just save event on any action for example user creation, but you don’t have to return response immediately. Event handlers, handle event to populate their views to make available to query
  85. 85. CQRS Command and Query Responsibility Segregation A Command alters the state of an object, but does not returns data A Query returns data, but does not alter state of object
  86. 86. Product Service Create Product Update Product Delete Product ProductCreateHandler Topic per Event Or Topic per Object and event type in log Apache Kafka Database APIGATEWAY Create Product Request Read Product Request
  87. 87. Frameworks
  88. 88. Thank You http://bit.ly/huseyinbabal http://bit.ly/kloia-daas http://bit.ly/k8s-microservice