Skip to main content

atmos.kubernetes

The atmos.kubernetes function runs atmos kubernetes through the current Atmos executable. Use it to render, validate, diff, apply, and delete Kubernetes-native Atmos components from automation.

Usage​

atmos.kubernetes(
*positionals,
flags = {},
args = [],
working_directory = ...,
env = ...,
output = "stream",
check = True,
)

Also available as atmos.k8s.

Subcommands​

Pass the subcommand and the component name as strings before the keyword arguments. The call atmos.kubernetes("render", "demo", flags = {"stack": "dev"}) runs atmos kubernetes render demo --stack=dev.

SubcommandPurpose
renderRender Kubernetes manifests.
validateValidate rendered Kubernetes manifests.
planPreview server-side Kubernetes manifest changes.
diffShow server-side Kubernetes manifest changes.
applyApply Kubernetes manifests.
deployDeploy Kubernetes manifests.
deleteDelete Kubernetes manifests.

See the atmos kubernetes command reference for the complete list of subcommands and flags.

Arguments​

*positionals

(Optional) Strings placed on the command line right after kubernetes, in order: the subcommand, then the component name. Every value must be a string.

flags

(Optional) A dictionary of command-line options; see flag translation. A bare key such as "stack" becomes --stack, and the registered shorthand "s" resolves to the same flag. Other flags include "all", "affected", "base", "labels", "tags", "target", and the global "identity".

args
(Optional) A list or tuple of strings appended after the flags.
working_directory, env, output, check

(Optional) See atmos.run for process options and defaults.

Options other than the positionals are keyword-only.

Returns​

A result with stdout, stderr, and exit_code. See atmos.run for output and error behavior.

Examples​

Render a component​

manifests = atmos.kubernetes("render", "demo", flags = {"stack": "dev"}, output = "capture")
print(manifests.stdout)

This runs atmos kubernetes render demo --stack=dev and returns the rendered manifests in stdout.

Diff, then apply with an identity​

atmos.kubernetes("diff", "demo", flags = {"stack": "dev", "identity": "local-k3s"})
atmos.kubernetes("apply", "demo", flags = {"stack": "dev", "identity": "local-k3s"})

Apply everything in a stack​

atmos.kubernetes("apply", flags = {"all": True, "stack": "dev"})

This runs atmos kubernetes apply --all --stack=dev, which processes every Kubernetes component in dependency order.

Apply only affected components​

atmos.kubernetes("apply", flags = {"affected": True, "base": "origin/main"})
note

The Kubernetes commands are experimental, and Atmos prints its experimental notice when the script runs them. Authentication through the identity flag works the same way as on the command line.