Anemos Documentation

website·Indexed 31 days ago

https://anemos.sh/

A single binary CLI tool used to generate Kubernetes manifests and packages. Anemos leverages the JavaScript package management ecosystem for dependencies and provides a structured API for defining resource generation steps, including sanitization, modification, and outputting of documents.

Tokens
24.4K
Snippets
204
Records
256
Agent score
60%

What's inside Anemos

  1. Overview of Anemos Kubernetes Package Management

    Anemos is a single binary CLI tool that allows developers to manage Kubernetes manifests and infrastructure as code using JavaScript. Unlike tools that focus on single packages, Anemos is designed to manage the entire infrastructure as a whole, enabling the integration of multiple packages, dependencies, and configurations within a single codebase. Key capabilities include:

    • Generating Kubernetes manifests via template-based or object-oriented programming in JavaScript.
    • Managing multiple environments (e.g., development, staging, production) within one project.
    • Defining service requirements and dependencies.
    • Modifying generated Kubernetes manifests individually or in bulk.
  2. Populate Kubernetes resources using the populateKubernetesResources step

    The populateKubernetesResources step is used to populate KubernetesResource objects. This allows subsequent components in the pipeline to access information about existing resources to either modify them or generate additional dependent resources. For example, populating ServiceMonitor resources enables other components to generate the necessary monitoring configurations for services.
    const populateKubernetesResources: Step;
  3. Manage multiple applications and environments in one Anemos project

    Anemos projects are designed to handle multiple applications and environments (e.g., development, staging, production) within a single codebase. This prevents fragmented configurations and duplication of common values (like image registries or annotations) that typically occur when managing multiple separate Helm charts.
  4. Create an Environment instance

    The Environment class is used to store information about a target environment. It is initialized with a name and a type, both of which are strings.
    const env = new Environment('production', 'cloud');
  5. Use existing Helm charts within Anemos

    Anemos provides interoperability support that allows you to generate documents from existing Helm charts, facilitating a gradual migration process from Helm to Anemos.
  6. Install Anemos CLI via GitHub Releases

    Anemos is available as a single binary for Linux, Windows, and MacOS. Download the binary corresponding to your operating system and architecture from the GitHub releases page and place it in a directory included in your system's PATH.
  7. Understand Anemos Builder, Component, and Action architecture

    In Anemos, the generation process is managed by a Builder. The Builder is composed of multiple Component objects, which act as logical units of work or plugins (e.g., a component for backend manifests). Each Component contains one or more Actions.

    When Builder.build() is invoked, Anemos collects all actions from all registered components, sorts them by their assigned execution steps, and executes them sequentially. Actions are the actual functions that perform work, such as generating or modifying documents.

  8. Manage Component metadata with setMetadata()

    Use the setMetadata(key, value) method to store additional information about a component as string key-value pairs. This metadata is ignored by the builder but is accessible to other components.
    // setMetadata(key: string, value: string): void
    component.setMetadata("category", "ui-element");
  9. Instantiate a KubernetesCluster

    The KubernetesCluster class is used to provide information about the target Kubernetes cluster. It requires a version and a distribution string, and optionally accepts a list of additional Kubernetes resources.
    new KubernetesCluster(
       version: Version,
       distribution: string,
       additionalResources?: KubernetesResource[]
    );
  10. Create and use the Step class for flexible ordering

    The Step class allows for flexible ordering of items using a list of numbers. When comparing two Step objects, the numbers in their lists are compared index by index. If one list is shorter than the other, the missing index is treated as 0. This allows for the insertion of steps between existing ones (e.g., a step with values (1, 1, 1) falls between (1, 1) and (1, 2)).
    // Example logic:
    // Step A: (1, 2)
    // Step B: (1)
    // Comparison: Index 0 is equal (1=1). Index 1 for Step B is assumed 0. 
    // Since 2 > 0, Step A is greater than Step B.
  11. Create a basic Anemos package to generate Kubernetes manifests

    An Anemos package is defined as a JavaScript function (typically named add) that accepts a builder and an optional options object. This function uses the builder.addDocument method to define Kubernetes manifests.

    Key concepts:

    • Options: Used to provide customizable values (e.g., image names, namespaces) with defaults.
    • Document Groups: The documentGroup parameter organizes documents into folders and ensures they are applied or deleted as a single unit.
    • Custom Paths: The path parameter allows overriding the default filename (which is usually the lowercase kind and metadata name).
    function add(builder, options) {
      options ??= {};
    
      const name = options.name ?? "my-package";
      const namespace = options.namespace ?? "default";
      const image = options.image ?? "nginx";
    
      builder.addDocument({
        documentGroup: name,
        path: `pod.yaml`,
        content: `
          apiVersion: "v1"
          kind: "Pod"
          metadata:
            name: ${name}
            namespace: ${namespace}
          spec:
            containers:
              - name: "echo"
                image: "${image}"
                ports:
                  - name: "http"
                    containerPort: 80
                    protocol: "TCP"
          `
      });
    }
    
    module.exports = {
      add
    }
  12. Manage Anemos type declarations

    Anemos automatically generates type declarations in the .anemos/types directory. These are updated automatically when running build or package management commands (install, add, update, remove, link, unlink). If manual regeneration is required, use the anemos declarations command.
    anemos declarations .anemos/types