All Products
Search
Document Center

Container Service for Kubernetes:Enable the core dump feature

Last Updated:Aug 25, 2023

This topic describes how to enable the core dump feature. You can view and analyze a core dump file to identify the cause of the issue when a container is unexpectedly terminated.

Background information

In Linux, if a program unexpectedly terminates or exits, the operating system records the state of the memory that is allocated to the program and saves the state to a file. This process is called a core dump. You can view and analyze the core dump file to identify the cause of an issue.

The following figure shows the signals that indicate core dumps in Linux. The values of the signals in the Action column are Core.

For more information, see Core dump file.

Overview

By default, the core dump feature is disabled in elastic container instances to prevent service unavailability that is caused by excessive disk usage. You can use one of the following methods to enable the core dump feature:

  • Method 1: Specify a path to store core files

    Elastic Container Instance allows you to use an external storage device to store core files. After you specify the storage device, the core dump feature is automatically enabled for the elastic container instance. If a container unexpectedly terminates or exits, the core dump feature is triggered to generate a core file. The core file is saved to the specified external storage device.

  • Method 2: Execute a core dump O&M task

    After you enable the core dump feature, the system generates an O&M task. If a container unexpectedly terminates or exits, the core dump feature is triggered to generate a core file. The core file is automatically saved to an Object Storage Service (OSS) bucket.

Note

  • Method 1 requires an external storage device. You can use this method to generate core files even if the program is unstable. However, if the program repeatedly restarts, a large number of core files may be generated.

  • Method 2 is easy to use, but has limits on the validity periods and regions that you specify. Method 2 is suitable for temporary program debugging and diagnostics.

    • An O&M task that is generated by using Method 2 can be executed only once. After the O&M task is executed and a core file is generated, the core dump feature is disabled. The validity period of the O&M task is 12 hours.

    • Method 2 is based on OSS and Message Service (MNS). You cannot use Method 2 in the following regions because these regions support Elastic Container Instance but do not support OSS or MNS: China (Beijing), China (Ulanqab), China (Heyuan), China (Guangzhou), and China (Nanjing).

Method 1: Specify a path to store core files

Description

Elastic Container Instance allows you to specify the path in which core files are stored. After you specify a path, the core dump feature is automatically enabled. Core files are used to analyze issues offline. In most cases, core files are stored on external storage devices instead of the local storage of containers. This prevents the loss of core files if the containers terminate. You can use one of the following methods to specify a path to store core files:

Important

The path cannot start with a vertical bar (|). You cannot use core dump files to configure executable programs.

  • Kubernetes

    When you create a pod in Kubernetes, you can add an annotation to specify the path where core files are saved.

    annotations:
        k8s.aliyun.com/eci-core-pattern: "/xx/xx/core"
  • OpenAPI

    When you call the CreateContainerGroup API operation to create an elastic container instance, you can use the CorePattern parameter to specify the path where core files are saved:

    CorePattern = "/xx/xx/core"

Example

You can call the following API operation to mount Apsara File Storage (NAS) file systems as external storage devices to store core files.

  1. Create Elastic Container Instance A, mount the NAS file system to Elastic Container Instance A, and specify a path to store core files.

    When you call the CreateContainerGroup API operation to create Elastic Container Instance A, configure the following parameters to mount the /dump/ directory of the NAS file system to the /data/dump-a/ directory of the container and specify the /data/dump/core path to store core files.

    'Volume.1.Name': 'volume1',
    'Volume.1.Type': 'NFSVolume',
    'Volume.1.NFSVolume.Path': '/dump/',
    'Volume.1.NFSVolume.Server': '143b24****-gfn3.cn-beijing.nas.aliyuncs.com',
    
    'Container.1.VolumeMount.1.Name': 'volume1',
    'Container.1.VolumeMount.1.MountPath': '/data/dump-a/',
    
    'CorePattern':'/data/dump-a/core',
  2. Trigger the core dump feature in a directory of the container on Elastic Container Instance A.

    For example, after you run the sleep 100 command in the container, you can press the Ctrl key and the \ key at the same time to trigger the core dump feature. The core file is saved to the /data/dump-a/ path of the container.

    coredump4
  3. Release Elastic Container Instance A.

  4. Mount the same NAS file system to Elastic Container Instance B.

    When you call the CreateContainerGroup API operation to create Elastic Container Instance B, specify the following parameters to mount the /dump/ directory of the NAS file system to the /data/dump-b/ directory of the container.

    'Volume.1.Name': 'volume1',
    'Volume.1.Type': 'NFSVolume',
    'Volume.1.NFSVolume.Path': '/dump/',
    'Volume.1.NFSVolume.Server': '143b24****-gfn3.cn-beijing.nas.aliyuncs.com',
    
    'Container.1.VolumeMount.1.Name': 'dvolume1',
    'Container.1.VolumeMount.1.MountPath': '/data/dump-b/',
  5. View the core file in the container of Elastic Container Instance B.

    The following figure shows that the core file is stored in the /data/dump-b/ path of the container. The core file is not lost after Elastic Container Instance A is released because the core file is stored in an external storage device.

    coredump5

Method 2: Execute a core dump O&M task

Use the Elastic Container Instance console

  1. Log on to the Elastic Container Instance console and create an elastic container instance.

  2. Enable the core dump feature.

    1. Click the instance ID to go to the instance details page.

    2. Click the O&M tab and click Enable.

      After you click Enable, the system generates an O&M task. Before the core dump feature is triggered, the task is in the Pending state.

      eci_coredump
  3. Trigger the core dump feature.

    After you run the following sleep 100 command in the container, press the Ctrl key and the \ key at the same time to trigger the core dump feature. A core file is automatically generated and saved to an OSS bucket.coredump2

  4. Download the core file.

    On the O&M tab of the instance details page, you can view the O&M task that is generated for the core dump. After the core dump feature is triggered and the system generates a core file, the status of the O&M task changes to Successful. Click Download in the Result column to download the core file to your on-premises machine.

    eci_coredump2

    If the system does not respond, check the website permission settings of your browser. For example, if you use Google Chrome, you can use the following method to allow the download:

    1. In the Elastic Container Instance console, click the Browser icon icon in the address bar of your browser, and then select Site settings. Browser settings 1

    2. Change the settings of the configuration item Insecure content to Allow. Browser settings 2

OpenAPI

  1. Create an elastic container instance.

    When you call the CreateContainerGroup API operation to create an elastic container instance, do not specify the CorePattern parameter.

  2. Enable the core dump feature.

    Call the CreateInstanceOpsTask API operation to create an O&M task. Set OpsType to coredump and OpsValue to enable to enable the core dump feature.

  3. Trigger the core dump feature.

    After you run the following sleep 100 command in the container, press the Ctrl key and the \ key at the same time to trigger the core dump feature. A core file is automatically generated and saved to an OSS bucket.coredump2

  4. Download the core file.

    Call the DescribeInstanceOpsRecords API operation to query the result of the O&M task that is executed. The ResultContent response parameter specifies the OSS path of the core file. You can use the path to download the core file.