# Preparing a Chart

You can prepare a chart using one of the following methods:

- Customizing a Chart
- Using a Kubernetes Official Chart

#### Customizing a Chart

1. Customize the content of a chart as required.

   For details about how to create a chart, see https://helm.sh/docs/chart_template_guide/getting_started/.

2. Set the chart directory structure and name the chart based on the requirements defined in Chart Specifications.

#### Using a Kubernetes Official Chart

1. Visit https://artifacthub.io/ to obtain the required chart.
2. Log in to a Linux host.
3. Upload the chart obtained in 1.
4. Run the following command to compress the chart.

   - If the Helm client is not installed on the Linux host, run the following command:

     tar pzcf {name}-{version}.tgz {name}/

     In the preceding command,

     {name} indicates the actual chart name.

     {version} indicates the actual chart version.

     The values of {name} and {version} must be the same as the values of name and version in the Chart.yaml file in the chart.

   - If the Helm client is installed on the Linux host, run the following command:

     helm package {name}/

     In the preceding command, replace {name} with the actual chart name.

5. Set the chart directory structure and name the chart based on the requirements defined in Chart Specifications.

#### Chart Specifications

This section uses the redis chart as an example to illustrate the chart specifications.

- Naming Requirement

  A chart package is named in the format of {name}-{version}.tgz, where {version} indicates the version number in the format of Major version number.Minor version number.Revision number, for example, redis-0.4.2.tgz.

  The chart name {name} can contain a maximum of 64 characters.

  The version number must comply with the semantic versioning rules.

  - The main and minor version numbers are mandatory, and the revision number is optional.
  - The major and minor version numbers and revision number must be integers, greater than or equal to 0, and less than or equal to 99.
- Directory Structure

  The directory structure of a chart is as follows:

      redis/
        templates/
        values.yaml
        README.md
        Chart.yaml
        .helmignore

  As listed in Table 1, the parameters marked with * are mandatory.

  Table 1 Parameters in the directory structure of a chart
  Parameter | Description
  --- | ---
  * templates | Stores all templates.

  * values.yaml

  Describes configuration parameters required by templates.

  NOTICE:

  Make sure that the image address set in the values.yaml file is the same as the image address in the container image repository. Otherwise, an exception occurs when you create a workload, and the system displays a message indicating that the image fails to be pulled.

  To obtain the image address, perform the following operations: Log in to the CCE console. In the navigation pane, choose Image Repository to access the SWR console. Choose My Images > Private Images and click the name of the uploaded image. On the Image Tags tab page, obtain the image address from the pull command. You can click to copy the command in the Image Pull Command column.

  README.md

  A markdown file, including:
  - The workload or services provided by the chart.
  - Prerequisites for running the chart.
  - Configurations in the values.yaml file.
  - Information about chart installation and configuration.

  * Chart.yaml | Basic information about the chart.
  .helmignore | Files or data that does not need to read templates during workload installation.

Parent topic: My Charts