All Documents
Current Document

Content is empty

If you don't find the content you expect, please try another search term

Documentation

Create images

Last updated:2021-08-04 11:26:30

You can create custom images based on instances that can run normally. The instances must be in the Running or Stopped state.

You can create custom images based on existing instances or snapshots. These images can be used to quickly replicate the system environment, saving the need of repeated configuration.

At present, 50 custom images are supported in each region.

Preparations

To ensure that a custom image can be used normally, you must fulfill the following tasks before you create the image:

  • To create a Linux image, you must delete or comment out the mount information you have added in the /etc/fstab configuration file, and retain only the mount information that comes with the system.

  • To create a Windows image, you must enable the DHCP ports (UDP 67 and UDP 68) on the Windows firewall by using the following commands:

    netsh advfirewall firewall set portopening udp 67 enable
    netsh advfirewall firewall set portopening udp 68 enable

    Or

    netsh firewall set portopening udp 67 enable
    netsh firewall set portopening udp 68 enable

Procedure

Create custom images from instances

  1. Log in to the KEC console. The Instance page appears by default.

  2. In the instance list, find the instance from which you want to create an image and choose More > Create Image in the Operation column.

  3. In the dialog box that appears, set the Instance Type parameter and add data disks based on your business requirements. Common images and local images are supported. The images are stored in different locations:

    • Common images: These images are stored in KS3, and can be created from local disks or EBS volumes.
    • Local images: These images are stored in EBS clusters and support quick startup. Local images support only instances that use EBS volumes as system disks.
  4. Enter the image name and then click OK.

After the image is created, you can view and manage the image on the Image page.

You can use a custom image to create an instance or reinstall the operating system. You can use a local image in the corresponding region to create only an instance that uses SSD EBS 3.0 as the system disk or reinstall the operating system for such an instance.

Create custom images from snapshots

  1. Log in to the KEC console. In the left navigation pane, choose Snapshot > Snapshot List.

  2. Find the snapshot from which you want to create an image and click Create Image in the Operation column. When you create an image, you can decide whether to add data disks based on your business requirements. If you select a local snapshot as the system disk snapshot, the type of data disk snapshots can only be local snapshot and the created custom image is a local image. If you select a common snapshot as the system disk snapshot, the type of data disk snapshots can only be common snapshot and the created custom image is a common image.

  3. Enter the image name and then click OK.

After the image is created, you can view and manage the image on the Image page.

You can use a custom image to create an instance or reinstall the operating system.

Create custom images by using Packer

Packer is a lightweight image tool that supports mainstream operating systems, such as Windows, Linux, and macOS. This section describes how to use Packer to create custom images.

  1. Install Packer.
  • Log in to a Linux KEC instance. For more information about how to log in to a Linux KEC instance, see Connect to instances.
  • Clone the Packer repository to the $GOPATH/src/github.com/kingsoftcloud/packer-plugin-ksyun directory. $ mkdir -p $GOPATH/src/github.com/kingsoftcloud; $ cd $GOPATH/src/github.com/kingsoftcloud $ git clone git@github.com:kingsoftcloud/packer-plugin-ksyun.git
  • Build and link to Packer. $ cd $GOPATH/src/github.com/kingsoftcloud/packer-plugin-ksyun $ make build $ln -s $GOPATH/bin/packer-plugin-ksyun ~/.packer.d/plugins/packer-plugin-ksyun
  1. Define a Packer template.

To use Packer to create a custom image, you must create a template file in the JSON format. In the template file, you must specify the builder and provisioner for creating the custom image.

The following is a sample template file, which can be found in the example directory.

{
  "variables": {
    "access_key": "{{ env `KSYUN_ACCESS_KEY` }}",
    "secret_key": "{{ env `KSYUN_SECRET_KEY` }}"
  },
  "builders": [{
    "type":"ksyun-kec",
    "access_key":"{{user `access_key`}}",
    "secret_key":"{{user `secret_key`}}",
    "region":"cn-shanghai-2",
    "image_name":"packer_test",
    "source_image_id":"IMG-dd1f8324-1f27-46e0-ad6b-b41d8c8ff025",
    "instance_type":"N3.1B",
    "ssh_username":"root",
    "associate_public_ip_address": true
  }],
  "provisioners": [{
    "type": "shell",
    "inline": [
      "sleep 30",
      "yum install mysql -y"
    ]
  }]
}

The following table describes the parameters that you need to customize.

Parameter Description
access_key Your AccessKey ID.
secret_key Your AccessKey secret.
region The region of temporary resources that are used to create the custom image.
image_name The name of the custom image.
source_image_id The ID of the base image.
instance_type The type of the temporary instance that is created when you create the custom image.
provisioners The Packer provisioner that is used to create the custom image.
  1. Use Packer to create the custom image.
  • Import your AccessKey ID. export KSYUN_ACCESS_KEY=<Your AccessKey ID>
  • Import your AccessKey secret. export KSYUN_SECRET_KEY=<Your AccessKey secret>
  • Use Packer to create the custom image. packer build example/ksyun.json
On this page
Pure ModeNormal Mode

Pure Mode

Click to preview the document content in full screen
Feedback