# Dependency injection

Running several packages in the same Kubernetes cluster usually means maintaining glue configuration between them: datasource files and trace links in Grafana, extension lists in PostgreSQL, and cloud IAM annotations on ServiceAccounts. In Kix, connected packages configure each other in both directions at build time, enable optional shared services only when needed, and switch between static Secrets and cloud workload identities.

<Video
  title="Dependency injection"
  duration="5:19"
  src="https://media.kix.run/videos/explanation-dependency-injection/v3/explanation-dependency-injection.mp4"
  poster="https://media.kix.run/videos/explanation-dependency-injection/v3/poster.webp"
  captions="https://media.kix.run/videos/explanation-dependency-injection/v3/captions.en.vtt"
/>

## Two-way configuration without glue files

When two packages connect in Kix, settings can move in both directions across that link during compilation.

From provider to application, a backing service publishes its addresses, ports, and credentials, and any connected application reads them to build its configuration files, environment variables, and cross-service links. From application to provider, an application can also push required setup settings into the backing service it depends on, such as asking PostgreSQL to enable an extension or asking ClickHouse for read grants on system tables.

Two-way configuration never loops because Kix compiles in two steps. First, Kix resolves package connections and merges each instance's defaults, cluster settings, and incoming settings from dependent applications. Second, once every instance's settings are final, Kix builds the Kubernetes manifests and passes service addresses and credentials forward.

## Adapting to optional services automatically

Grafana shows how optional dependencies remove manual glue work. On its own, the Grafana package requires only an administrator login Secret, while metrics, alerting, logs, distributed tracing, single sign-on, and mail are optional inputs. Place only Grafana and its admin Secret in a monitoring namespace, and Grafana starts with built-in login and no preconfigured datasources.

Add Prometheus, Alertmanager, Loki, and Tempo to that monitoring namespace, and Kix connects all four backends to Grafana without any changes to the Grafana entry. Grafana writes its datasources ConfigMap with fixed identifiers so dashboards work across clusters, links Tempo traces to Loki pod logs and Prometheus service graphs, orders rollouts, and opens matching ingress and egress firewall rules. Prometheus also connects to Alertmanager in the same build. If those backends run in separate namespaces, explicit cross-namespace links on Grafana produce the same setup.

## Pushing requirements upstream and setting guardrails

Plausible Analytics shows why settings also flow into backing services. During its first startup migration, Plausible creates the `citext` extension in PostgreSQL and needs custom function privileges and read access on six system tables in ClickHouse. With Helm or plain YAML, missing one of those steps leaves the database healthy while the application fails on startup. In Kix, the Plausible package declares those database settings itself, and Kix merges them into the connected PostgreSQL and ClickHouse instances.

Two cases call for explicit limits on upstream settings, and Kix checks both offline:

- **Locked platform databases:** On a restricted PostgreSQL database where applications may not enable extra extensions on their own, you can lock the database's extensions list in your cluster file. Adding an application that requests an unlisted extension fails the local check, naming the locked setting and the application that requested the change.
- **External cloud databases:** When PostgreSQL runs outside Kix on Amazon RDS, Kix does not manage the server and cannot install extensions. Instead, you list the extensions installed on RDS on the service import, and local checks verify that every required extension is listed before you deploy.

## On-demand services, cluster roles, and cloud identities

Dependency resolution also controls which shared services run in a cluster and how pods authenticate to cloud APIs.

Shared cluster modules can mark services such as ClickHouse as optional. While no active application uses ClickHouse, Kix renders no ClickHouse manifests and runs no policy checks on it; adding an application that requires ClickHouse enables it automatically. Clusters can also offer a catalog of stable packages for on-demand creation: when an application requires a Redis cache and none is declared, Kix adds a Valkey instance automatically, and requires a dedicated platform namespace before adding any cluster-wide operator. Optional inputs such as Grafana's Loki connection never turn on extra services; they connect only when the service is already active.

Cluster flavors also mark built-in capabilities such as DNS, storage classes, load balancers, and pod networking as absent, replaceable by a Kix package, or owned exclusively by the platform so local checks block duplicate CNI plugins or metrics servers.

Packages that call cloud APIs, including ExternalDNS, Velero, Tempo, and CloudNativePG, accept either a Kubernetes Secret or a cloud workload identity on the same credential input. On bare metal or kind, pass a Secret; on EKS, GKE, or AKS, pass an AWS, Google Cloud, or Azure identity without editing package code. Kix writes the required ServiceAccount annotations and pod labels, rejects cloud mismatches offline, adds a pod template hash so changing an IAM role rolls pods, exports IAM trust subjects as JSON for Terraform or OpenTofu, and checks new pods during deployment on AWS and Azure to catch missing webhook token variables.

Next, read [Availability levels](/docs/concepts/availability-levels/) to see how Kix turns one cluster resilience target into replica counts, pod placement, and disruption budgets. For exact options on upstream settings, locks, on-demand packages, and cloud identities, see [Instances and composition](/docs/reference/instances-and-composition/).