Alibaba Cloud provides the ImageCache feature of Elastic Container Instance by using the ImageCache CustomResourceDefinition (CRD). This way, you can use the ImageCache feature of Elastic Container Instance to accelerate the creation of Elastic Container Instance-based pods in Kubernetes. This topic describes ImageCaches and how to create, query, and delete an ImageCache.
Make preparations
Log on to your Kubernetes cluster and run the following command to check whether the Kubernetes cluster supports ImageCaches:
kubectl get crd/imagecaches.eci.alibabacloud.com
If an error is returned, the cluster does not support ImageCaches. Sample output:
Error from server (NotFound): customresourcedefinitions.apiextensions.k8s.io "imagecaches.eci.alibabacloud.com" not found
If your cluster does not support ImageCaches, update the ack-virtual-node component to a version that supports ImageCaches.
NoteWe recommend that you update the ack-virtual-node component to the latest version to use new features.
For information about the versions of ack-virtual-node, see ack-virtual-node.
For information about how to update ack-virtual-node, see Manage system components.
If information about imagecaches.eci.alibabacloud.com is returned, your Kubernetes cluster supports ImageCaches. Sample output:
NAME CREATED AT imagecaches.eci.alibabacloud.com 2024-01-23T05:54:44Z
If the ImageCache CRD in your cluster is not of the latest version, we recommend that you run the
kubectl apply
command to update the ImageCache CRD to the latest version.kubectl apply -f imagecache-crd-sample.yaml
Configure an ImageCache
The following code provides the YAML configuration file of an ImageCache. For more information, see Kubernetes ImageCache API.
apiVersion: eci.alibabacloud.com/v1
kind: ImageCache
metadata:
name: imagecache-sample
annotations:
k8s.aliyun.com/imc-enable-reuse: "true" # Enables the ImageCache reuse feature.
spec:
images:
- centos:latest
- busybox:latest
imagePullSecrets:
- default:secret1
- default:secret2
- kube-system:secret3
imageCacheSize:
25
retentionDays:
7
Parameter description:
Parameter | Type | Required | Description |
spec.images | String[] | Yes | The container images that can be used to create the ImageCache. |
spec.imagePullSecrets | String[] | No | The secrets of private image repositories.
|
spec.imageCacheSize | int | No | The size of the ImageCache. Unit: GiB. Default value: 20. Valid values: 20 to 32768. |
spec.retentionDays | int | No | The retention period of the ImageCache. When the specified retention period ends, the ImageCache is deleted. Unit: days. This parameter is left empty by default, which indicates that the ImageCache never expires. |
You can add annotations to the YAML configuration file of the ImageCache to make full use of the ImageCache feature. For example, in the preceding YAML file, the k8s.aliyun.com/imc-enable-reuse: "true"
annotation is added to enable the ImageCache reuse feature. For more information, see ImageCache annotations.
Create an ImageCache
Create an ImageCache.
kubectl create -f imagecache-test.yaml
Sample imagecache-test.yaml file:
apiVersion: eci.alibabacloud.com/v1 kind: ImageCache metadata: name: imagecache-sample-test annotations: k8s.aliyun.com/imc-enable-reuse: "true" # Enables the ImageCache reuse feature. spec: images: - registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2 - registry.cn-shanghai.aliyuncs.com/eci_open/busybox:1.30 imageCacheSize: 25 retentionDays: 7
View the status of the ImageCache.
kubectl get imagecache imagecache-sample-test
The following sample code provides a sample output. If the ImageCache is in the Ready state, the ImageCache is created and can be used.
NAME AGE CACHEID PHASE PROGRESS imagecache-sample-test 5m30s imc-2ze2kbf9l1onf03z**** Ready 100%
Query an ImageCache
You can query details about an ImageCache or the ImageCache list in a cluster.
Query the ImageCache list in a cluster
kubectl get imagecache
Query details about an ImageCache
kubectl get imagecache <imagecache-name> -o yaml
Delete an ImageCache
An ImageCache is a snapshot. If you want to retain an ImageCache that you manually created, you must pay the snapshot cost. If you no longer use the ImageCache, we recommend that you manually delete it in a timely manner.
If you want to delete an ImageCache, run the following command:
kubectl delete imagecache <imagecache-name>