Add a sidecar container

更新时间:
复制 MD 格式

Serverless App Engine (SAE) lets you add a sidecar container to an application to enhance the main application container's functionality. A sidecar container helps you decouple and standardize non-business functions, such as monitoring and log collection. This approach separates auxiliary tasks from the main application container, allowing it to focus on its core business logic.

Entry points

  1. Create an application

    On the SAE Application List page, select a destination region and namespace in the top navigation bar, and then click Create Application. On the Application Basic Information page, configure the parameters and click Next: Advanced Settings.

    Change a running application

    Warning

    After you redeploy an application, the application is restarted. To prevent unpredictable errors such as business interruptions, we recommend that you deploy applications during off-peak hours.

    On the SAE Application List page, select a destination region and namespace in the top navigation bar. Click the ID of the target Application to open the application details page.In the navigation pane on the left, click Basic Information. In the upper-right corner, click Deploy Application.

    Change a stopped application

    On the SAE Application List page, select a destination region and namespace in the top navigation bar. Click the ID of the target Application to open the application details page.Click Basic Information, and then click Modify Application Configuration.

  2. Find and expand the Add a sidecar container. section, and then click Add.

Configuration

In the Sidecar container panel, configure the following parameters and click OK.

  1. Enter a custom Container name.

  2. Based on the image source for your sidecar, select either Images of Current Alibaba Cloud Account or Custom Image:

    • Images of Current Alibaba Cloud Account: Pull an image from the Container Registry (ACR) repository in the current account. You can use either Container Registry Personal Edition or Container Registry Enterprise Edition.

      Prerequisites: You have created an image and pushed it to an ACR image repository in the current account. For more information, see Image creation examples, Build images by using Enterprise Edition instances, or Push and pull images by using Personal Edition instances.

      • Container Registry Personal Edition: Specify the sidecar image by selecting an Image Repository Namespace, an Image Repository Name, and an Image Version.

        For example, set the image repository namespace to demo, the image repository name to nginx, and the image tag to latest.

      • Container Registry Enterprise Edition: Specify the sidecar image by selecting an instance from the Enterprise Edition Instances list, and then selecting an Image Repository Namespace, an Image Repository Name, and an Image Version.

    • Custom Image: Pull an image from a private image repository in another Alibaba Cloud account or a third-party image repository.

      • Private image repository in another Alibaba Cloud account:

        If the main application container pulls its image from an ACR repository in another Alibaba Cloud account, the sidecar container can also pull an image from the same repository. SAE automatically reuses the acrAssumeRoleArn and secret configured for the main application container.

        You must enter the full Image address. The format is <image repository address>:<image tag>. For example: registry.cn-beijing.aliyuncs.com/sae-demo-******:nginx.

      • Third-party image repository:

        To pull an image from a third-party image repository such as Docker Hub, Harbor, or GitHub Container Registry, ensure that the image repository address is accessible from the public internet.

        You must enter the full Image address. The format is <image name>:<image tag>. For example: registry.openanolis.cn/******/nginx:1.14.1-8.6.

        Important

        By default, SAE applications cannot access the public internet and therefore cannot pull images from public repositories. To enable this access, you must configure a NAT Gateway for your application's Virtual Private Cloud (VPC). For more information, see Configure a NAT Gateway to enable public network access for SAE applications.

  3. Set the Maximum number of CPU resources and Maximum number of memory resources for the Sidecar container.

    Note

    The sidecar container shares CPU and memory resources with the main application container. To ensure the main application container functions properly, set reasonable resource limits for the sidecar container to prevent it from consuming excessive resources.

  4. (Optional) Click Advanced Settings to configure the following parameters for the sidecar container.

    1. In the Startup Command section, configure a startup command for the sidecar container. For more information, see Set a startup command.

    2. In the Environment Variable section, configure environment variables for the sidecar container. For more information, see Set environment variables.

    3. In the Configuration Management section, inject required configuration into the sidecar container by mounting a ConfigMap. For more information, see Inject configurations.

    4. In the Share temporary storage section, create and mount a temporary storage directory to both the main application container and the sidecar container.

      Enter a Temporary Storage Name and a Container Path.

      Note

      The temporary storage name can contain only lowercase letters, digits, and hyphens (-).

Deployment verification

  • On the Log Management page, view the real-time logs for both the main application container and the sidecar container.

    From the Container drop-down list at the top of the page, select Sidecar container sidecar-nginx to view its real-time logs.

  • On the Instances page, use Webshell to log on to an instance. The Webshell page displays details for both the main application container and the sidecar container.

    Use the drop-down list at the top to switch between the Main application container and the Sidecar container sidecar-nginx.

  • In the /tmp directory of the main application container and the sidecar container, check for a test directory.