最近更新时间:2025-06-09 14:54:39
本文主要介绍通过 Kubernetes CustomResourceDefinition(CRD)的方式创建和管理 KCI 镜像缓存的方法。
已创建KCE集群,并安装v1.7.4及以上版本的vk(虚拟节点);
vk配置文件中imageCacheEnable: flase参数已设置为imageCacheEnable: true。
1.创建Imagecache对应的CRD,实例yaml文件imagecache-crd.yaml如下:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: imagecaches.kci.io
spec:
group: kci.io
names:
plural: imagecaches
singular: imagecache
kind: ImageCache
shortNames:
- icache
scope: Namespaced
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
cacheId:
type: string
description: Unique identifier of the image cache
subnetId:
type: string
description: Subnet ID used to create the container instance for the image cache
securityGroupId:
type: string
description: Security group ID used to create the container instance for the image cache
images:
type: array
description: Container images used to create the image cache, range [1,20]
items:
type: string
imageRegistryCredential:
type: array
description: Credentials for accessing private image registries
items:
type: object
properties:
server:
type: string
description: Image registry server
username:
type: string
description: Username
password:
type: string
description: Password
imageCacheType:
type: string
description: Type of image cache, Common or Rapid. Default is Common
enum:
- Common
- Rapid
imageCacheSize:
type: integer
description: Size of the image cache in GB
retentionDays:
type: integer
description: Retention period of the image cache in days. Default is unlimited
enableWarm:
type: boolean
description: Whether to warm up the cache. Only valid when imageCacheType is Common. Default is false
status:
type: object
properties:
phase:
type: string
description: Status of the image cache. Creating, Ready, Deleting, Deleted
subresources:
status: {}
additionalPrinterColumns:
- name: CacheID
type: string
description: Unique identifier of the image cache
jsonPath: .spec.cacheId
- name: Phase
type: string
description: Status of the image cache
jsonPath: .status.phase
- name: Age
type: date
description: Creation timestamp of the resource
jsonPath: .metadata.creationTimestamp2.创建以下命令,创建Imagecache CRD。
kubectl create -f imagecache-crd.yaml1.创建KCI镜像缓存对应的ImageCache CR。示例yaml文件imagecache-sample.yaml 代码如下:
apiVersion: kci.io/v1alpha1
kind: ImageCache
metadata:
name: imagecache-sample
spec:
subnetId: "******" #创建镜像缓存容器实例的子网id
securityGroupId: "******" #创建镜像缓存容器实例的安全组id
images: #用于制作镜像缓存的容器镜像,范围[1,20]
- "hub.kce.ksyun.com/wu/xxxx:1"
imageRegistryCredential: #拉取镜像仓库中私有镜像的凭据,可填多个,公开镜像无须填写凭据
- server: "hub.kce.ksyun.com1"
username: "your-username"
password: "your-password"
- server: "hub.kce.ksyun.com2"
username: "your-username"
password: "your-password"
imageCacheType: "Common" #镜像缓存类型:普通型Common、极速型Rapid
imageCacheSize: 50 #镜镜像缓存大小。当镜像缓存类型是普通型时范围[20,2000],当镜像缓存类型是极速型时范围[40,2000]
retentionDays: 35 #镜像缓存保留时间,过期将自动删除该镜像缓存,单位天
enableWarm: true #是否预热,当imageCacheType为普通型时可填写,默认false2.执行以下命令,创建 ImageCache
kubectl create -f imagecache-sample.yaml3.执行以下命令,查询 ImageCache
查询集群下所有可用ImageCache列表:
kubectl get ImageCache查询具体ImageCache信息:
kubectl get ImageCache <ImageCache-name> -o yaml
kubectl describe ImageCache <ImageCache-name>4.执行以下命令,删除 ImageCache
kubectl delete ImageCache <ImageCache-name>KCI控制台镜像缓存与集群中ImageCache关系说明:
1.ImageCache创建的镜像缓存会同步到KCI控制台;
2.KCI控制台所有镜像缓存的编辑与删除也会同步到集群ImageCache。
纯净模式
