Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Yandex Compute Cloud
  • Getting started
    • Overview
    • Creating a Linux VM
    • Creating a Windows VM
    • Creating instance groups
  • Step-by-step instructions
    • All instructions
    • Creating VMs
      • Creating a Linux VM
      • Creating a Windows VM
      • Creating a VM from a set of disks
      • Creating a VM with disks from snapshots
      • Creating a VM from a custom image
      • Creating a VM with a GPU
      • Making a VM preemptible
    • DSVM
      • Overview
      • Creating a VM from a public DSVM image
    • Placement groups
      • Creating a placement group
      • Deleting a placement group
      • Creating a VM in a placement group
      • Adding a VM to a placement group
      • Removing a VM from a placement group
    • Images with pre-installed software
      • Creating a VM from a public image
      • Configuring software
      • Running a VM based on a public image
      • Getting a list of public images
    • Getting information about a VM
      • Getting information about a VM
      • Getting serial port's output
    • Managing VMs
      • Stopping and starting a VM
      • Resetting a VM user password
      • Attaching a disk to a VM
      • Detaching a disk from a VM
      • Moving a VM to a different availability zone
      • Moving a VM to another folder
      • Attaching a public IP address to a VM
      • Detaching a public IP address from a VM
      • Making a VM's public IP address static
      • Updating a VM
      • Changing VM computing resources
      • Deleting a VM
    • Working on VMs
      • Connecting to a VM via SSH
      • Connecting to a VM via RDP
      • Connecting to a VM via PowerShell
      • Working with Yandex Cloud from inside a VM
      • Installing NVIDIA drivers
      • Restoring access to a VM
    • Managing the password reset agent
      • Verifying agent operation
      • Installing the agent
      • Deleting the agent
    • Creating new disks
      • Creating an empty disk
      • Creating an empty disk with a large block
      • Creating a non-replicated disk
    • Disk management
      • Creating a disk snapshot
      • Updating a disk
      • Moving a disk to another folder
      • Deleting a disk
      • Deleting a disk snapshot
    • Disk placement groups
      • Creating a disk placement group
      • Removing a disk from a placement group
    • Creating new images
      • Preparing a disk image
      • Uploading your image
      • Creating an image from a disk
      • Creating an image from a snapshot
      • Creating an image from other custom image
    • Managing images
      • Getting a list of images
      • Deleting a disk image
    • File storage
      • Creating file storage
      • Attaching file storage to a VM
      • Detaching file storage from a VM
      • Updating file storage
      • Deleting file storage
    • Managing the serial console
      • Getting started
      • Connecting to a serial console via SSH
      • Connecting to a serial console via CLI
      • Starting your terminal in the Windows serial console (SAC)
      • Disabling access to the serial console
    • Creating instance groups
      • Creating a fixed-size instance group
      • Creating a fixed-size instance group with a network load balancer
      • Creating a fixed-size instance group with an L7 load balancer
      • Creating an automatically scaled instance group
      • Creating an instance group from a Container Optimized Image
      • Creating an instance group based on the YAML specification
    • Getting information about instance groups
      • Getting a list of instance groups
      • Getting information about an instance group
      • Getting a list of instances in a group
    • Managing instance groups
      • Editing an instance group
      • Edit an instance group based on the YAML specification
      • Configuring application health check on the VM
      • Updating a group
        • Incremental update
        • Uninterrupted updates
      • Pausing an instance group
      • Resuming an instance group
      • Stopping an instance group
      • Starting an instance group
      • Deleting an instance group
    • Dedicated hosts
      • Creating a VM in a group of dedicated hosts
      • Creating a VM on a dedicated host
  • Yandex Container Solution
  • Practical guidelines
    • Configuring NTP time synchronization
    • Running instance groups with auto scaling
    • Automatically scaling an instance group for handling messages from a queue
    • Updating an instance group under load
    • Deploying Remote Desktop Gateway
    • Transferring logs from a VM instance to Yandex Cloud Logging
    • Creating a VM backup with Hystax Acura Backup
  • Concepts
    • Relationship between resources
    • Virtual machines
      • Overview
      • Platforms
      • vCPU performance levels
      • Preemptible VMs
      • Network on a VM
      • Software-accelerated network
      • Live migration
      • Placement groups
      • Statuses
      • Metadata
      • Resetting a Windows VM password
    • Graphics accelerators
    • Disks and file storage
      • Overview
      • Disks
      • Disk snapshots
      • Non-replicated disk placement groups
      • File storage
      • Read and write operations
    • Images
    • Instance groups
      • Overview
      • Access
      • YAML specification
      • Instance template
      • Variables in an instance template
      • Policies
        • Overview
        • Allocation policy
        • Deployment policy
        • Scaling policy
      • Scaling types
      • Auto-healing
      • Updating
        • Overview
        • Allocating instances across zones
        • Deployment algorithm
        • Rules for updating virtual machines
        • Changing secondary disks in an instance template
      • Stopping and pausing an instance group
      • Statuses
    • Dedicated host
    • Backups
    • Quotas and limits
  • Access management
  • Pricing policy
    • Current pricing policy
    • Archive
      • Before January 1, 2019
      • From January 1 to March 1, 2019
      • From March 1 to May 1, 2019
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • DiskPlacementGroupService
      • DiskService
      • DiskTypeService
      • FilesystemService
      • HostGroupService
      • HostTypeService
      • ImageService
      • InstanceService
      • PlacementGroupService
      • SnapshotScheduleService
      • SnapshotService
      • ZoneService
      • InstanceGroupService
      • OperationService
    • REST
      • Overview
      • DiskPlacementGroup
        • Overview
        • create
        • delete
        • get
        • list
        • listDisks
        • listOperations
        • update
      • Disk
        • Overview
        • create
        • delete
        • get
        • list
        • listOperations
        • move
        • update
      • DiskType
        • Overview
        • get
        • list
      • Filesystem
        • Overview
        • create
        • delete
        • get
        • list
        • listOperations
        • update
      • HostGroup
        • Overview
        • create
        • delete
        • get
        • list
        • listHosts
        • listInstances
        • listOperations
        • update
      • HostType
        • Overview
        • get
        • list
      • Image
        • Overview
        • create
        • delete
        • get
        • getLatestByFamily
        • list
        • listOperations
        • update
      • Instance
        • Overview
        • addOneToOneNat
        • attachDisk
        • attachFilesystem
        • create
        • delete
        • detachDisk
        • detachFilesystem
        • get
        • getSerialPortOutput
        • list
        • listOperations
        • move
        • removeOneToOneNat
        • restart
        • start
        • stop
        • update
        • updateMetadata
        • updateNetworkInterface
      • PlacementGroup
        • Overview
        • create
        • delete
        • get
        • list
        • listInstances
        • listOperations
        • update
      • SnapshotSchedule
        • Overview
        • create
        • delete
        • disable
        • enable
        • get
        • list
        • listDisks
        • listOperations
        • listSnapshots
        • update
        • updateDisks
      • Snapshot
        • Overview
        • create
        • delete
        • get
        • list
        • listOperations
        • update
      • Zone
        • Overview
        • get
        • list
      • Operation
        • Overview
        • get
      • InstanceGroup
        • Overview
        • list
        • get
        • listLogRecords
        • updateFromYaml
        • updateAccessBindings
        • pauseProcesses
        • stop
        • start
        • delete
        • listInstances
        • createFromYaml
        • update
        • setAccessBindings
        • listOperations
        • create
        • listAccessBindings
        • resumeProcesses
  • Questions and answers
    • General questions
    • Virtual machines
    • Connection
    • Disks, snapshots, and images
    • Disaster recovery
    • Monitoring
    • Licensing
    • All questions on the same page
  1. Step-by-step instructions
  2. Creating instance groups
  3. Creating an instance group from a Container Optimized Image

