Select a documentation version: <button class="button button-with-icon cloud-select-dropdown__button button-primary" aria-haspopup="true">18.4.0</button>

- [Current (18.4.0)](https://docs.cloud.google.com/alloydb/omni/kubernetes/current/docs/kubernetes-sidecar-container.md.txt)
- [18.4.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/18.4.0/docs/kubernetes-sidecar-container.md.txt)
- [18.3.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/18.3.0/docs/kubernetes-sidecar-container.md.txt)
- [18.1.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/18.1.0/docs/kubernetes-sidecar-container.md.txt)
- [17.10.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/17.10.0/docs/kubernetes-sidecar-container.md.txt)
- [17.9.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/17.9.0/docs/kubernetes-sidecar-container.md.txt)
- [17.7.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/17.7.0/docs/kubernetes-sidecar-container.md.txt)
- [17.5.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/17.5.0/docs/kubernetes-sidecar-container.md.txt)
- [16.14.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/16.14.0/docs/kubernetes-sidecar-container.md.txt)
- [16.13.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/16.13.0/docs/kubernetes-sidecar-container.md.txt)
- [16.11.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/16.11.0/docs/kubernetes-sidecar-container.md.txt)
- [16.9.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/16.9.0/docs/kubernetes-sidecar-container.md.txt)
- [16.8.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/16.8.0/docs/kubernetes-sidecar-container.md.txt)
- [16.3.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/16.3.0/docs/kubernetes-sidecar-container.md.txt)
- [15.18.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.18.0/docs/kubernetes-sidecar-container.md.txt)
- [15.17.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.17.0/docs/kubernetes-sidecar-container.md.txt)
- [15.15.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.15.0/docs/kubernetes-sidecar-container.md.txt)
- [15.13.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.13.0/docs/kubernetes-sidecar-container.md.txt)
- [15.12.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.12.0/docs/kubernetes-sidecar-container.md.txt)
- [15.7.1](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.7.1/docs/kubernetes-sidecar-container.md.txt)
- [15.7.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.7.0/docs/kubernetes-sidecar-container.md.txt)
- [15.5.5](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.5.5/docs/kubernetes-sidecar-container.md.txt)
- [15.5.4](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.5.4/docs/kubernetes-sidecar-container.md.txt)
- [15.5.2](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.5.2/docs/kubernetes-sidecar-container.md.txt)

<br />

> [!CAUTION]
> The information on this page applies only to AlloyDB Omni using the container orchestrator. It does not apply to AlloyDB Omni using containers.

<br />

If your database runs in a Kubernetes cluster, then you can add
sidecar containers to your database cluster using the AlloyDB Omni Kubernetes operator.
AlloyDB Omni operator sidecar containers are regular
Kubernetes
[containers](https://kubernetes.io/docs/concepts/containers/) that run
independently alongside the main application container within the same Pod.
You can use these sidecar containers to serve requests for application
monitoring, logging, and tracing.

AlloyDB Omni operator sidecar containers are distinct from
Kubernetes built-in
[sidecar containers](https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/#pod-sidecar-containers).

To manually add a sidecar container to an existing
AlloyDB Omni installation, you create a
[`Sidecar` custom resource (CR)](https://docs.cloud.google.com/alloydb/omni/kubernetes/current/docs/reference/kubernetes-crds-1.9.0/sidecar.md.txt)
and add it to your database cluster. For complete manifest examples, see the
[Custom Sidecar sample](https://docs.cloud.google.com/alloydb/omni/kubernetes/current/docs/samples.md.txt#custom-sidecar)
and the
[DBCluster with Custom Sidecar sample](https://docs.cloud.google.com/alloydb/omni/kubernetes/current/docs/samples.md.txt#dbcluster-custom-sidecar).

> [!CAUTION]
> **Caution:** Making changes to an active sidecar container restarts the Pod that it runs on, which might result in database downtime.

## Create a sidecar CR

1. Apply the following manifest:

   ```yaml
   apiVersion: alloydbomni.dbadmin.goog/v1
   kind: Sidecar
   metadata:
     name: SIDECAR_CR_NAME
   spec:
     sidecars:
     - image: CONTAINER_IMAGE
       command: ["CONTAINER_COMMAND"]
       args: ["CONTAINER_ARGS"]
       name: CONTAINER_NAME
   ```

   > [!NOTE]
   > **Note:** If you configure volumes in the `spec.additionalVolumes` field of your Sidecar custom resource (CR), AlloyDB Omni operator only supports the `configMap`, `secret`, and `downwardAPI` volume types. No other volume types are supported.

   Replace the following variables:
   - `SIDECAR_CR_NAME`: the name for your sidecar container.
   - `CONTAINER_IMAGE`: the name of the image file to run in your sidecar container. For example, `busybox`.
   - `CONTAINER_COMMAND`: the command for the container that runs in the Pod. The command can be a list of quoted strings. For more information, see [Define a command and arguments when you create a Pod](https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/).
   - `CONTAINER_ARGS`: arguments for `CONTAINER_COMMAND`.
   - `CONTAINER_NAME`: the name of the container. You can have multiple containers in the same sidecar CR, and each container has a different container name, image, command, and arguments.
2. To verify that the sidecar CR is created, run the following command:

   ```bash
   kubectl describe Sidecar/SIDECAR_CR_NAME
   ```

   The output is similar to the following:

   ```yaml
   Name:  SIDECAR_CR_NAME
   Labels:       <none>
   Annotations:  <none>
   API Version:  alloydbomni.dbadmin.goog/v1
   Kind:         Sidecar
   Metadata:
     Creation Timestamp:  2024-04-15T21:49:00Z
     Finalizers:
       sidecars.dbadmin.goog/finalizer
     Generation:        2
     Resource Version:  2561336
     UID:               e57f2e13-20c5-4905-b13b-39203bab36b4
   Spec:
     Sidecars:
       Args:
         CONTAINER_ARGS
       Command:
         CONTAINER_COMMAND
       Image:  CONTAINER_IMAGE
       Name:   CONTAINER_NAME
       Resources:
   Status:
     Observed Generation:  2
     Reconciled:           true
   Events:                 <none>
   ```

## Register a sidecar container

To register the sidecar container name to your database cluster, use the
following command to apply the updated specification:

```bash
kubectl patch dbclusters.alloydbomni.dbadmin.goog DB_CLUSTER_NAME -p '{"spec":{"primarySpec":{"sidecarRef":{"name":"SIDECAR_CR_NAME"}}}}' --type=merge
```

Replace the following variables:

- `DB_CLUSTER_NAME`: the name of your database cluster.
- `SIDECAR_CR_NAME`: the name for your sidecar container.

## Access logs from a sidecar container

1. Create, or modify an existing, sidecar container so that
   `spec.sidecars.volumeMounts.name` is set to `obsdisk` and
   `spec.sidecars.volumeMounts.mountPath` to a path visible within the
   sidecar container.

   ```yaml
     apiVersion: alloydbomni.dbadmin.goog/v1
     kind: Sidecar
     metadata:
       name: SIDECAR_CR_NAME
     spec:
       sidecars:
       - image: CONTAINER_IMAGE
         command: ["CONTAINER_COMMAND"]
         args: ["CONTAINER_ARGS"]
         name: CONTAINER_NAME
         volumeMounts:
           - name: obsdisk
             mountPath: LOGS_PATH
   ```

   Replace the following:
   - `SIDECAR_CR_NAME`: the name for your sidecar container.
   - `CONTAINER_IMAGE`: the name of the image file to run in your sidecar container. For example, `busybox`.
   - `CONTAINER_COMMAND`: the command for the container that runs in the Pod. The command can be a list of quoted strings. For more information, see [Define a command and arguments when you create a Pod](https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/).
   - `CONTAINER_ARGS`: the arguments for `CONTAINER_COMMAND`.
   - `CONTAINER_NAME`: the name of the container. You can have multiple containers in the same sidecar CR, and each container has a different container name, image, command, and arguments.
   - `LOGS_PATH`: the path within the sidecar container that AlloyDB Omni should output logs to.
2. [Register](https://docs.cloud.google.com/alloydb/omni/kubernetes/current/docs/kubernetes-sidecar-container.md.txt#register-sidecar-container) your new, or modified, sidecar
   container.

## What's next

- [Configure database flags](https://docs.cloud.google.com/alloydb/omni/kubernetes/current/docs/configure-database-flags.md.txt)
- [Manage and monitor AlloyDB Omni](https://docs.cloud.google.com/alloydb/omni/kubernetes/current/docs/manage.md.txt)
- [View the `Sidecar` CRD reference](https://docs.cloud.google.com/alloydb/omni/kubernetes/current/docs/reference/kubernetes-crds-1.9.0/sidecar.md.txt)
- [Explore Kubernetes configuration samples](https://docs.cloud.google.com/alloydb/omni/kubernetes/current/docs/samples.md.txt#custom-sidecar)