javadockerkubernetesgoogle-kubernetes-enginevitess

Connect java application to YouTube Vitess database


I deployed my java web application in kubernetes using DEPLOYMENTS and was able to scale it and connect it to a database POD, but then I wanted to scale the database too but as you know is not possible in kubernetes and the MYSQL REPLICA not recommended for production. So I tried vitess and was able to scale my database but don't know how or where should I create my java web application DEPLOYMENTS/REPLICAS and connect them to the database through vtgate. And is there another way of scaling mysql database through kubernetes ?


Solution

  • It's important to note that Vitess is not a transparent proxy that you can just insert between the app and MySQL at the connection level. Vitess turns a set of MySQL servers into a clustered database, and it requires you to build your app against a Vitess driver instead of the plain MySQL driver.

    If you're already using JDBC, you shouldn't need a lot of code changes other than connection management, since there is a Vitess implementation of the JDBC interface. However, some query constructs may not be supported yet by Vitess, so you may need to rewrite them into an equivalent form that is supported.

    Once your app is compatible with Vitess, deploying it in Kubernetes will be the same as you did before, except you will point the app pods to connect to the VTGate service via DNS.

    As for other ways to scale MySQL in Kubernetes without Vitess, there's an important new feature entering Beta in Kubernetes 1.5 called StatefulSet that will help you scale databases like MySQL similar to the way a Deployment can scale stateless Pods. Vitess itself will also become more convenient to scale in Kubernetes by taking advantage of StatefulSet.

    However, StatefulSet with pure MySQL will mostly only help you scale read-only traffic by increasing the number of slaves. If you need to scale write traffic, you will likely need to implement application-defined sharding. At that point, the required changes to your app will almost certainly be much more than if you modify it to support Vitess.