Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Distributed Caching in Kubernetes with Hazelcast

0 views

Published on

As Monolith to Microservices migration almost became mainstream, Engineering Teams have to think about how their caching strategies will evolve in cloud-native world. Kubernetes is clear winner in containerized world so caching solutions must be cloud-ready and natural fit for Kubernetes.

Caching is an important piece in high performance microservices and choosing right architectural pattern can be crucial for your deployments. Hazelcast is a well known caching solution in open source community and can handle caching piece in microservices based applications.

In this talk, you will learn
* Distributed Caching With Hazelcast
* Distributed Caching Patterns in Kubernetes
* Kubernetes Deployment Options and Best Practices
* How to Handle Distributed Caching Day 2 Operations

Published in: Technology

Distributed Caching in Kubernetes with Hazelcast

  1. 1. @mesutcelik Distributed Caching Patterns in Kubernetes Mesut Celik,Hazelcast
  2. 2. @mesutcelik Mesut Celik ● Tech Lead @Hazelcast ● Java Developer ● lived in Turkey,Belgium,US ● Twitter: @mesutcelik
  3. 3. @mesutcelik Agenda ● Hazelcast Introduction ● Caching Patterns ● Kubernetes Deployments ● Day 2 Operations
  4. 4. @mesutcelik Hazelcast Products ● Hazelcast IMDG ● Hazelcast Jet ● Hazelcast Cloud ● Management Center Hazelcast is an Open Source Company ● Apache 2 License ● Remote friendly ● raised $21M series C ● Always hiring!!!!
  5. 5. @mesutcelik Why Distributed Cache? ● Cache, Memory is faster than storage ● Distributed,Natural fit for Cloud-Native Deployments
  6. 6. @mesutcelik Cache Layers
  7. 7. @mesutcelik Caching Patterns
  8. 8. @mesutcelik Cache-aside Application DB Cache Application DB Cache Read-through, Write-through, Write-behind Caching Patterns Cache-as-SoR
  9. 9. @mesutcelik Read-Through Cache
  10. 10. @mesutcelik Read-Through Cache 1,MinskPartition_34 1,MinskBackup_34
  11. 11. @mesutcelik Hazelcast and Kubernetes Caching Patterns
  12. 12. @mesutcelik Distributed Caching Patterns in Kubernetes ● Embedded ● Sidecar ● Proxy Cache ● Client-Server
  13. 13. @mesutcelik POD Spring Boot Microservice Hazelcast Member POD Hazelcast ClusterKubernetesService Http Request Embedded Spring Boot Microservice Hazelcast Member Kubernetes Cluster
  14. 14. @mesutcelik Embedded ● Simple ● Java only ● Data co-located with Microservice JVM
  15. 15. @mesutcelik Python Microservice POD Hazelcast Member Python Microservice POD Hazelcast Member Hazelcast ClusterKubernetesService Http Request SideCar Kubernetes Cluster hazelcast-client hazelcast-client
  16. 16. @mesutcelik Sidecar ● Simple ● Multiple Programming Languages ○ Java, Node.js, .NET, Python, Golang ● Data co-located with Microservice POD
  17. 17. hazelcast-proxy sidecar POD Spring Boot Application POD Spring Boot Application Hazelcast ClusterKubernetesService Http Request Http reverse proxy caching Hazelcast Member hazelcast-proxy sidecar Hazelcast Member Kubernetes Cluster
  18. 18. Http reverse proxy caching ● Injecting Cache into every microservice ● No coupling with any Cache API ● Enabled w/o code change
  19. 19. @mesutcelik POD Spring Boot Microservice hazelcast-java-client Hazelcast ClusterKubernetesService Http Request Client Server POD Hazelcast Member POD Hazelcast Member Kubernetes Cluster POD Spring Boot Microservice hazelcast-java-client POD ASP.NET Core Microservice hazelcast-dotnet-client KubernetesService Http Request
  20. 20. @mesutcelik POD KubernetesService Http Request Hazelcast Cloud POD cloud.hazelcast.com Hazelcast Cluster Kubernetes Cluster Spring Boot Application hazelcast-client Spring Boot Application hazelcast-client
  21. 21. @mesutcelik Client Server ● CaaS - Cache as a Service ● Multiple Programming Languages ○ Java, nodejs, .NET, Python, Golang ● Separate Microservice and Hazelcast Layers
  22. 22. @mesutcelik Spring Boot - Hazelcast Embedded Config @Bean public Config hazelcastConfig() { Config config = new Config(); JoinConfig joinConfig = config.getNetworkConfig().getJoin(); joinConfig.getMulticastConfig().setEnabled(false); joinConfig.getKubernetesConfig().setEnabled(true); return config; }
  23. 23. @mesutcelik Spring Boot - Hazelcast Client Config @Bean public ClientConfig hazelcastConfig() { ClientConfig config = new ClientConfig(); config.getNetworkConfig().getKubernetesConfig().setEnabled(true); return config; }
  24. 24. @mesutcelik Hazelcast Cache Put and Get Operations @Autowired HazelcastInstance hazelcast; Map<String, String> cities = hazelcast.getMap("cities"); cities.put("1","Minsk"); System.out.println("Best City in the world is " + cities.get("1"));
  25. 25. @mesutcelik Kubernetes Deployment Options For Hazelcast
  26. 26. @mesutcelik Hazelcast Helm Chart $ helm install stable/hazelcast
  27. 27. @mesutcelik Hazelcast Kubernetes Operator ● OperatorHub.io ● Openshift 4 Operator Catalog ● IBM Cloud Private
  28. 28. @mesutcelik Hazelcast Cloud ● Managed Service ● Pay as you go model ● https://cloud.hazelcast.com
  29. 29. @mesutcelik Deployment Best Practices
  30. 30. @mesutcelik Predictable Resource Allocation ● Calculate CPU/Memory Requirements ● Set Resource Request and Limits as the same value
  31. 31. @mesutcelik Pod Anti-Affinity ● Hazelcast per K8S Node ● Large Kubernetes Clusters ● Safer in Node crushes
  32. 32. @mesutcelik Multi-zone Deployment with ZONE_AWARE hazelcast-member -1 hazelcast-member -2 hazelcast-member -3 Availability-Zone-A hazelcast-member -4 hazelcast-member -5 hazelcast-member -6 Availability-Zone-B Multi-zone Hazelcast Cluster * Multi-zone if your architecture prefers availability over performance
  33. 33. @mesutcelik Day 2 Operations
  34. 34. @mesutcelik Scaling Hazelcast Cluster ● Manual Scaling (kubectl scale or helm upgrade) ● Horizontal Pod Autoscaler (HPA) ● Vertical Pod Autoscaler ● Cluster Autoscaler
  35. 35. @mesutcelik Rolling Upgrade - Why? ● Hazelcast Version Update ● Config Change ● Adding Jar to the classpath
  36. 36. @mesutcelik Rolling Upgrade - How? ● helm upgrade (--set image.tag) ● kubectl set image ● StatefulSet ● Deployment with RollingUpdateStrategy ● Enable Graceful Shutdown ● Optimized Grace Period
  37. 37. @mesutcelik Monitoring ● Hazelcast Management Center ● Metrics via Prometheus ● Alerting
  38. 38. @mesutcelik Thank you! ● https://twitter.com/mesutcelik ● https://github.com/mesutcelik ● https://www.linkedin.com/in/mesutcelik/

×