K8s Namespace Sync

K8s Namespace Sync is a Kubernetes controller that automatically synchronizes Secrets and ConfigMaps across multiple namespaces within a Kubernetes cluster.
Features
- Automatic synchronization of Secrets and ConfigMaps across namespaces
- Automatic detection and synchronization of changes in source namespace
- Automatic exclusion of system namespaces (kube-system, kube-public, etc.)
- Support for manually excluding specific namespaces
- Prometheus metrics support
- Synchronization status monitoring
Installation
kubectl apply -f https://raw.githubusercontent.com/somaz94/k8s-namespace-sync/main/release/install.yaml
Usage
- Create a Secret or ConfigMap in the source namespace:
apiVersion: v1
kind: Secret
metadata:
name: test-secret
namespace: default
type: Opaque
stringData:
username: admin
password: secret123
---
apiVersion: v1
kind: ConfigMap
metadata:
name: test-configmap
namespace: default
data:
key1: value1
key2: value2
- Create a NamespaceSync CR:
Basic synchronization:
apiVersion: sync.nsync.dev/v1
kind: NamespaceSync
metadata:
name: namespacesync-sample
spec:
sourceNamespace: default
configMapName: test-configmap
secretName: test-secret
Basic apply the CR:
kubectl apply -f https://raw.githubusercontent.com/somaz94/k8s-namespace-sync/main/release/examples/sync_v1_namespacesync.yaml
With excluded namespaces:
apiVersion: sync.nsync.dev/v1
kind: NamespaceSync
metadata:
name: namespacesync-sample-with-exclude
spec:
sourceNamespace: default
configMapName: test-configmap
secretName: test-secret
exclude:
- test-ns2
- test-ns3
Exclude apply the CR:
kubectl apply -f https://raw.githubusercontent.com/somaz94/k8s-namespace-sync/main/release/examples/sync_v1_namespacesync_with_exclude.yaml
Verification
- Check synchronization status:
kubectl get namespacesync namespacesync-sample -o yaml
- Verify resources in other namespaces:
kubectl get secret test-secret -n target-namespace
kubectl get configmap test-configmap -n target-namespace
Excluded Namespaces
The following namespaces are automatically excluded from synchronization:
- kube-system
- kube-public
- kube-node-lease
- k8s-namespace-sync-system
Additionally, you can manually exclude specific namespaces using the exclude field in the NamespaceSync CR.
Metrics
The following Prometheus metrics are available:
namespacesync_sync_success_total: Number of successful synchronizations
namespacesync_sync_failure_total: Number of failed synchronizations
Cleanup
- Delete the NamespaceSync CR:
kubectl delete namespacesync namespacesync-sample
kubectl delete namespacesync namespacesync-sample-with-exclude
- Remove the controller:
kubectl delete -f https://raw.githubusercontent.com/somaz94/k8s-namespace-sync/main/release/install.yaml
Contributing
Issues and pull requests are welcome.
License
This project is licensed under the MIT License - see the LICENSE file for details.