Deploy Nacos on a Kubernetes cluster

Deploy Nacos on a Kubernetes cluster

Recently, a demo was given on how to deploy a Nacos service on K8s. In this article, we’ll provide more context on the demo. Hopefully, it will be helpful when you are trying it out.

Nacos

Nacos is an open source project offered by Alibaba. It supports two major use cases, namely, service registry and config service. Even though Nacos is written in Java, it is designed to be a general purpose service registry and config server.

To use Nacos on K8s, it doesn’t necessarily have to be deployed in the same cluster with your application. However, for the convenience of the demo, we would recommend that. In this example, we are showing Nacos being deployed on K8s as StatefulSets.

To access the service after it has been deployed, you might use an SDK or REST API. There are Java and Golang SDKs available for now. As for this demo, we’ll use the REST API to access the service.

Verify the deployment

We’ll use curl to access the REST APIs provided by the Nacos service.

  • Service registry
curl -X PUT 'http://cluster-ip:8848/nacos/v1/ns/instance?.naming.serviceName&.18.7.10&'

 

  • Service discovery
curl -X GET 'http://cluster-ip:8848/nacos/v1/ns/instances?.naming.serviceName'
  • Write configuration
curl -X POST "http://cluster-ip:8848/nacos/v1/cs/configs?.cfg.dataId&&"
  • Read configuration
curl -X GET "http://cluster-ip:8848/nacos/v1/cs/configs?.cfg.dataId&"

Nacos Cluster

Yes, Nacos has a cluster. That’s why instead of a normal deployment, it is using StatefulSets. StatefulSets will guarantee the order of each pod joining and leaving the cluster. This way we can maintain the order of the Nacos cluster.

Following the demo, we see a section of scaling the cluster. This is a good exercise that will help users understand how the cluster works.

MySQL

In this demo, all the data from Nacos is persisted to a MySQL database. And the database is using NFS as persistent volume.  There is also a simple version where it’s using a local MySQL version but that should not be used in production.

When deploying MySQL we are using ReplicationController, which will make sure that certain numbers of replicas will be running all the time. This way we can be sure the database and the NFS volume is always ready.

Summary

Nacos has different modes of deployment. It can be deployed in Spring Cloud or Spring boot. It can also be deployed with Dubbo. And this demo is showcasing how to deploy it K8s. If you have further questions, please go to the git repo of the demo and raise issues there.

from DZone Cloud Zone

Sharing is caring!

Comments are closed.