gitlab pipelie 使用 minio 作为 cache 服务器

当gitlab的runner使用kubernetes动态调度的时候,由于不确定pod会调度到哪个节点,所以,使用宿主机目录作为cache是有问题的。这时需要一个cache的服务器。

在k8s中安装minio

用helm 找到 minio的chart包。修改values.yaml中的defaultBucket:

  enabled: true
  ## If enabled, must be a string with length > 0
  name: gitlab
  ## Can be one of none|download|upload|public
  policy: none
  ## Purge if bucket exists already
  purge: false

安装gitlab runner

先用helm下载gitlab runner的chart包,chart包的helm仓库是https://charts.gitlab.io/
解压chart包,然后修改templates/_cache.tpl,添加一个name为CACHE_S3_INSECURE变量:

{{- define "gitlab-runner.cache" }}
{{-   if .Values.runners.cache.cacheType }}
- name: CACHE_TYPE
  value: {{ default "" .Values.runners.cache.cacheType | quote }}
- name: CACHE_PATH
  value: {{ coalesce .Values.runners.cache.cachePath .Values.runners.cache.s3CachePath | default "" | quote }}
{{-     if .Values.runners.cache.cacheShared }}
- name: CACHE_SHARED
  value: "true"
{{-     end }}
{{-     if eq .Values.runners.cache.cacheType "s3" }}
- name: CACHE_S3_SERVER_ADDRESS
  value: {{ template "gitlab-runner.cache.s3ServerAddress" . }}
- name: CACHE_S3_BUCKET_NAME
  value: {{ default "" .Values.runners.cache.s3BucketName | quote }}
- name: CACHE_S3_BUCKET_LOCATION
  value: {{ default "" .Values.runners.cache.s3BucketLocation | quote }}
- name: CACHE_S3_INSECURE
  value: {{ default "false" .Values.runners.cache.Insecure | quote }}
{{-       if .Values.runners.cache.s3CacheInsecure }}
- name: S3_CACHE_INSECURE
  value: "true"
{{-       end }}
{{-     end }}
{{-     if eq .Values.runners.cache.cacheType "gcs" }}
- name: CACHE_GCS_BUCKET_NAME
  value: {{ default "" .Values.runners.cache.gcsBucketName | quote }}
{{-     end }}
{{-   end }}
{{- end -}}

修改values.yamlrunners.cache部分(其他部分按照实际情况修改):

    cacheType: s3
    cachePath: "gitlab_runner"
    cacheShared: true
    # 这个是自己加的,作用是不用https
    Insecure: true
    ## S3 settings
    # minio的地址
    s3ServerAddress: minio.example.com
    # 对应minio的defaultBucket name
    s3BucketName: gitlab
    s3BucketLocation:
    s3CacheInsecure: false
    # helm安装minio后会创建两个secret,用非sa token的这个
    # 也可以用命令创建kubectl create secret generic s3access --from-literal=accesskey="YourAccessKey" --from-literal=secretkey="YourSecretKey"
    # 这两个key的值都在minio的values中,网页上登陆minio也是通过这两个值
    secretName: littering-aardvark-minio

总结

需要注意的有两点:

  1. minio需要创建Bucket,gitlab runner才可用,在本文中,helm安装的同时创建了一个默认的bucket
  2. gitlab runner安装的时候需要配置INSECURE,gitlab 官方提供的chart包没有这个配置项,需要自己加上,作用是不使用https
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容