如何在kubernetes下使用本地缓存运行gitlab-runner

mzmfm0qo  于 2023-08-03  发布在  Kubernetes
关注(0)|答案(1)|浏览(146)

我尝试在k8s下的gitlab-runners上使用本地缓存-我不想使用s3。
我正在阅读https://docs.gitlab.com/runner/executors/kubernetes.html#using-the-cache-with-the-kubernetes-executor上的文档:
当该高速缓存与Kubernetes执行程序一起使用时,一个名为/cache的卷被挂载在pod上。在作业执行期间,如果需要缓存的数据,则运行器将检查缓存的数据是否可用。如果压缩文件在该高速缓存卷上可用,则缓存数据可用。
要设置该高速缓存卷,请使用config.toml文件中的cache_dir设置。
如果可用,压缩文件将解压缩到构建文件夹中,然后可以在作业中使用。如果不可用,则从配置的存储中下载缓存数据,并将其作为压缩文件保存到缓存目录中。然后将压缩文件解压缩到构建文件夹中。
这与运行器如何通过k8s API为每个作业启动执行器pod的描述一起,我感觉该高速缓存将 * 正常工作 *。运行程序本身在我的设置中是长期存在的-没有自动缩放,如果该高速缓存存在其中并自动安装到执行器pod中就足够了。
它似乎不工作,虽然和日志是混乱的。
这是我的测试管道:

default:
  cache: &cache
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - local-cached-folder

prepare: 
  stage: prepare
  cache:
    <<: *cache
    policy: pull-push
  script:
    - mkdir local-cached-folder
    - echo "preparing…" > ./local-cached-folder/cached_file
    - echo "ls /cache"
    - ls -lFa /cache || true

build:
  stage: build
  cache:
    <<: *cache
    policy: pull-push
  script:
    - echo "ls -lFa ."
    - ls -lFa .
    - echo "ls -lFa local-cached-folder"
    - ls -lFa local-cached-folder || true
    - echo "ls /cache"
    - ls -lFa /cache || true

字符串
奇怪的是,日志显示“成功提取缓存”,但那里什么也没有:

Created fresh repository.
Checking out 7e436847 as detached HEAD (ref is master)...
Skipping Git submodules setup
Restoring cache
00:01
Checking cache for master-6-protected...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Executing "step_script" stage of the job script
00:01
$ mkdir local-cached-folder
$ echo "preparing…" > ./local-cached-folder/cached_file
$ echo "ls /cache"
ls /cache
$ ls -lFa /cache || true
ls: cannot access '/cache': No such file or directory
Saving cache for successful job
00:01
Creating cache master-6-protected...
local-cached-folder: found 2 matching artifact files and directories 
No URL provided, cache will not be uploaded to shared cache server. Cache will be stored only locally. 
Created cache


下一个工作:

Restoring cache
00:01
Checking cache for master-6-protected...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Executing "step_script" stage of the job script
00:01
$ echo "ls -lFa ."
ls -lFa .
$ ls -lFa .
…
$ echo "ls -lFa local-cached-folder"
ls -lFa local-cached-folder
$ ls -lFa local-cached-folder || true
ls: cannot access 'local-cached-folder': No such file or directory
$ echo "ls /cache"
ls /cache
$ ls -lFa /cache || true
ls: cannot access '/cache': No such file or directory
Saving cache for successful job
00:01
Creating cache master-6-protected...
WARNING: local-cached-folder: no matching files. Ensure that the artifact path is relative to the working directory (/builds/kostbevakningen/kb-frontend)


对我来说,它听起来像是找到了一个缓存归档,但也许这是我误解了文档和糟糕的日志记录的组合?
我确实读过gitlab-runner kubernetes cache is ignored,并认为我可能应该使用runners.kubernetes.volumes.pvc安装PVC,但它非常旧,公认的答案只是S3。

elcex8rz

elcex8rz1#

我得到了它的工作,使用一个PVC对执行人把它在toml在图表。我的完整values.yaml用于官方掌舵图表现在是:

gitlabUrl: https://gitlab.com/
rbac:
  create: true

runners:
  config: |
    [[runners]]
      [runners.kubernetes]
        namespace = "{{.Release.Namespace}}"
        image = "ubuntu:22.04"
        helper_image = "gitlab/gitlab-runner-helper:alpine-latest-arm64-v16.1.0"

      [[runners.kubernetes.volumes.pvc]]
        name = "runners-cache"
        mount_path = "/cache"
  executor: kubernetes

volumeMounts: []
volumes: []

字符串
所以看起来/cache是默认值,需要在那里挂载一些东西。写着“成功提取缓存”的日志似乎完全是无稽之谈。

相关问题