Giter Club home page Giter Club logo

nacos-controller's Introduction

Nacos Controller

This project includes a series of Kubernetes custom resources (CustomResourceDefinition) and their related controller implementations. The current version defines CRDs as follows:

  • DynamicConfiguration: Synchronization bridge between Nacos configuration and Kubernetes configuration.

中文文档

Quick Start

Deploy Nacos Controller

  1. Install helm,see document
  2. Install Nacos Controller
git clone https://github.com/nacos-group/nacos-controller.git
cd nacos-controller/charts/nacos-controller

export KUBECONFIG=/path/to/your/kubeconfig/file
kubectl create ns nacos
helm install -n nacos nacos-controller .

Sync configuration from Kubernetes to Nacos Server

  1. a Secret contains authorization information of nacos server, which is ak and sk
  2. a ConfigMap contains dataIds and their content
  3. a DynamicConfiguration, which defines the behaviour of synchronization
    • spec.dataIds:defines which dataIds should be synced
    • spec.nacosServer:defines the information of nacos server
    • spec.strategy:defines the strategy of synchronization
    • spec.objectRef:reference of object which contains dataIds and their content
apiVersion: nacos.io/v1
kind: DynamicConfiguration
metadata:
    name: dc-demo-cluster2server
spec:
  dataIds:
  - data-id1.properties
  - data-id2.yml
  nacosServer:
    endpoint: <your-nacos-server-endpoint>
    namespace: <your-nacos-namespace-id>
    group: <your-nacos-group>
    authRef:
      apiVersion: v1
      kind: Secret
      name: nacos-auth
  strategy:
    syncPolicy: Always
    syncDirection: cluster2server
    syncDeletion: true
  objectRef:
    apiVersion: v1
    kind: ConfigMap
    name: nacos-config-cm

---
apiVersion: v1
kind: ConfigMap
metadata:
    name: nacos-config-cm
    namespace: default
data:
    data-id1.properties: |
      key=value
      key2=value2
    data-id2.yml: |
      app:
        name: test

---
apiVersion: v1
kind: Secret
metadata:
    name: nacos-auth
data:
    ak: <base64 ak>
    sk: <base64 sk>

