How-to guide / Platform capabilities
Use externally managed secrets
These docs describe Kix's main branch, which can include changes not yet released. Read the docs for the latest release.
Use scope.mkSecretRef when another system creates the Kubernetes Secret. Kix
does not render or update the Secret data, but it validates the keys your
package expects and waits for them before applying dependent resources.
This guide assumes the external system creates the Secret in the workload’s namespace.
Declare the Secret reference
Section titled “Declare the Secret reference”Add a reference to the package’s returned parts and list every key the package will consume:
16 credentials = scope.mkSecretRef {17 name = "billing-api-credentials";18 keys = [ "api-key" ];19 };The example expects Secret/billing-api-credentials in the package namespace.
scope.mkSecretRef emits an import marker rather than a Secret manifest.
Keep the reference in the build function’s returned attrset, as shown by the
credentials part above. A reference used only in a let binding is not
collected into the cluster artifact.
Consume declared keys
Section titled “Consume declared keys”Use the same out helpers available on a Kix-managed Secret:
23 deployment = scope.mkDeployment {24 name = scope.instanceName;25 spec = {26 replicas = 1;27 selector.matchLabels = scope.selectorLabels;28 template.spec.containers = [29 {30 name = "app";31 image = "busybox:1.36";32 command = [ "sh" "-c" "sleep 3600" ];33 env = self.credentials.out.mkEnv {34 BILLING_API_KEY = "api-key";35 };36 }37 ];38 };39 };out.mkEnv validates api-key during evaluation and adds the dependency edge
from the Deployment to the import marker.
Reference a Secret used whole
Section titled “Reference a Secret used whole”When the package only mounts the whole Secret or loads it with envFrom, and
no pod reads one of its keys by name, write keys = [ ];. The deploy then
checks only that the Secret exists. A pod that reads a key by name, through
secretKeyRef, a volume’s items, or a subPath, fails the cluster build
(cross-resource check 22) unless the ref lists that key, so the deploy can
check the live Secret holds it.
Check the wiring
Section titled “Check the wiring”Evaluate the cluster before connecting to Kubernetes:
❱ kix check how-to-platform-secrets
TOOL RESULT DETAILS
eval pass 11 manifests evaluated
scorecard pass 0 errors, 13 warnings, 2 info
governance.hasOwner (warning), 2:
secret-examples/external-example: package 'external-example' has no meta.owner
secret-examples/managed-example: package 'managed-example' has no meta.owner
reliability.boundedResources (warning), 2:
secret-examples/external-example/external-example: container 'app' is missing resource settings: requests.cpu, requests.memory, limits.cpu, limits.memory. Set CPU and memory requests and limits. Without a memory limit, a workload can exhaust the node's memory.
secret-examples/managed-example/managed-example: container 'app' is missing resource settings: requests.cpu, requests.memory, limits.cpu, limits.memory. Set CPU and memory requests and limits. Without a memory limit, a workload can exhaust the node's memory.
reliability.hasProbes (warning), 4:
secret-examples/external-example/external-example: container 'app' has no livenessProbe
secret-examples/external-example/external-example: container 'app' has no readinessProbe
secret-examples/managed-example/managed-example: container 'app' has no livenessProbe
secret-examples/managed-example/managed-example: container 'app' has no readinessProbe
security.hasNetworkPolicy (warning), 1:
secret-examples: namespace 'secret-examples' has workloads but no network policy
security.nonRoot (warning), 2:
secret-examples/external-example/external-example: container 'app' may run as root: neither it nor the pod sets securityContext.runAsNonRoot, and no non-zero runAsUser resolves for it
secret-examples/managed-example/managed-example: container 'app' may run as root: neither it nor the pod sets securityContext.runAsNonRoot, and no non-zero runAsUser resolves for it
security.readOnlyRootfs (warning), 2:
secret-examples/external-example/external-example: container 'app' does not set readOnlyRootFilesystem
secret-examples/managed-example/managed-example: container 'app' does not set readOnlyRootFilesystem
2 info finding(s) not listed; run with -v to list them. Inspect the graph when you need to confirm the deploy ordering:
❱ kix graph how-to-platform-secrets -o tree Show outputHide output · 25 lines
Namespace/kube-system
├── PackageInstance.kix.run/platform-storage@kube-system (import)
│ └── Activation.kix.run/how-to-platform-secrets-a29mvnqc7p7l
└── PackageInstance.kix.run/platform-dns@kube-system (import)
└── Activation.kix.run/how-to-platform-secrets-a29mvnqc7p7l
Namespace/secret-examples
├── Secret/managed-example-credentials@secret-examples
│ └── Deployment.apps/managed-example@secret-examples
│ └── PackageInstance.kix.run/managed-example@secret-examples
│ └── Activation.kix.run/how-to-platform-secrets-a29mvnqc7p7l
├── PackageInstance.kix.run/secret-ref-external-example-billing-api-credentials@secret-examples (import)
│ └── Deployment.apps/external-example@secret-examples
│ └── PackageInstance.kix.run/external-example@secret-examples
│ └── Activation.kix.run/how-to-platform-secrets-a29mvnqc7p7l
├── PackageInstance.kix.run/managed-example@secret-examples
│ └── Activation.kix.run/how-to-platform-secrets-a29mvnqc7p7l
├── PackageInstance.kix.run/external-example@secret-examples
│ └── Activation.kix.run/how-to-platform-secrets-a29mvnqc7p7l
├── Deployment.apps/managed-example@secret-examples
│ └── PackageInstance.kix.run/managed-example@secret-examples
│ └── Activation.kix.run/how-to-platform-secrets-a29mvnqc7p7l
└── Deployment.apps/external-example@secret-examples
└── PackageInstance.kix.run/external-example@secret-examples
└── Activation.kix.run/how-to-platform-secrets-a29mvnqc7p7l
11 resources, 16 dependencies The secret-ref-external-example-billing-api-credentials import appears
before Deployment.apps/external-example.
Verify the external Secret
Section titled “Verify the external Secret”Confirm that the provider has created the Secret in the expected namespace:
❱ kubectl get secret billing-api-credentials -n secret-examples During kix deploy, Kix checks that the Secret exists and contains the
declared keys before applying the dependent Deployment. A missing Secret or
key fails that deploy wave rather than starting the workload with an invalid
reference.