ImageCache Annotation
In Kubernetes scenarios, the ImageCache custom resource definition (CRD) enables the image cache feature of Elastic Container Instance (ECI) to accelerate pod creation. Add the annotations listed below, each with a configuration example, to get the full benefit of image caching when creating an ImageCache.
List of ImageCache annotations
The following table lists the annotations that ImageCache supports:
|
Parameter |
Sample value |
Description |
Configuration example |
|
k8s.aliyun.com/vswitch-ids |
"vsw-bp1dktddjsg5nktv****,vsw-bp1xpiowfm5vo8o3c****" |
Specifies the vSwitch. Multiple vSwitches can be specified to enable the multi-zone feature. If this parameter is not specified, the vSwitch configured in eci-profile is used by default. |
|
|
k8s.aliyun.com/imc-cpu-arch |
"arm64" |
Specifies the CPU architecture. Valid values:
|
|
|
k8s.aliyun.com/imc-os-type |
"windows" |
Specifies the operating system. Valid values:
|
|
|
k8s.aliyun.com/security-group-id |
"sg-bp1dktddjsg5nktv****" |
Specifies the security group. If this parameter is not specified, the security group configured in eci-profile is used by default. |
|
|
k8s.aliyun.com/resource-group-id |
"rg-aek2z3elfs4****" |
Specifies the resource group. If this parameter is not specified, the resource group configured in eci-profile is used by default. |
|
|
k8s.aliyun.com/acr-instance-ids |
"cri-j36zhodptmyq****" |
Specifies a Container Registry (ACR) Enterprise instance, which is used to pull images without a password. A cross-region ACR Enterprise instance is also supported. When you specify a cross-region instance, add the region to which the instance belongs before the instance ID. For example: |
|
|
k8s.aliyun.com/acr-service-arns |
acs:ram::1609982529******:role/role-assume |
The Alibaba Cloud Resource Name (ARN) of the Resource Access Management (RAM) role under the account to which the ECI resources belong. This parameter must be configured when you specify a RAM role to create resources. |
|
|
k8s.aliyun.com/acr-user-arns |
acs:ram::1298452580******:role/role-acr |
The ARN of the RAM role under the account to which the ACR instance belongs. This parameter must be configured when you pull ACR images across accounts. |
|
|
k8s.aliyun.com/plain-http-registry |
"harbor***.pre.com,192.168.XX.XX:5000,reg***.test.com:80" |
Specifies the address of the self-managed image repository. To create an ImageCache from an image in a self-managed image repository that uses HTTP, configure this parameter so that ECI pulls the image over HTTP. This prevents image pull failures caused by a protocol mismatch. |
|
|
k8s.aliyun.com/insecure-registry |
"harbor***.pre.com,192.168.XX.XX:5000,reg***.test.com:80" |
Specifies the address of the self-managed image repository. To create an ImageCache from an image in a self-managed image repository that uses a self-signed certificate, configure this parameter to skip certificate verification. This prevents image pull failures caused by certificate verification errors. |
|
|
k8s.aliyun.com/imc-enable-reuse |
"true" |
Specifies whether to enable image cache reuse. After this feature is enabled, a newly created image cache can reuse the image layers of an existing image cache, which speeds up image cache creation. |
|
|
k8s.aliyun.com/imc-enable-flash |
"true" |
Specifies whether to enable the instant image cache feature. After this feature is enabled, a local snapshot is temporarily created, which shortens the time required to create the image cache. |
|
|
k8s.aliyun.com/imc-retention-days |
"7" |
Sets the retention period of the image cache. Unit: days. Expired image caches are automatically cleaned up. By default, an image cache never expires. |
|
|
k8s.aliyun.com/imc-size |
"25" |
Sets the size of the image cache. Default value: 20 GiB. Valid values: 20 to 32768 GiB. |
|
|
k8s.aliyun.com/eip-instance-id |
"eip-bp1q5n8cq4p7f6dzu****" |
Binds an Elastic IP Address (EIP). If no NAT gateway is configured, you can bind an existing EIP to pull images from the Internet. |
|
|
k8s.aliyun.com/auto-create-eip |
"true" |
Specifies whether to automatically create and bind an EIP. If no NAT gateway is configured, an EIP can be automatically created and bound to pull images from the Internet. |
|
|
k8s.aliyun.com/eip-bandwidth |
"5" |
Specifies the bandwidth of the EIP when an EIP is automatically created. Unit: Mbps. |
|
|
k8s.aliyun.com/eip-internet-charge-type |
PayByBandwidth |
Specifies the metering method of the EIP when an EIP is automatically created. Valid values:
|
|
|
k8s.aliyun.com/eip-isp |
BGP |
Specifies the line type of the EIP when an EIP is automatically created. Only pay-as-you-go EIPs support this parameter. Valid values:
|
|
|
k8s.aliyun.com/eip-common-bandwidth-package-id |
"cbwp-2zeukbj916scmj51m****" |
Specifies a shared bandwidth package. |
Create resources across multiple zones
When an ImageCache is created, the system temporarily creates an ECI instance that serves as an intermediary for creating the ImageCache. To avoid the impact of ECI instance resource inventory and to ensure that the ImageCache is created, you can specify multiple vSwitches to enable the multi-zone feature.
When you create an ImageCache, the vSwitch information of the cluster or virtual node is used by default. If the cluster or virtual node is already configured with multiple zones, you do not need to specify this parameter.
apiVersion: eci.alibabacloud.com/v1
kind: ImageCache
metadata:
name: imagecache-sample
annotations:
k8s.aliyun.com/vswitch-ids: "vsw-bp1dktddjsg5nktv****,vsw-bp1xpiowfm5vo8o3c****" # Specify multiple vSwitches
spec:
images:
- centos:latest
- busybox:latest
imageCacheSize:
25
retentionDays:
7
Specify the CPU architecture
When you pull an image of the Arm architecture to create an ImageCache, you must specify the CPU architecture.
If you specify the CPU architecture as Arm, make sure that a virtual node of the Arm architecture already exists in the cluster. For more information, see Schedule pods to ARM-based virtual nodes.
apiVersion: eci.alibabacloud.com/v1
kind: ImageCache
metadata:
name: imagecache-sample
annotations:
k8s.aliyun.com/imc-cpu-arch: "arm64" # Set the CPU architecture to Arm
spec:
images:
- arm64v8/centos:7.9.2009 # Use a container image based on the Arm architecture
imageCacheSize:
25
retentionDays:
7
Specify the operating system
When you pull a Windows image to create an ImageCache, you must specify the operating system.
If you specify the operating system as Windows, make sure that a Windows virtual node already exists in the cluster. For more information, see (Invitational preview) Schedule Pods to Windows virtual nodes.
apiVersion: eci.alibabacloud.com/v1
kind: ImageCache
metadata:
name: imagecache-sample
annotations:
k8s.aliyun.com/imc-os-type: "windows" # Set the operating system to Windows
spec:
images:
- mcr.microsoft.com/windows/nanoserver:ltsc2022 # Use a Windows container image
imageCacheSize:
25
retentionDays:
7
Set the security group and resource group
When you create an ImageCache, the security group and resource group configured in eci-profile are used by default. If you have special requirements, you can specify the security group and resource group.
apiVersion: eci.alibabacloud.com/v1
kind: ImageCache
metadata:
name: imagecache-sample
annotations:
k8s.aliyun.com/security-group-id: "sg-bp1dktddjsg5nktv****" # Specify the security group
k8s.aliyun.com/resource-group-id: "rg-aek2z3elfs4****" # Specify the resource group
spec:
images:
- centos:latest
- busybox:latest
imageCacheSize:
25
retentionDays:
7
Pull ACR images without a password
Whether you can pull ACR images without a password depends on whether the ACR instance belongs to the same Alibaba Cloud account as the ImageCache to be created. It also depends on the ACR instance type:
|
Account scenario |
ACR type |
Support |
|
Same-account |
|
Enabled by default. You can configure a RAM role to restrict the scope of secret-free access. |
|
Same-account |
Enterprise Edition (custom domain name) |
Not enabled by default. You must specify the ACR instance to enable secret-free access. |
|
Cross-account |
|
Not enabled by default. You must configure a RAM role to enable secret-free access. |
For configuration details, see Pull ACR images without a password.
Use a self-managed image repository
To create an ImageCache from an image in a self-managed image repository that uses HTTP or a self-signed certificate, you must configure the relevant annotations to prevent image pull failures.
-
The self-managed image repository uses the HTTP protocol
Because ECI pulls images over HTTPS by default, you must configure
k8s.aliyun.com/plain-http-registrywhen you create an ImageCache so that ECI interacts with the image repository over HTTP.apiVersion: eci.alibabacloud.com/v1 kind: ImageCache metadata: name: imagecache-sample annotations: k8s.aliyun.com/plain-http-registry: "192.168.XX.XX:5000" # Specify the address of the self-managed image repository and pull images over HTTP spec: images: - 192.168.XX.XX:5000/test/nginx:latest imagePullSecrets: - default:secret1 - default:secret2 - kube-system:secret3 imageCacheSize: 25 retentionDays: 7 -
The self-managed image repository uses a self-signed certificate
When a self-signed certificate is used, image pulls cannot pass certificate verification. You must configure
k8s.aliyun.com/insecure-registryto skip certificate verification.apiVersion: eci.alibabacloud.com/v1 kind: ImageCache metadata: name: imagecache-sample annotations: k8s.aliyun.com/insecure-registry: "harbor***.pre.com" # Specify the address of the self-managed image repository and skip certificate verification when pulling images spec: images: - harbor***.pre.com/test/nginx:latest imagePullSecrets: - default:secret1 - default:secret2 - kube-system:secret3 imageCacheSize: 25 retentionDays: 7
-
If images for multiple containers must be pulled from different image repositories, you can specify multiple image repository addresses separated by commas (,). For example:
harbor***.pre.com,192.168.XX.XX. -
If the image repository address includes a port number, you must include the port number. For example, if the image address is
192.168.XX.XX:5000/nginx:latest, set the value of the annotation to192.168.XX.XX:5000.
Enable image cache reuse
The time required to create an ImageCache depends on multiple factors, such as the image size and the network. To speed up ImageCache creation, you can enable the image cache reuse feature.
After image cache reuse is enabled, the system automatically matches existing ImageCaches when an ImageCache is created. If the new ImageCache has image layers that duplicate those of an existing ImageCache, the new ImageCache reuses those layers. This accelerates ImageCache creation.
apiVersion: eci.alibabacloud.com/v1
kind: ImageCache
metadata:
name: imagecache-sample
annotations:
k8s.aliyun.com/imc-enable-reuse: "true" # Enable image cache reuse
spec:
images:
- centos:latest
- busybox:latest
imageCacheSize:
25
retentionDays:
7
Enable the instant image cache
The time required to create an ImageCache depends on multiple factors, such as the image size and the network. To shorten the creation time, you can enable the instant image cache feature.
After the instant image cache is enabled, the system temporarily creates a local snapshot when an ImageCache is created. The local snapshot is created quickly based on the instant availability feature of snapshots, and the ImageCache is ready to use as soon as the snapshot is created.
After the local snapshot is created, the system automatically begins to create a standard snapshot. During this time, the image cache is backed by the local snapshot. After the standard snapshot is ready, the system automatically deletes the local snapshot, and the image cache is then backed by the standard snapshot.
apiVersion: eci.alibabacloud.com/v1
kind: ImageCache
metadata:
name: imagecache-sample
annotations:
k8s.aliyun.com/imc-enable-flash: "true" # Enable the instant image cache
spec:
images:
- centos:latest
- busybox:latest
imageCacheSize:
25
retentionDays:
7
Set the size and retention period of an image cache
By default, a manually created ImageCache is 20 GiB in size and is retained indefinitely after creation. In addition to the imageCacheSize and retentionDays parameters in spec, you can also use annotations to customize the size and retention period of an ImageCache.
apiVersion: eci.alibabacloud.com/v1
kind: ImageCache
metadata:
name: imagecache-sample
annotations:
k8s.aliyun.com/imc-retention-days: "7" # Set the retention period of the image cache
k8s.aliyun.com/imc-size: "25" # Set the size of the image cache
spec:
images:
- centos:latest
- busybox:latest
Configure an EIP to pull images from the Internet
An EIP is a public IP address resource that can be purchased and held independently. When an EIP is bound to a cloud resource, the cloud resource can communicate with the Internet through the EIP. For more information about EIPs, see Elastic IP Address.
When you create an ImageCache, if you need to pull images from the Internet, make sure that the current network can connect to the Internet. Connect to the Internet by configuring a NAT gateway or an EIP. If your VPC is not bound to a NAT gateway, configure an EIP to pull images from the Internet. Two configuration methods are available:
When an ImageCache is created, the system temporarily creates an intermediary ECI instance, and the EIP is bound to that ECI instance. After the ImageCache is created, a pre-existing EIP is retained, and an automatically created EIP is released together with the ECI instance.
-
Bind an existing EIP
apiVersion: eci.alibabacloud.com/v1 kind: ImageCache metadata: name: imagecache-sample annotations: k8s.aliyun.com/eip-instance-id: "eip-bp1q5n8cq4p7f6dzu****" # Bind an existing EIP spec: images: - centos:latest - busybox:latest imageCacheSize: 25 retentionDays: 7 -
Automatically create and bind an EIP
apiVersion: eci.alibabacloud.com/v1 kind: ImageCache metadata: name: imagecache-sample annotations: k8s.aliyun.com/auto-create-eip: "true" # Automatically create and bind an EIP k8s.aliyun.com/eip-bandwidth: "10" # Set the bandwidth of the EIP. Unit: Mbps k8s.aliyun.com/eip-internet-charge-type: PayByBandwidth # Set the metering method of the EIP k8s.aliyun.com/eip-common-bandwidth-package-id: "cbwp-2zeukbj916scmj51m****" # Use a shared bandwidth package spec: images: - centos:latest - busybox:latest imageCacheSize: 25 retentionDays: 7