Use coredump to analyze instance program exceptions

Updated at:

If a program unexpectedly terminates or stops responding, the operating system records the content of the random access memory (RAM) that is allocated to the program and saves the content to a file for subsequent debugging and analysis. This process is called a core dump. This topic describes how to enable coredump for an elastic container instance (pod). This way, you can view and analyze the core files generated by coredump, find out the cause of the issue, and fix the program exceptions if a container is terminated due to exceptions.

Background information

On Linux, when an application terminates unexpectedly or crashes, the operating system records the application's memory state and saves it to a file. This process is known as a coredump. You can then analyze the core file to identify the cause of the problem.

The following figure shows the Linux signals that trigger a coredump. For these signals, the default action is Core.

For more information, see coredump file.

Overview

By default, coredump is disabled for an ECI instance to prevent excessive disk usage, which could lead to service outages. You can enable coredump by using one of the following methods:

  • Method 1: Enable a coredump O&M task

    After you manually enable coredump, the system creates an O&M task. When a container terminates abnormally or exits, the generated core file is automatically saved to OSS.

  • Method 2: Customize the save path for core files

    You can store core files in external storage by specifying a custom save path. After you set the save path, coredump is automatically enabled. When a container crashes or exits unexpectedly, the resulting core file is saved to the specified path.

Note
  • Method 1 is easy to use but has time and region limitations. It is suitable for temporary debugging and diagnostics.

    • The generated O&M task is a one-time task. Once a core file is successfully captured, coredump is automatically disabled. The O&M task is valid for 12 hours and expires if it is not triggered within this period.

    • This method is not supported in the following regions: China (Ulanqab), China (Heyuan), China (Guangzhou), Philippines (Manila), South Korea (Seoul), and Thailand (Bangkok).

  • Method 2 requires you to configure external storage. If your application is unstable, you can use this method to ensure that core files are captured. However, if a faulty application restarts repeatedly, a large number of core files can be generated.

Method 1: Execute a coredump O&M task

By using the Elastic Container Instance console, you can manually enable coredump O&M tasks.

  1. Log on to the Elastic Container Instance console.

  2. Enable coredump for the ECI instance.

    1. Click the ID of the target instance to open the instance details page.

    2. Click the O&M tab, select the Coredump tab, and then click Enable.

      After you enable coredump, the system generates an O&M task. If coredump has not been triggered, the task status is Pending.

  3. Trigger a coredump.

    Connect to the ECI instance. In the container, run the sleep 100 command and then press Ctrl+\ to trigger a coredump. The generated core file is automatically saved to OSS.

    # sleep 100
    ^\Quit (core dumped)
  4. Download the core file.

    After the coredump is triggered and the core file is generated, the status of the O&M task changes to Successful. Click Download in the Result column to download the core file.

    Note

    If the download does not start, check the site permission settings in your browser.

Method 2: Specify a path to store core files

Core files are used to analyze issues offline. In most cases, core files are stored on external storage devices instead of local storage of containers. This prevents loss of core files if containers terminate. Elastic Container Instance allows you to specify a path to store core files. After you specify a path, coredump is automatically enabled.

Important

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

The following code provides a sample configuration in which a network-attached storage (NAS) file system is used as an external storage.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: coredump-test
  labels:
    app: test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      name: nginx-test
      labels:
        app: nginx
        alibabacloud.com/eci: "true" 
      annotations:
        k8s.aliyun.com/eci-core-pattern: "/data/dump-a/core"    # Specify the path to store core files.
    spec:
      containers:
      - name: nginx
        image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
        ports:
        - containerPort: 80
        volumeMounts:
          - name: nas-volume
            mountPath: /data/dump-a/
      volumes:     # Mount a NAS file system.
        - name: nas-volume
          csi:
            driver: nasplugin.csi.alibabacloud.com
            fsType: nas
            volumeAttributes:
              server: "0389a***-nh7m.cn-shanghai.extreme.nas.aliyuncs.com"
              path: "/"
              vers: "3"
              options: "nolock,tcp,noresvport"

FAQ

The download does not start when I click Download in the console. What should I do?

If the download does not start, check the site permission settings in your browser. For example, in Chrome, follow these steps to grant the necessary permission:

  1. Click the lock icon to the left of the Chrome browser address bar, and in the popup panel, click Site settings.

  2. In the site permissions list, find Insecure content and set its permission to Allow.