• Stars
    star
    595
  • Rank 74,799 (Top 2 %)
  • Language
    Go
  • Created almost 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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
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:

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

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

Advanced

Tips

If you use a custom database, please initialize the database script yourself first. https://github.com/alibaba/nacos/blob/develop/distribution/conf/mysql-schema.sql

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
kubectl create -f deploy/nfs/rbac.yaml

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

# 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
kubectl create -f deploy/nfs/deployment.yaml
  • Create NFS StorageClass
kubectl create -f deploy/nfs/class.yaml
  • Verify that NFS is working
kubectl get pod -l app=nfs-client-provisioner

Deploy database

  • Deploy mysql
cd nacos-k8s

kubectl create -f deploy/mysql/mysql-nfs.yaml
  • Verify that Database is working
kubectl get pod 
NAME                         READY   STATUS    RESTARTS   AGE
mysql-gf2vd                        1/1     Running   0          111m

Deploy Nacos

  • Modify deploy/nacos/nacos-pvc-nfs.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
kubectl create -f nacos-k8s/deploy/nacos/nacos-pvc-nfs.yaml
  • Verify that Nacos is working
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.
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 <statefulset name>-<ordinal index>. Because the replicas field of the nacos StatefulSet is set to 2, In the cluster file only two nacos address

k8s

  • Use kubectl to scale StatefulSets
kubectl scale sts nacos --replicas=3

scale

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

get_cluster_after

  • Use kubectl exec to get the state of the Pods in the nacos StatefulSet after scale StatefulSets
for i in 0 1 2; do echo nacos-$i; kubectl exec nacos-$i curl GET "http://localhost:8848/nacos/v1/ns/raft/state"; done

You can find that the new node has joined the cluster

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.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.db.name Y database name
mysql.port N database port
mysql.user Y database username
mysql.password Y database password
SPRING_DATASOURCE_PLATFORM Y Database type,The default is embedded database,parameters only support mysql or embedded
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

More Repositories

1

nacos-docker

This project contains a Docker image meant to facilitate the deployment of Nacos .
Shell
1,405
star
2

nacos-sdk-go

Nacos client in Golang
Go
1,119
star
3

nacos-examples

Nacos Examples
Java
953
star
4

r-nacos

Nacos server re-implemented in Rust.
Rust
812
star
5

nacos-spring-boot-project

Nacos ECO Project for Spring Boot
Java
785
star
6

nacos-spring-project

Nacos ECO Project for Spring Framework
Java
755
star
7

nacos-sdk-csharp

This nacos csharp sdk
C#
420
star
8

nacos-sdk-python

nacos python sdk
Python
362
star
9

nacos-sync

Service Sync component
Java
292
star
10

nacos-sdk-nodejs

nacos node.js sdk client
TypeScript
291
star
11

nacos-sdk-cpp

C++ client for Nacos
C++
125
star
12

nacos-sdk-rust

nacos client for rust
Rust
117
star
13

grpc-java-registry-nacos

gRPC Nacos registry integration
Java
97
star
14

nacos-group.github.io

nacos-group.github.io
MDX
97
star
15

nacos-plugin

A collection of Nacos plug-ins, providing Nacos with pluggable plug-in capabilities, support for user customization and high scalability
Java
91
star
16

nacos-coredns-plugin

Nacos DNS-F Client Based On CoreDNS
Go
83
star
17

nacos-template

nacos-template include PPT template and knote
70
star
18

nginx-nacos-upstream

nginx nacos module. subscribe service and configuration from nacos instead of modifying and reloading nginx.conf
C
61
star
19

nacos-confd

Go
40
star
20

nacos-istio

Nacos integrate with Istio as a MCP server
Go
38
star
21

nacos-controller

nacos k8s controller
Go
25
star
22

dubbo-registry-nacos

Dubbo Registry support for Nacos
14
star
23

nacos-k8s-sync

A component for sync services between Nacos and Kubernetes.
Go
12
star
24

nacos-sdk-lua

Lua
12
star
25

nacos-activity

The documents presented in nacos activities
11
star
26

nacos-sdk-php

PHP
11
star
27

nacos-ctl

The controller command sdk for nacos
Java
7
star
28

logback-adapter

Java
5
star
29

acm2nacos-spring-cloud-example

Java
4
star
30

nacos-tutorial

Nacos 知行实验仓库
2
star
31

acm2nacos-java-example

Java
2
star
32

apollo-2-nacos-migration

Apollo迁移到Nacos的脚本工程
Java
1
star
33

nacos-logo

The logo files for nacos
1
star