push-to-k8s

by mattmattox503

Helm chartv1.2.4App v1.2.4

A Kubernetes controller that automatically synchronizes labeled secrets from a source namespace to all other namespaces in the cluster

About this chart

Push-to-K8s Helm Chart

A Kubernetes controller that automatically synchronizes labeled secrets from a source namespace to all other namespaces in the cluster.

Overview

Push-to-K8s is a lightweight Go-based controller that watches for secrets labeled with push-to-k8s=source in a designated namespace and automatically syncs them to all other namespaces (excluding system namespaces and those with exclusion labels). This is ideal for distributing common secrets like registry credentials, API keys, and TLS certificates across your entire cluster.

Features

  • Automatic Secret Synchronization: Syncs labeled secrets to all namespaces
  • Real-time Namespace Watching: Automatically syncs secrets to newly created namespaces
  • Smart Update Detection: Only updates secrets when data changes
  • Namespace Exclusion: Label namespaces to exclude them from receiving secrets
  • Prometheus Metrics: Built-in metrics for monitoring controller health
  • Health Endpoints: /healthz and /readyz endpoints for Kubernetes probes
  • Graceful Shutdown: Proper signal handling and cleanup

Prerequisites

  • Kubernetes 1.19+
  • Helm 3.0+

Installation

Add the Helm Repository (if available)

helm repo add push-to-k8s https://supporttools.github.io/push-to-k8s
helm repo update

Install from Local Chart

# From the repository root
helm install push-to-k8s ./charts/push-to-k8s --namespace push-to-k8s --create-namespace

Install with Custom Values

helm install push-to-k8s ./charts/push-to-k8s \
  --namespace push-to-k8s \
  --create-namespace \
  --set settings.debug=true \
  --set settings.SyncInterval=10

Configuration

Key Parameters

ParameterDescriptionDefault
settings.debugEnable debug loggingfalse
settings.metrics.enabledEnable Prometheus metricstrue
settings.metrics.portMetrics server port9090
settings.ExcludeNamespaceLabelLabel to exclude namespaces""
settings.SyncIntervalSync interval in minutes15
replicaCountNumber of controller replicas1
image.repositoryContainer image repositorycube8021/push-to-k8s
image.tagContainer image taglatest
image.pullPolicyImage pull policyAlways
resources.requests.cpuCPU request100m
resources.requests.memoryMemory request128Mi
resources.limits.cpuCPU limit200m
resources.limits.memoryMemory limit256Mi

Example values.yaml

settings:
  debug: false
  metrics:
    enabled: true
    port: 9090
  ExcludeNamespaceLabel: "push-to-k8s-exclude"
  SyncInterval: 15

image:
  repository: cube8021/push-to-k8s
  tag: "v1.0.0"
  pullPolicy: IfNotPresent

resources:
  limits:
    cpu: 200m
    memory: 256Mi
  requests:
    cpu: 100m
    memory: 128Mi

nodeSelector:
  kubernetes.io/os: linux

Usage

1. Label Secrets for Synchronization

Label any secret in the controller's namespace with push-to-k8s=source:

kubectl create secret generic my-registry-credentials \
  --from-literal=username=myuser \
  --from-literal=password=mypass \
  --namespace push-to-k8s

kubectl label secret my-registry-credentials push-to-k8s=source -n push-to-k8s

2. Verify Secret Synchronization

# Check the source secret
kubectl get secret my-registry-credentials -n push-to-k8s --show-labels

# Verify it was synced to other namespaces
kubectl get secret my-registry-credentials -n default
kubectl get secret my-registry-credentials -n production

3. Exclude Namespaces (Optional)

Set the ExcludeNamespaceLabel value and label namespaces to exclude:

helm upgrade push-to-k8s ./charts/push-to-k8s \
  --set settings.ExcludeNamespaceLabel=push-to-k8s-exclude \
  --reuse-values

kubectl label namespace kube-system push-to-k8s-exclude=true
kubectl label namespace kube-public push-to-k8s-exclude=true

Monitoring

Accessing Metrics

Port-forward to the controller and access Prometheus metrics:

kubectl port-forward -n push-to-k8s deployment/push-to-k8s 9090:9090

# View all metrics
curl http://localhost:9090/metrics

# View controller-specific metrics
curl http://localhost:9090/metrics | grep k8s_

Available Metrics

  • k8s_namespace_total - Total number of namespaces in the cluster
  • k8s_namespace_synced_total - Number of namespaces receiving synced secrets
  • k8s_namespace_not_synced_total - Number of excluded namespaces
  • k8s_source_secrets_total - Number of source secrets being synced
  • k8s_managed_secrets_total - Total number of managed secrets across all namespaces
  • k8s_connection_success_total - Kubernetes connection status

Health Checks

# Liveness probe
curl http://localhost:9090/healthz

# Readiness probe
curl http://localhost:9090/readyz

Troubleshooting

Secrets Not Syncing

  1. Verify the controller is running:

    kubectl get pods -n push-to-k8s
    kubectl logs -n push-to-k8s deployment/push-to-k8s
    
  2. Check that secrets have the correct label:

    kubectl get secrets -n push-to-k8s --show-labels | grep push-to-k8s
    
  3. Verify RBAC permissions:

    kubectl auth can-i create secrets --as=system:serviceaccount:push-to-k8s:push-to-k8s -n default
    

Controller Not Starting

  1. Check deployment status:

    kubectl describe deployment -n push-to-k8s push-to-k8s
    
  2. Verify service account exists:

    kubectl get serviceaccount -n push-to-k8s
    
  3. Check RBAC resources:

    kubectl get clusterrole,clusterrolebinding | grep push-to-k8s
    

Upgrading

# Update chart values
helm upgrade push-to-k8s ./charts/push-to-k8s \
  --namespace push-to-k8s \
  --reuse-values \
  --set image.tag=v1.1.0

Uninstalling

helm uninstall push-to-k8s --namespace push-to-k8s

Note: This will not automatically remove synced secrets from other namespaces. You can manually clean them up if needed.

Contributing

See CONTRIBUTING.md for details on contributing to this project.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Support

  • GitHub Issues: https://github.com/supporttools/push-to-k8s/issues
  • Documentation: https://github.com/supporttools/push-to-k8s
  • Maintainer: mattmattox ([email protected])

Deploy push-to-k8s with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has push-to-k8s on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartpush-to-k8s is pinned at v1.2.4 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply