Reference
Section titled “Reference”Root decorators
Section titled “Root decorators”@initKubernetes()
Section titled “@initKubernetes()”Initialize a Kubernetes plugin instance for k8sSecret(), k8sConfigMap(), k8sSecretBulk(), and k8sConfigMapBulk() resolvers.
Key/value args:
id(optional, static): Instance identifier for multiple instances, defaults to_defaultnamespace(optional): Kubernetes namespace to read from. Defaults to the kubeconfig context namespace, the pod’s mounted service account namespace (when in-cluster), ordefaultcontext(optional): Kubeconfig context name to use (overrides the current context)kubeconfig(optional): Path to a kubeconfig file, or raw kubeconfig YAML/JSON contentclusterServer(optional): Kubernetes API server URL for explicit auth (e.g.,https://kubernetes.example.com:6443)token(optional): Bearer token for explicit authskipTlsVerify(optional): Set totrueto skip TLS verification on the cluster certificate. Only applies when usingclusterServer+tokenallowMissing(optional): Iftrue, missing resources or keys returnundefinedinstead of throwingdefaultSecret(optional): Default Secret name used byk8sSecret()/k8sSecretBulk()when no name argument is provideddefaultConfigMap(optional): Default ConfigMap name used byk8sConfigMap()/k8sConfigMapBulk()when no name argument is provided
# @initKubernetes(namespace=default, defaultSecret=app-secrets, defaultConfigMap=app-config)Data types
Section titled “Data types”kubernetesBearerToken
Section titled “kubernetesBearerToken”This type is @internal by default: varlock uses it to fetch your other secrets but does not inject it into your application. Override with @internal=false if your app uses the credential directly, for example to write secrets back or fetch additional secrets at runtime.
Represents a Kubernetes bearer token used for API server authentication (typically a service account token). This type is marked as @sensitive.
# @type=kubernetesBearerTokenKUBERNETES_TOKEN=Resolver functions
Section titled “Resolver functions”k8sSecret()
Section titled “k8sSecret()”Fetch a single key from a Kubernetes Secret. Secret data values are base64-decoded automatically.
Arguments can be provided positionally or as named arguments, but the same field cannot be provided both ways.
Array args (positional):
instanceId(optional, static): Instance identifier to use when multiple plugin instances are initializedname(optional): Name of the Secret resource. Required unlessdefaultSecretis set on@initKubernetes()key(optional): Key inside the Secret’sdatato fetch. If omitted, uses the item key (variable name)
Named args:
id(optional, static): same as positionalinstanceIdname(optional): same as positionalnamekey(optional): same as positionalkey
# Auto-infer key from item nameDATABASE_URL=k8sSecret(app-secrets)
# Explicit key name (positional)DB_URL=k8sSecret(app-secrets, DATABASE_URL)
# Override just the key (uses defaultSecret from @initKubernetes)STRIPE_KEY=k8sSecret(key=stripe_api_key)
# Both positional and namedDB_URL=k8sSecret(name=app-secrets, key=DATABASE_URL)
# With instance IDPROD_DB=k8sSecret(prod, app-secrets, DATABASE_URL)k8sConfigMap()
Section titled “k8sConfigMap()”Fetch a single key from a Kubernetes ConfigMap. Both data and binaryData fields are supported.
Arguments can be provided positionally or as named arguments, but the same field cannot be provided both ways.
Array args (positional):
instanceId(optional, static): Instance identifier to use when multiple plugin instances are initializedname(optional): Name of the ConfigMap resource. Required unlessdefaultConfigMapis set on@initKubernetes()key(optional): Key inside the ConfigMap to fetch. If omitted, uses the item key (variable name)
Named args:
id(optional, static): same as positionalinstanceIdname(optional): same as positionalnamekey(optional): same as positionalkey
# Auto-infer key from item namePUBLIC_API_HOST=k8sConfigMap(app-config)
# Explicit key nameAPI_HOST=k8sConfigMap(app-config, PUBLIC_API_HOST)
# Named argsAPI_HOST=k8sConfigMap(name=app-config, key=PUBLIC_API_HOST)
# With instance IDDEV_HOST=k8sConfigMap(dev, app-config, PUBLIC_API_HOST)k8sSecretBulk()
Section titled “k8sSecretBulk()”Fetch all keys from a Kubernetes Secret as a JSON object string. Designed to be used with @setValuesBulk(..., format=json).
Array args (positional):
instanceId(optional, static): Instance identifier to use when multiple plugin instances are initializedname(optional): Name of the Secret resource. Required unlessdefaultSecretis set on@initKubernetes()
Named args:
id(optional, static): same as positionalinstanceIdname(optional): same as positionalname
# Uses defaultSecret from @initKubernetes# @setValuesBulk(k8sSecretBulk(), format=json)
# Explicit name# @setValuesBulk(k8sSecretBulk(app-secrets), format=json)
# With instance ID# @setValuesBulk(k8sSecretBulk(prod, app-secrets), format=json)k8sConfigMapBulk()
Section titled “k8sConfigMapBulk()”Fetch all keys from a Kubernetes ConfigMap as a JSON object string. Designed to be used with @setValuesBulk(..., format=json).
Array args (positional):
instanceId(optional, static): Instance identifier to use when multiple plugin instances are initializedname(optional): Name of the ConfigMap resource. Required unlessdefaultConfigMapis set on@initKubernetes()
Named args:
id(optional, static): same as positionalinstanceIdname(optional): same as positionalname
# @setValuesBulk(k8sConfigMapBulk(app-config), format=json)
# @setValuesBulk(k8sConfigMapBulk(prod, app-config), format=json)Troubleshooting
Section titled “Troubleshooting”Secret or ConfigMap not found (404)
Section titled “Secret or ConfigMap not found (404)”- Verify the resource exists:
kubectl get secret <name> -n <namespace>orkubectl get configmap <name> -n <namespace> - Double-check the namespace; the plugin reads only from the configured namespace
- Resource names are case-sensitive and namespace-scoped
- If the resource is genuinely optional, set
allowMissing=trueon@initKubernetes()and@required=falseon the item
Permission denied (403)
Section titled “Permission denied (403)”- Check that the active identity has the required RBAC:
kubectl auth can-i get secrets -n <namespace> - For in-cluster use, verify the pod’s
serviceAccountNameis set and bound to aRole/ClusterRolethat grantsgetonsecrets/configmaps - The error message includes the exact
Rolesnippet you need to grant
Authentication failed (401)
Section titled “Authentication failed (401)”- Local dev: Run
kubectl config current-contextand verify it points to the right cluster; runkubectl get secretsto confirm your kubeconfig works - Explicit token: Verify the token isn’t expired or revoked. Service account tokens created from
kubernetes.io/service-account-tokenSecrets are long-lived, but TokenRequest-issued tokens have shorter TTLs - In-cluster: Check the pod’s mounted service account token at
/var/run/secrets/kubernetes.io/serviceaccount/token
Connection refused or TLS errors
Section titled “Connection refused or TLS errors”- Verify the cluster API URL is reachable from your machine/pod
- For clusters with self-signed certificates and explicit auth, set
skipTlsVerify=true(development only) - If using
kubectlworks but the plugin doesn’t, your kubeconfig may rely on an exec credential plugin (e.g.,aws eks get-token,gke-gcloud-auth-plugin,kubelogin). Ensure the helper binary is on your$PATH
Wrong namespace
Section titled “Wrong namespace”- The plugin uses (in order): the explicit
namespaceargument, the current kubeconfig context’s namespace, the pod’s mounted SA namespace, ordefault - To force a specific namespace, pass it explicitly:
@initKubernetes(namespace=my-ns)