searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

在tekton下实现kaniko构建加速

2024-05-10 08:33:22
13
0

背景

用kaniko打包的时候,引用的基础镜像都需要拉取,实际基础镜像变化很小,可以利用kaniko的缓存机制进行加速

使用

原理是使用Kaniko-warmer 提前缓存基础镜像,用kaniko 构建镜像时,可以直接使用缓存的基础镜像进行加速,基础镜像一般会比较大,几百M字节,这样可以大大减少构建时间。

考虑kaniko 是跑在tekton里,需要考虑缓存存放,因为基础镜像比较大,所以直接放弃了使用NAS的方式,而是采用在每个节点直接挂载hostpath方式进行镜像缓存,这样每个节点都有基础镜像的缓存。

1:制作Kaniko-warmer 工具,以下为wamer.yaml,这里挂载了hostpath:/home/kaniko/cache

如果有多个镜像,在--image不断添加即可

apiVersion: v1due to PUT multiple errors returned: MANIFEST_BLOB_UNKNOWN: blob unknown to registry
kind: Pod
metadata:
  name: kaniko-warmer
spec:
  nodeSelector:
    physical: "yes"
  containers:
  - name: kaniko-warmer
    image: faas-harbor-registry-vpc-huadong1.crs.ctyun.cn/faas-sys/kaniko-warmer:latest
    args: ["--cache-dir=/kaniko/cache",
           "--image=registry.com/app/python3-runtime:1.0",
           "--image=registry.com/app/hello-world:linux"]
    volumeMounts:
      - name: kaniko-secret
        mountPath: /secret
      - name: kaniko-cache
        mountPath: /kaniko/cache
    env:
      - name: GOOGLE_APPLICATION_CREDENTIALS
        value: /secret/kaniko-secret.json
  restartPolicy: Never
  volumes:
    - name: kaniko-secret
      secret:
        secretName: kaniko-secret
    - name: kaniko-cache
      hostPath:
        path: /home/kaniko/cache

2: 使用Kaniko-warmer缓存镜像

  直接kubectl apply -f wamer.yaml 这样可以看到在节点的/home/kaniko/cache上有基础镜像的缓存文件,可以看到有的基础镜像是蛮大的,200~600M

2:kaniko构建开启kaniko缓存

主要是以下几个配置

--cache-repo=registry/app/testimage:v1-cache --cache-copy-layers=false --cache-run-layers=false --cache=true --cache-dir=/kaniko/cache

 /kaniko/executor --context=/workspace/tmpspace --dockerfile=/workspace/tmpspace/Dockerfile --destination=registry/app/testimage:v1 --log-timestamp=true --push-retry=3 --image-fs-extract-retry=3 --digest-file=/tekton/results/IMAGE_DIGEST --insecure=false --insecure-pull=false --skip-tls-verify=false --cache-repo=registry/app/testimage:v1-cache --cache-copy-layers=false --cache-run-layers=false --cache=true --cache-dir=/kaniko/cache

  执行结果

 

0条评论
0 / 1000