當(dāng)gitlab的runner使用kubernetes動態(tài)調(diào)度的時(shí)候,由于不確定pod會調(diào)度到哪個(gè)節(jié)點(diǎn)况芒,所以肥惭,使用宿主機(jī)目錄作為cache是有問題的。這時(shí)需要一個(gè)cache的服務(wù)器疟暖。
在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
,添加一個(gè)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.yaml
的runners.cache
部分(其他部分按照實(shí)際情況修改):
cacheType: s3
cachePath: "gitlab_runner"
cacheShared: true
# 這個(gè)是自己加的骨望,作用是不用https
Insecure: true
## S3 settings
# minio的地址
s3ServerAddress: minio.example.com
# 對應(yīng)minio的defaultBucket name
s3BucketName: gitlab
s3BucketLocation:
s3CacheInsecure: false
# helm安裝minio后會創(chuàng)建兩個(gè)secret硬爆,用非sa token的這個(gè)
# 也可以用命令創(chuàng)建kubectl create secret generic s3access --from-literal=accesskey="YourAccessKey" --from-literal=secretkey="YourSecretKey"
# 這兩個(gè)key的值都在minio的values中,網(wǎng)頁上登陸minio也是通過這兩個(gè)值
secretName: littering-aardvark-minio
總結(jié)
需要注意的有兩點(diǎn):
- minio需要創(chuàng)建Bucket擎鸠,gitlab runner才可用缀磕,在本文中,helm安裝的同時(shí)創(chuàng)建了一個(gè)默認(rèn)的bucket
- gitlab runner安裝的時(shí)候需要配置INSECURE劣光,gitlab 官方提供的chart包沒有這個(gè)配置項(xiàng)袜蚕,需要自己加上,作用是不使用https