Kubernetes Nacos
This project contains a Nacos Docker image meant to facilitate the deployment of Nacos on Kubernetes via StatefulSets.
Quick Start
- Clone Project
- Simple Start
If you want to start Nacos without NFS, but emptyDirs will possibly result in a loss of data. as follows:
-
Testing
- Service registration
- Service discovery
- Publish config
- Get config
Advanced
In advanced use, the cluster is automatically scaled and data is persisted, but PersistentVolumeClaims must be deployed. In this example, NFS is used.
Deploy NFS
- Create Role
If your K8S namespace is not default, execute the following script before creating RBAC
- Create
ServiceAccount
And deployNFS-Client Provisioner
- Create NFS StorageClass
- Verify that NFS is working
Deploy database
- Deploy master
- Deploy slave
- Verify that Database is working
Deploy Nacos
- Modify deploy/nacos/nacos-pvc-nfs.yaml
- Create Nacos
- Verify that Nacos is working
Scale Testing
- Use
kubectl exec
to get the cluster config of the Pods in thenacos
StatefulSet.
The StatefulSet controller provides each Pod with a unique hostname based on its ordinal index. The hostnames take the form of <statefulset name>-<ordinal index>
. Because the replicas
field of the nacos
StatefulSet is set to 2
, In the cluster file only two nacos address
- Use kubectl to scale StatefulSets
- Use
kubectl exec
to get the cluster config of the Pods in thenacos
StatefulSet after scale StatefulSets
- Use
kubectl exec
to get the state of the Pods in thenacos
StatefulSet after scale StatefulSets
You can find that the new node has joined the cluster
Prerequisites
- Kubernetes Node configuration(for reference only)
Network IP | Hostname | Configuration |
---|---|---|
172.17.79.3 | k8s-master | CentOS Linux release 7.4.1708 (Core) Single-core processor Mem 4G Cloud disk 40G |
172.17.79.4 | node01 | CentOS Linux release 7.4.1708 (Core) Single-core processor Mem 4G Cloud disk 40G |
172.17.79.5 | node02 | CentOS Linux release 7.4.1708 (Core) Single-core processor Mem 4G Cloud disk 40G |
- Kubernetes version:1.12.2+
- NFS version:4.1+
Limitations
- Persistent Volumes must be used. emptyDirs will possibly result in a loss of data
Project directory
Directory Name | Description |
---|---|
plugin | Help Nacos cluster achieve automatic scaling in K8s |
deploy | Deploy the required files |
Configuration properties
- nacos-pvc-nfs.yaml or nacos-quick-start.yaml
Name | Required | Description |
---|---|---|
mysql.master.db.name | Y | Master database name |
mysql.master.port | N | Master database port |
mysql.slave.port | N | Slave database port |
mysql.master.user | Y | Master database username |
mysql.master.password | Y | Master database password |
NACOS_REPLICAS | Y | The number of clusters must be consistent with the value of the replicas attribute |
NACOS_SERVER_PORT | N | Nacos port,default:8848 |
PREFER_HOST_MODE | Y | Enable Nacos cluster node domain name support |
- nfs deployment.yaml
Name | Required | Description |
---|---|---|
NFS_SERVER | Y | NFS server address |
NFS_PATH | Y | NFS server shared directory |
server | Y | NFS server address |
path | Y | NFS server shared directory |
- mysql yaml
Name | Required | Description |
---|---|---|
MYSQL_ROOT_PASSWORD | N | Root password |
MYSQL_DATABASE | Y | Database Name |
MYSQL_USER | Y | Database Username |
MYSQL_PASSWORD | Y | Database Password |
MYSQL_REPLICATION_USER | Y | Master-slave replication username |
MYSQL_REPLICATION_PASSWORD | Y | Master-slave replication password |
Nfs:server | Y | NFS server address |
Nfs:path | Y | NFS server shared path |