现在很多项目都会自行部署gitlab来托管代码,然后通过gitlab-runner来进行代码的ci/cd构建,因为跑一次构建,会启动一个gitlab-runner pod来执行流水线任务,流水线执行完后,pod就会销毁,runner pod会快速创建和销毁,因此很多时候会选择eks集群或者超级节点来跑gitlab-runner,因为eks集群或者超级节点是通过腾讯云自研的轻量虚拟化技术,确保更快的资源创建效率,用户可以在几秒内创建或删除容器服务,非常适用于gitlab-runner这类业务。
但是在超级节点或者eks集群创建gitlab-runner会出现runner pod跑不起来,下面我们来详细说说这个问题。
runner pod在eks集群或者调度到超级节点创建,日志报错
Job failed (system failure): prepare environment: unable to upgrade connection: 404 request not found. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information
通过翻阅文档https://docs.gitlab.com/runner/executors/kubernetes.html和咨询研发,发现eks集群的不支持attach操作,只支持exec操作,但是gitlab runner默认是kube attach,而不是kube exec
GitLab Runner uses kube attach instead of kube exec by default. This should avoid problems like when a job is marked successful midway in environments with an unstable network.
因此这里job会执行失败。
既然问题已经找到了,那么我们修改下gitlab-runner的执行方式为exec就行,这里只需要参考文档配置下环境变量就行 https://docs.gitlab.com/runner/configuration/feature-flags.html#enable-feature-flag-in-pipeline-configuration
如果gitlab-runner也是部署在集群,直接在对应的configmap里给runner加上环境变量即可。
FF_USE_LEGACY_KUBERNETES_EXECUTION_STRATEGY = true