Creating an instance group with a Container Optimized Image

Written by
Yandex Cloud

    To run multiple instances of the service in Docker containers, you can create an instance group from a Container Optimized Image. In such groups, you can update Docker containers with VM metadata using the COI or Docker Compose specification.

    Alert

    When creating instance groups, keep the limits in mind. Not to disrupt the component Instance Groups, do not update or delete manually created resources: target group Network Load Balancer, VMs, and disks. Instead of this, change or delete the entire group.

    By default, all operations in Instance Groups are performed on behalf of a service account. If you don't have a service account, create one.

    To create an instance group based on a Container Optimized Image:

    1. If you don't have the Yandex Cloud command line interface yet, install and initialize it.

    2. The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name or --folder-id parameter.

    3. View a description of the CLI command to create an instance group:

      CLI
      yc compute instance-group create --help
      
    4. Check whether there are networks in the folder:

      CLI
      yc vpc network list
      

      If there aren't any, create one.

    5. Create a YAML file with a name like specification.yaml.

    6. Find out the ID of the latest version of the public Container Optimized Image.

      The Container Optimized Image in the Yandex Container Registry can be updated and changed according to releases. This will not automatically update the VM image to the latest version. To create an instance group with the latest Container Optimized Image version, you need to check whether it's available yourself:

      CLI
      Marketplace
      yc compute image get-latest-from-family container-optimized-image --folder-id standard-images
      

      Result:

      id: <ID of latest COI version>
      folder_id: standard-images
      ...
      
      1. Go to the page Cloud Marketplace and select the image with the desired configuration:
        • Container Optimized Image.
        • Container Optimized Image GPU.
      2. Under Product IDs, copy the value of image_id.
    7. In the specification.yaml file you created, specify the following:

      • General information about the group:

        name: container-optimized-group
        service_account_id: aje3932acd8avp6edhbt
        description: "This instance group was created from YAML config."
        

        Where:

        • name: An arbitrary name of the instance group. The name must be unique within the folder. The name may contain lowercase Latin letters, numbers, and hyphens. The first character must be a letter. The last character can't be a hyphen. The maximum length of the name is 63 characters.
        • service_account_id: Service account ID.
        • description: A description of the instance group.
      • Instance template:

        instance_template:
          platform_id: standard-v3
          resources_spec:
            memory: 2G
            cores: 2
          boot_disk_spec:
            mode: READ_WRITE
            disk_spec:
              image_id: <ID of latest COI version>
              type_id: network-hdd
              size: 32G
          network_interface_specs:
            - network_id: c64mknqgnd8avp6edhbt
              primary_v4_address_spec: {}
          metadata:
            docker-container-declaration: |-
              spec:
                containers:
                  - name: nginx
                    image: cr.yandex/mirror/nginx:1.17.4-alpine
                    securityContext:
                      privileged: false
                    tty: false
                    stdin: false
        

        The disk size is specified in bytes by default. You can specify a different unit of measurement using the applicable suffix.

        Suffix Prefix and multiplier Example
        k kilo- (210) 640k = 640 × 210 = 655360
        m mega- (220) 48m = 48 × 220 = 50331648
        g giga- (230) 10g = 10 × 230 = 10737418240
        t tera- (240) 4t = 4 × 240 = 4398046511104
        p peta- (250) 2p = 2 × 250 = 2251799813685248

        Where:

        • platform_id: Platform ID.
        • memory: Amount of RAM.
        • cores: Number of processor cores (vCPUs).
        • mode: Disk access mode:
          • READ_ONLY: Read-only access.
          • READ_WRITE: Read/write access.
        • image_id: ID of the public Container Optimized Image.
        • type_id: Disk type.
        • size: Disk size.
        • network_id: ID of default-net.
        • primary_v4_address_spec: IPv4 specification. Only IPv4 is currently available. You can grant public access to the group's instances by specifying the IP version for a public IP address.
        • metadata: Values to pass to the VM metadata.
        • docker-container-declaration: Key in the VM metadata that is used with the COI specification of the Docker container. In the metadata, you can use the Docker Compose specification. To do this, specify the docker-compose key instead of the docker-container-declaration key.
      • Policies:

        deploy_policy:
          max_unavailable: 1
          max_expansion: 0
        scale_policy:
          fixed_scale:
            size: 3
        allocation_policy:
          zones:
            - zone_id: ru-central1-a
        

        Where:

        • deploy_policy: Deployment policy for instances in the group.
        • scale_policy: Scaling policy for instances in the group.
        • allocation_policy: Allocation policy of the instances by zone and region.

        Full code for the specification.yaml file:

        name: container-optimized-group
        service_account_id: aje3932acd8avp6edhbt
        description: "This instance group was created from YAML config."
        instance_template:
          service_account_id: aje3932acd8avp6edhbt # ID of the service account to access private Docker images.
          platform_id: standard-v3
          resources_spec:
            memory: 2G
            cores: 2
          boot_disk_spec:
            mode: READ_WRITE
            disk_spec:
              image_id: <ID of latest COI version>
              type_id: network-hdd
              size: 32G
          network_interface_specs:
            - network_id: c64mknqgnd8avp6edhbt
              primary_v4_address_spec: {}
          metadata:
            docker-container-declaration: |-
              spec:
                containers:
                  - name: nginx
                    image: cr.yandex/mirror/nginx:1.17.4-alpine
                    securityContext:
                      privileged: false
                    tty: false
                    stdin: false
        deploy_policy:
          max_unavailable: 1
          max_expansion: 0
        scale_policy:
          fixed_scale:
            size: 3
        allocation_policy:
          zones:
            - zone_id: ru-central1-a
        

        Note

        To use in specification.yaml the Docker Compose specification, specify the docker-compose key instead of the docker-container-declaration key.

    8. Create an instance group in the default folder:

      CLI
      yc compute instance-group create --file specification.yaml
      

      This command creates a group of three similar instances with the following characteristics:

      • Named container-optimized-group.
      • From the latest version of the public Container Optimized Image.
      • With a running Docker container based on cr.yandex/mirror/nginx:1.17.4-alpine.
      • In the default-net network.
      • In the ru-central1-a availability zone.
      • With 2 vCPUs and 2 GB of RAM.
      • With a 32 GB network HDD.

    Was the article helpful?

    Language / Region
    © 2022 Yandex.Cloud LLC