Operating kbridge
This guide covers what a cluster operator and an application team need once kbridge runs: connecting a provider account, writing managed resources, reading their status, and handling drift, adoption and deletion. Installation is in the README.
ProviderConfig
A ProviderConfig (cluster-scoped, kbridge.io/v1alpha1) connects one provider account. Managed resources name it in spec.providerConfigRef.
| Field | Required | Description |
|---|---|---|
spec.provider | yes | Name of the Provider descriptor, for example aws or cloudflare. A resource of another provider cannot use it. |
spec.allowedNamespaces | yes | Namespaces whose resources may use it. "*" allows every namespace. |
spec.credentials.source | yes | Secret, WebIdentity or PodIdentity. Only awsSigV4 providers accept the last two. |
spec.credentials.secretRef.name | with Secret | Secret in the controller namespace. |
spec.credentials.assumeRoleARN | no | AWS role assumed with the base credentials, for cross-account access. |
spec.credentials.stsRegion | with WebIdentity or assumeRoleARN | Region of the STS endpoint. kbridge never guesses it. |
spec.values | no | String values exposed to descriptor expressions as config, for example the Cloudflare accountId. |
Secret keys by provider authentication type:
| Auth type | Keys |
|---|---|
bearer | token |
header | value |
basic | username, password |
awsSigV4 | accessKeyId, secretAccessKey, optional sessionToken |
WebIdentity uses the token that IRSA mounts (AWS_ROLE_ARN, AWS_WEB_IDENTITY_TOKEN_FILE). PodIdentity uses the EKS Pod Identity agent (AWS_CONTAINER_CREDENTIALS_FULL_URI, AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE). kbridge does not fall back to the default AWS credential chain.
kbridge reads Secrets directly from the API server and reuses them for 5 minutes. A rotated Secret applies within 5 minutes, or at once when the ProviderConfig changes.
Examples: providerconfig-aws.yaml, providerconfig-aws-irsa.yaml, providerconfig-cloudflare.yaml, providerconfig-proxmox.yaml.
Self-hosted APIs
The Proxmox VE provider talks to your own cluster, so its address is not known in advance. Before you build the image, set spec.endpoint and spec.allowedHosts in providers/proxmox/provider.yaml, for example:
endpoint: https://pve.lab.example.com:8006/api2/json
allowedHosts:
- '^pve\.lab\.example\.com:8006$'
kbridge trusts the system certificate authorities only and never skips TLS verification, so it refuses the self-signed certificate Proxmox VE installs by default. Either:
- issue a trusted certificate with the ACME support built into Proxmox VE, or
- mount the cluster CA,
/etc/pve/pve-root-ca.pemon any node, in a directory of the controller pod, and setSSL_CERT_DIRto that directory. The system authorities stay trusted.
Create a dedicated user and its token on a node. The role covers storage management only; Datastore.Audit lets kbridge see every storage, without it every storage looks absent and creates fail:
pveum user add kbridge@pve --comment "kbridge controller"
pveum role add KbridgeStorage --privs "Datastore.Allocate,Datastore.Audit"
pveum acl modify /storage --users kbridge@pve --roles KbridgeStorage
pveum user token add kbridge@pve kbridge --privsep 0
Store the whole header in the Secret, with the token secret that the last command prints:
kubectl -n kbridge create secret generic proxmox-token \
--from-literal=value='PVEAPIToken=kbridge@pve!kbridge=<secret>'
Managed resources
Every generated CRD has the same top-level shape. Only forProvider depends on the descriptor.
| Field | Required | Default | Description |
|---|---|---|---|
spec.providerConfigRef | yes | Name of the ProviderConfig. | |
spec.forProvider | yes | Desired state of the external object, validated by the descriptor schema. Fields listed as immutable cannot change after creation; the API server rejects the update. | |
spec.driftPolicy | no | descriptor’s policy, Reapply for the shipped ones | Reapply, Alert or Ignore. See Drift. |
spec.deletionPolicy | no | Delete | Delete removes the external object with the resource; Orphan keeps it. |
Examples: s3-bucket.yaml, r2-bucket.yaml, proxmox-storage.yaml.
kubectl -n web get buckets.s3.aws.kbridge.io
kubectl -n web describe buckets.s3.aws.kbridge.io media
Status
| Field | Description |
|---|---|
status.conditions | Ready and Synced, see below. |
status.atProvider | External object state as the descriptor’s observe expression projects it. |
status.observedGeneration | Last spec generation applied to the external object. |
status.lastSyncTime | End of the last sync. |
Ready is True (reason Available) once the external object exists and has been read. It turns False with ExternallyDeleted when the object disappears and the policy does not recreate it.
Synced tells whether the last sync succeeded and the external object matches the spec:
| Status | Reason | Meaning and action |
|---|---|---|
| True | Synced | The external object matches the spec. |
| True | DriftIgnored | Fields differ and the policy is Ignore. |
| False | Drifted | Fields differ and the policy is Alert. Fix the external object, or switch to Reapply. |
| False | ImmutableDrift | An immutable field differs. kbridge never changes immutable fields: recreate the object, or align the spec through a new resource. |
| True or False | ExternallyDeleted | The external object was deleted outside kbridge and the policy is Ignore (True) or Alert (False). Remove the kbridge.io/external-name annotation, or switch to Reapply, to create it again. |
| False | AlreadyExists | An object matching the spec exists, but kbridge did not create it. See Adoption. |
| False | CreatePending | A previous create may have succeeded, and the object cannot be found without its identifier. See Interrupted creates. |
| False | ProviderConfigError | The ProviderConfig is missing, belongs to another provider, or does not allow the namespace. |
| False | CredentialsError | The Secret is missing or lacks a key, or the credential source does not fit the provider. |
| False | UpdateIneffective | The update calls succeeded but the fields still differ: the descriptor’s update or observe expression is wrong. |
| False | APIError | The provider API refused a request. The message holds the status and the provider’s error. |
| False | ReconcileError | Any other failure, such as a network error. |
Sync cycle
A resource syncs when it is created, when its spec or annotations change, and then every drift interval of its descriptor, 10 minutes by default, plus up to 10 % jitter. Each sync reads the resource from the API server rather than from the informer cache, so a stale copy is never mistaken for a spec change.
Retries:
- Statuses listed as
retryablein the provider descriptor and network errors retry with exponential backoff, from 1 second to 15 minutes. ARetry-Afterheader sets the delay. - Other API errors and configuration errors wait for the next drift interval or for a change to the resource.
Requests of one ProviderConfig share the rate limit of the provider descriptor. Separate accounts therefore get separate budgets.
Drift
A spec change is intent: kbridge applies it, with no drift report. A difference found without a spec change is drift.
kbridge compares only the top-level fields present both in spec.forProvider and in the observed state. A field left out of forProvider is not managed. Values must match exactly; numbers compare by value. A map compares as a whole, so a tag added on the provider side is drift.
| Policy | Mutable field drift | External deletion |
|---|---|---|
Reapply | Reported, then reverted. | Reported, then recreated. |
Alert | Reported. Synced=False, reason Drifted. | Reported. Ready=False, not recreated. |
Ignore | Not reported. Synced=True, reason DriftIgnored. | Not reported. Ready=False, not recreated. |
Immutable field drift is never reverted. It sets Synced=False with reason ImmutableDrift under every policy, and is reported unless the policy is Ignore.
A drift report consists of:
- a Warning event on the resource, with reason
DriftDetected,ImmutableDriftorExternallyDeleted; - a JSON log line
drift detectedwith group, kind, namespace, name, reason, fields and policy; - an increment of
kbridge_drift_detected_total.
Events and logs name the fields that differ, never their values.
Adoption
kbridge never takes over an object it did not create. When the read finds an object matching a new resource, the resource gets Synced=False with reason AlreadyExists, and kbridge leaves the object alone.
To adopt the object, set its identifier as the external name. For S3 and R2 buckets, the identifier is the bucket name:
kubectl -n web annotate buckets.s3.aws.kbridge.io media kbridge.io/external-name=acme-web-media
kbridge then converges the object to the spec. With deletionPolicy: Delete, it also deletes the object when the resource is deleted.
Interrupted creates
kbridge sets the kbridge.io/external-create-pending annotation (a timestamp) before it creates an object. It removes the annotation once it has recorded the identifier in kbridge.io/external-name. When a sync finds the annotation, kbridge knows that this resource started a create:
- If the descriptor can read the object from spec fields, as for S3 and R2, kbridge finds the object and records its identifier.
- If the read needs the identifier assigned by the provider, kbridge cannot tell whether the create succeeded. It stops with reason
CreatePendingrather than risk a duplicate. Check the provider. Then either setkbridge.io/external-nameto the created object and remove the pending annotation, or remove only the pending annotation to create the object again.
A create that the provider rejects also leaves the pending annotation, so for such descriptors the same manual step follows a rejected create.
Deletion
kbridge adds the kbridge.io/finalizer finalizer to every resource. When the resource is deleted:
- with
deletionPolicy: Delete, kbridge runs the delete operation, treats “not found” as done, then removes the finalizer; - with
deletionPolicy: Orphan, or when nothing was ever created, it removes the finalizer and leaves the external object.
kbridge never deletes data inside an object. Deleting a non-empty S3 bucket fails with BucketNotEmpty; the resource stays with Synced=False and reason APIError until the bucket is emptied. To release the resource and keep the external object, set spec.deletionPolicy: Orphan.
Metrics
The metrics endpoint (--metrics-addr, port 8080, service kbridge-metrics) exposes the controller-runtime metrics and:
| Metric | Type | Labels | Description |
|---|---|---|---|
kbridge_drift_detected_total | counter | group, kind, policy | Drift reports. |
kbridge_resources_drifted | gauge | group, kind | Resources whose external object currently differs from the spec and is left so: Alert drift, immutable drift, external deletion under Alert. |
kbridge_api_requests_total | counter | provider, method, code | Provider API requests; code is the HTTP status, or error when no response arrived. |
kbridge_api_request_duration_seconds | histogram | provider | Provider API latency. |
Alert on kbridge_resources_drifted > 0 and on increase(kbridge_drift_detected_total[1h]) > 0.
Security model
- Credentials live only in Secrets of the controller namespace. The controller can
getSecrets there, and only there. allowedNamespacesdecides which application namespaces may spend aProviderConfig’s credentials.- Requests go over HTTPS, only to hosts that the provider’s
allowedHostspatterns match. Redirects are never followed, and responses are capped at 4 MiB. - Logs, events and conditions never contain secret values or field values.
- The container runs as a non-root user with a read-only root filesystem and no capabilities.