Sync configuration from Nacos Server to Kubernetes

  1. a Secret contains authorization information of nacos server, which is ak and sk
  2. a ConfigMap to store dataIds and their content (Optional, controller will create if this object doesn't exist)
  3. a DynamicConfiguration, which defines the behaviour of synchronization
    • spec.dataIds:defines which dataIds should be synced
    • spec.nacosServer:defines the information of nacos server
    • spec.strategy:defines the strategy of synchronization
    • spec.objectRef:reference of object which contains dataIds and their content(Optional, if empty, controller will create a ConfigMap with same name as default object)
apiVersion: nacos.io/v1
kind: DynamicConfiguration
metadata:
    name: dc-demo-server2cluster
spec:
  dataIds:
  - data-id1.properties
  - data-id2.yml
  nacosServer:
    endpoint: <your-nacos-server-endpoint>
    namespace: <your-nacos-namespace-id>
    group: <your-nacos-group>
    authRef:
      apiVersion: v1
      kind: Secret
      name: nacos-auth
  strategy:
    syncPolicy: Always
    syncDirection: server2cluster
    syncDeletion: true
---
apiVersion: v1
kind: Secret
metadata:
    name: nacos-auth
data:
    ak: <base64 ak>
    sk: <base64 sk>

NacosServer Configuration

  • endpoint: the address server of nacos server, conflict with serverAddr field, and higher priority than serverAddr field
  • serverAddr: the address of nacos server, conflict with endpoint field
  • namespace: the namespace id of nacos server
  • group: the group of nacos server
  • authRef: a reference of Object, which contains ak/sk of nacos server, currently only Secret is supported
  nacosServer:
    endpoint: <your-nacos-server-endpoint>
    serverAddr: <your-nacos-server-addr>
    namespace: <your-nacos-namespace-id>
    group: <your-nacos-group>
    authRef:
      apiVersion: v1
      kind: Secret
      name: nacos-auth

Contributors

Special thanks to the following individuals/teams for their contributions to this project:

  • Alibaba Cloud EDAS team (project incubation source)

nacos-controller's People

Contributors

junfengp avatar slievrly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nacos-controller's Issues

创建DynamicConfiguration后,k8s集群configmap无法同步到nacos

环境
centos7 Linux 4.17.11-1.el7.elrepo.x86_64 #1 SMP Sat Jul 28 09:33:09 EDT 2018 x86_64 x86_64 x86_64 GNU/Linux
k8s 1.16.15

资源
cluster2server.yaml

apiVersion: nacos.io/v1
kind: DynamicConfiguration
metadata:
name: dc-demo-cluster2server
spec:
dataIds:

  • data-id1.properties
  • data-id2.yml
    nacosServer:
    serverAddr: nacos-headless.default:8848
    namespace: test
    group: default
    authRef:
    apiVersion: v1
    kind: Secret
    name: nacos-auth
    strategy:
    syncPolicy: Always
    syncDirection: cluster2server
    syncDeletion: true
    objectRef:
    apiVersion: v1
    kind: ConfigMap
    name: nacos-config-cm

apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-config-cm
namespace: default
data:
data-id1.properties: |
key=value
key2=value2
data-id2.yml: |
app:
name: test

apiVersion: v1
data:
ak: YQo= #未开启认证,随便设置的,nacos-controller未报错
sk: YQo=
kind: Secret
metadata:
name: nacos-auth
namespace: default

server2cluster.yaml

apiVersion: nacos.io/v1
kind: DynamicConfiguration
metadata:
name: dc-demo-server2cluster
spec:
dataIds:

  • data-id1.properties
  • data-id2.yml
    nacosServer:
    serverAddr: nacos-headless.default:8848
    namespace: public
    group: default
    authRef:
    apiVersion: v1
    kind: Secret
    name: nacos-auth
    strategy:
    syncPolicy: Always
    syncDirection: server2cluster
    syncDeletion: true

k8s编辑nacos-config-cm后,nacos-controller日志如下:
2024-01-24T07:22:34Z INFO dynamicconfiguration-resource default {"name": "dc-demo-server2cluster"}
2024-01-24T07:22:34Z INFO dynamicconfiguration-resource validate update {"name": "dc-demo-server2cluster"}
2024-01-24T07:22:34Z INFO dynamicconfiguration-resource default {"name": "dc-demo-server2cluster"}
2024-01-24T07:22:34Z INFO dynamicconfiguration-resource validate update {"name": "dc-demo-server2cluster"}
2024-01-24T07:22:42Z INFO dynamicconfiguration-resource default {"name": "dc-demo-server2cluster"}
2024-01-24T07:22:42Z INFO dynamicconfiguration-resource validate create {"name": "dc-demo-server2cluster"}
2024-01-24T07:22:42Z INFO Add finalizer {"controller": "dynamicconfiguration", "controllerGroup": "nacos.io", "controllerKind": "DynamicConfiguration", "DynamicConfiguration": {"name":"dc-demo-server2cluster","namespace":"default"}, "namespace": "default", "name": "dc-demo-server2cluster", "reconcileID": "91d769db-c145-42e3-b8ae-20a9f70afdc6"}
2024-01-24T07:22:42Z INFO dynamicconfiguration-resource default {"name": "dc-demo-server2cluster"}
2024-01-24T07:22:42Z INFO dynamicconfiguration-resource validate update {"name": "dc-demo-server2cluster"}
2024-01-24T07:22:42Z INFO start listening from nacos server {"controller": "dynamicconfiguration", "controllerGroup": "nacos.io", "controllerKind": "DynamicConfiguration", "DynamicConfiguration": {"name":"dc-demo-server2cluster","namespace":"default"}, "namespace": "default", "name": "dc-demo-server2cluster", "reconcileID": "91d769db-c145-42e3-b8ae-20a9f70afdc6", "group": "default", "namespace": "public", "dataId": "data-id1.properties"}
2024-01-24T07:22:42Z INFO start listening from nacos server {"controller": "dynamicconfiguration", "controllerGroup": "nacos.io", "controllerKind": "DynamicConfiguration", "DynamicConfiguration": {"name":"dc-demo-server2cluster","namespace":"default"}, "namespace": "default", "name": "dc-demo-server2cluster", "reconcileID": "91d769db-c145-42e3-b8ae-20a9f70afdc6", "group": "default", "namespace": "public", "dataId": "data-id2.yml"}
2024-01-24T07:31:57Z INFO config published to nacos server {"controller": "dynamicconfiguration", "controllerGroup": "nacos.io", "controllerKind": "DynamicConfiguration", "DynamicConfiguration": {"name":"dc-demo-cluster2server","namespace":"default"}, "namespace": "default", "name": "dc-demo-cluster2server", "reconcileID": "798963a0-c062-4c02-ab81-3822d76d5a89", "group": "default", "namespace": "test", "dataId": "data-id1.properties"}
2024-01-24T07:31:57Z INFO skip syncing, due to same md5 of content {"controller": "dynamicconfiguration", "controllerGroup": "nacos.io", "controllerKind": "DynamicConfiguration", "DynamicConfiguration": {"name":"dc-demo-cluster2server","namespace":"default"}, "namespace": "default", "name": "dc-demo-cluster2server", "reconcileID": "798963a0-c062-4c02-ab81-3822d76d5a89", "group": "default", "namespace": "test", "dataId": "data-id2.yml", "md5": "4e22ae55a981aa1e934f08e71c9603ff"}
2024-01-24T07:31:57Z INFO skip syncing, due to same md5 of content {"controller": "dynamicconfiguration", "controllerGroup": "nacos.io", "controllerKind": "DynamicConfiguration", "DynamicConfiguration": {"name":"dc-demo-cluster2server","namespace":"default"}, "namespace": "default", "name": "dc-demo-cluster2server", "reconcileID": "18a7b1c1-bbe3-4df6-b4f9-c54687d73c5b", "group": "default", "namespace": "test", "dataId": "data-id1.properties", "md5": "d8d9a26f34fa1f8e9c1c8bc2e83e0262"}
2024-01-24T07:31:57Z INFO skip syncing, due to same md5 of content {"controller": "dynamicconfiguration", "controllerGroup": "nacos.io", "controllerKind": "DynamicConfiguration", "DynamicConfiguration": {"name":"dc-demo-cluster2server","namespace":"default"}, "namespace": "default", "name": "dc-demo-cluster2server", "reconcileID": "18a7b1c1-bbe3-4df6-b4f9-c54687d73c5b", "group": "default", "namespace": "test", "dataId": "data-id2.yml", "md5": "4e22ae55a981aa1e934f08e71c9603ff"}

未见明显报错,且有更新成功的日志,但是nacos server端配置并未变更
image
image
请问如何解决

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.