We are accessing shared database from multiple pods in kubernetes. All the pods may writes/updates and reads from the db. How to handle data integrity in this case ? Is JPA isolation levels are enough for handling this or need to go with pessimistic locking ? Can you also help me with the difference between both ?
Your question has nothing to do with Kubernets. This simply concurrent database access that you'll get if more than one connection is accessing your database.
If you want to avoid problems like lost update then you need locking.
There are two types of locking.
Optimistic is handled by Hibernate with a version field. Pessimistic is the locking mechanism of the database.
You should also read Hibernates documentation about Locking. https://docs.jboss.org/hibernate/orm/5.5/userguide/html_single/Hibernate_User_Guide.html#locking