Compute is in preview, and the
v1alpha API can change.Before you begin
- Select a project, install the
computeplugin, and get access to Compute. For more information, see Compute commands. - Make sure that you can read the ConfigMaps and Secrets that your workload references. When you apply a workload, Datum checks that you have
getpermission on each one, and rejects the request if you don’t.
datumctl compute deploy flags. These flags require compute plugin v0.10.7 or later. For anything that the flags can’t set, such as a variable from one key of a Secret or credentials for a private registry, write a workload manifest. Apply the manifest with datumctl compute deploy -f FILE or datumctl apply -f FILE, where FILE is the path to your manifest. You can’t combine the configuration flags with -f. A flag-based deploy saves its result to workload.yaml, which you can edit as a starting point. Each flag-based deploy overwrites workload.yaml in the current directory, so keep edited manifests under another name.
Set environment variables
To set an environment variable to a fixed value, pass--env KEY=VALUE when you deploy. Repeat the flag for each variable. Values can contain commas. The following command sets two variables:
WORKLOAD_NAME: the name of your workload.IMAGE: the full image reference, including the registry host.LOCATION: one or more locations, separated by commas.
-, such as --env=LOG_LEVEL-.
In a manifest, add the variable to the container’s env list, as in the following example:
Create a ConfigMap or Secret
ConfigMaps hold non-sensitive settings, and Secrets hold sensitive values such as passwords and tokens. Both live in your project, and a workload can reference any ConfigMap or Secret in the same project. To create a ConfigMap and a Secret, follow these steps:-
Save the following manifest as
api-config.yaml:ReplacePASSWORDwith your database password. -
To create the objects, run the following command:
Set a variable from a ConfigMap or Secret key
Thedeploy flags can’t set one variable from one key, so use a manifest. To set one environment variable from one key, use valueFrom with configMapKeyRef or secretKeyRef. This method works with both runtime classes. The following example sets one variable from a Secret key and one from a ConfigMap key:
Set variables from a whole ConfigMap or Secret
Ongeneral-purpose workloads, you can turn every key of a ConfigMap or Secret into an environment variable. To do so with flags, pass --env-from-configmap or --env-from-secret as NAME or NAME:PREFIX_. The following command loads every key from api-config with the prefix APP_, and every key from api-secrets without a prefix:
WORKLOAD_NAME: the name of your workload.IMAGE: the full image reference, including the registry host.LOCATION: one or more locations, separated by commas.
- to the name, such as --env-from-secret=api-secrets-.
In a manifest, use envFrom. Each entry names exactly one source. The optional prefix is added to each variable name, and must be a valid variable name itself. The following manifest example loads the same keys:
unikernel runtime class doesn’t support envFrom. On unikernel workloads, set each variable with valueFrom instead.
Mount a ConfigMap or Secret as files
To mount a ConfigMap or Secret as files with flags, pass--configmap or --secret as NAME:/mount/path. Each key becomes a file in the mount directory. The following command mounts api-config at /etc/api and api-secrets at /etc/api-secrets:
WORKLOAD_NAME: the name of your workload.IMAGE: the full image reference, including the registry host.LOCATION: one or more locations, separated by commas.
- to the name, such as --secret=api-secrets-.
In a manifest, declare a volume in spec.template.spec.volumes, and attach it to a container with volumeAttachments.
The following manifest example mounts the same ConfigMap and Secret:
- A ConfigMap volume uses
configMap.name, but a Secret volume usessecret.secretName. - Attach every volume that you declare to at least one container, and give each attachment a
mountPath. - To mount only some keys, or to choose file names, add
itemswith akeyand a relativepathfor each file. Apathcan’t contain... - To set file permissions, set
defaultMode.
Apply a configuration change
Running Instances don’t restart when a ConfigMap or Secret changes. To make your app pick up the new values, restart the workload:WORKLOAD_NAME with the name of your workload.
The restart replaces Instances one at a time in each location. For more information, see Placement and scaling.
Use images from a private registry
To pull an image from a private registry, store the registry credentials in a Secret and reference it inimagePullSecrets. This method works with both runtime classes. To use a private registry, follow these steps:
-
Save the following manifest as
registry-credentials.yaml:Replace the following:REGISTRY_HOST: the registry host name, such asghcr.io. For Docker Hub, usehttps://index.docker.io/v1/.REGISTRY_USERNAME: the user name for the registry.REGISTRY_TOKEN: a password or access token with permission to pull the image. Use a read-only token.
-
To create the Secret, run the following command:
-
In your workload manifest, add the Secret to
spec.template.spec.runtime.sandbox.imagePullSecrets: -
To apply the manifest, run the following command:
Replace
workload.yamlwith your manifest file if it has a different name.
Complete example
The following manifest combines the settings on this page for ageneral-purpose workload:
unikernel class, change runtime.class to unikernel and remove the envFrom entry.
Limits
ConfigMaps and Secrets that a workload references have the following size limits:- 256 KiB for each ConfigMap or Secret.
- 1 MiB in total for all the ConfigMaps and Secrets that a workload references in one location.
ReferencedDataNotReady and its Instances report SourceTooLarge. For other configuration errors, see Compute troubleshooting.
What’s next
- To serve the workload on a public URL, see Publish a workload.
- To check status and fix problems, see Compute operations and Troubleshooting.