Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
N

nacos-k8s

> 编程语言
Open source

This project contains a Nacos Docker image meant to facilitate the deployment of Nacos on Kubernetes using StatefulSets.

685 stars0 likes1 views
WebsiteGitHub

About

This project contains a Nacos Docker image meant to facilitate the deployment of Nacos on Kubernetes using StatefulSets.

Kubernetes Nacos

This project contains a Nacos Docker image meant to facilitate the deployment of Nacos on Kubernetes via StatefulSets.

中文文档

Tips

If you are using Nacos version 1.1.4 or lower, please refer to this Tag

It is recommended to deploy Nacos in Kubernetes using Nacos Operator.

Quick Start

  • Clone Project
bash
git clone https://github.com/nacos-group/nacos-k8s.git
  • Simple Start

If you want to start Nacos without NFS, but emptyDirs will possibly result in a loss of data. as follows:

bash
cd nacos-k8s
chmod +x quick-startup.sh
./quick-startup.sh
  • Testing

    • Service registration
    powershell
    curl -X POST 'http://cluster-ip:8848/nacos/v2/ns/instance?serviceName=nacos.naming.serviceName&ip=20.18.7.10&port=8080'
    • Service discovery
    powershell
    curl -X GET 'http://cluster-ip:8848/nacos/v2/ns/instance/list?serviceName=nacos.naming.serviceName'
    • Publish config
    powershell
    curl -X POST "http://cluster-ip:8848/nacos/v2/cs/config?dataId=nacos.cfg.dataId&group=test&content=helloWorld"
    • Get config
    powershell
    curl -X GET "http://cluster-ip:8848/nacos/v2/cs/config?dataId=nacos.cfg.dataId&group=test"

Advanced

Tips

If you use a custom database, please initialize the database script yourself first.

In advanced use, the cluster is automatically scaled and data is persisted, but PersistentVolumeClaims must be deployed. In this example, NFS is used.

⚠️ Deprecation Notice: The NFS, Ceph, and OpenShift deployment methods below are deprecated and no longer actively maintained. They rely on archived upstream projects (kubernetes-incubator/external-storage) and outdated APIs. Please use the Helm chart instead, which supports persistent storage via any StorageClass (including NFS CSI and Rook-Ceph) with persistence.enabled=true.

Deploy NFS

  • Create Role
bash
kubectl create -f deploy/nfs/rbac.yaml

If your K8S namespace is not default, execute the following script before creating RBAC

bash
# Set the subject of the RBAC objects to the current namespace where the provisioner is being deployed
$ NS=$(kubectl config get-contexts|grep -e "^\*" |awk '{print $5}')
$ NAMESPACE=${NS:-default}
$ sed -i "s/namespace:.*/namespace: $NAMESPACE/g" ./deploy/nfs/rbac.yaml
  • Create ServiceAccount And deploy NFS-Client Provisioner
bash
kubectl create -f deploy/nfs/deployment.yaml
  • Create NFS StorageClass
bash
kubectl create -f deploy/nfs/class.yaml
  • Verify that NFS is working
bash
kubectl get pod -l app=nfs-client-provisioner

Deploy database

  • Deploy mysql
bash

cd nacos-k8s

kubectl create -f deploy/mysql/mysql-nfs.yaml
  • Verify that Database is working
bash

kubectl get pod 
NAME                         READY   STATUS    RESTARTS   AGE
mysql-gf2vd                        1/1     Running   0          111m

Deploy Nacos

  • Modify deploy/nacos/nacos-pvc-nfs.yaml
yaml
data:
  mysql.host: "db host"
  mysql.db.name: "db name"
  mysql.port: " db port"
  mysql.user: " db username"
  mysql.password: " db password"
  • Create Nacos
bash
kubectl create -f nacos-k8s/deploy/nacos/nacos-pvc-nfs.yaml
  • Verify that Nacos is working
bash
kubectl get pod -l app=nacos

NAME      READY   STATUS    RESTARTS   AGE
nacos-0   1/1     Running   0          19h
nacos-1   1/1     Running   0          19h
nacos-2   1/1     Running   0          19h

Scale Testing

  • Use kubectl exec to get the cluster config of the Pods in the nacos StatefulSet.
powershell
for i in 0 1; do echo nacos-$i; kubectl exec nacos-$i -- cat conf/cluster.conf; done

The StatefulSet controller provides each Pod with a unique hostname based on its ordinal index. The hostnames take the form of -. 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
bash
kubectl scale sts nacos --replicas=3
  • Use kubectl exec to get the cluster config of the Pods in the nacos StatefulSet after scale StatefulSets
bash
for i in 0 1 2; do echo nacos-$i; kubectl exec nacos-$i -- cat conf/cluster.conf; done

Prerequisites

  • Kubernetes Node configuration(for reference only)
Hostname Configuration
k8s-master CentOS Linux release 7.4.1708 (Core) Single-core processor Mem 4G Cloud disk 40G
node01 CentOS Linux release 7.4.1708 (Core) Single-core processor Mem 4G Cloud disk 40G
node02 CentOS Linux release 7.4.1708 (Core) Single-core processor Mem 4G Cloud disk 40G
  • Kubernetes version:1.19+
  • 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.db.name Y database name
mysql.port N database port
mysql.user Y database username
mysql.password Y database password
NACOS_DATASOURCE_PLATFORM Y Database type,The default is embedded database,parameters only support mysql or embedded. (Old name SPRING_DATASOURCE_PLATFORM is deprecated)
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 for Peer-finder plugin
NACOS_APPLICATION_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
Nfs:server Y NFS server address
Nfs:path Y NFS server shared path

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Go

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言