Skip to content

Init Containers

Init Containers can be added to an agent's pod via .spec.agents[*].initContainers.

Kynomesh already runs two built-in init containers on every agent pod: init-runtime (prepares the shared runtime directory) runs first, then any containers listed in initContainers run, and agent (the user's agent container, run as a native sidecar via restartPolicy: Always) runs last — since it never completes, anything meant to prepare state for it must run before it starts.

The following example adds an init container that seeds a volume before the agent starts:

apiVersion: kynomesh.kyno.sh/v1alpha1
kind: AgentSet
metadata:
  name: my-agentset
spec:
  pattern: Supervisor
  entry: my-agent
  agents:
    - name: my-agent
      container:
        image: my-agent:latest
      initContainers:
        - name: my-init
          image: busybox:latest
          command: ["/bin/sh", "-c", 'echo "my-init is running!" && sleep 5']

The following example uses an init container together with a volume to provide the agent container files on startup:

apiVersion: kynomesh.kyno.sh/v1alpha1
kind: AgentSet
metadata:
  name: my-agentset
spec:
  pattern: Supervisor
  entry: my-agent
  agents:
    - name: my-agent
      volumes:
        - name: my-agent-data
          emptyDir: {}
      initContainers:
        - name: my-init
          image: amazon/aws-cli:latest
          command:
            [
              "/bin/sh",
              "-c",
              "aws s3 sync s3://path/to/my-s3-data /path/to/my-init-data",
            ]
          volumeMounts:
            - mountPath: /path/to/my-init-data
              name: my-agent-data
      container:
        image: my-agent:latest
        volumeMounts:
          - mountPath: /path/to/my-data
            name: my-agent-data

Init containers receive the same Kynomesh-injected environment variables as every other container in the pod, and initContainers[*].resources can be set like any other container resources.

See Also