gpt4 book ai didi

deployment - 如何通过k8s gitlab-ci Runner将某些东西部署到k8s集群?

转载 作者:行者123 更新时间:2023-12-02 11:58:34 24 4
gpt4 key购买 nike

猫/ etc / redhat-release:

CentOS Linux release 7.2.1511 (Core)

docker 版本:
Client:
Version: 1.13.1
API version: 1.26
Package version: <unknown>
Go version: go1.8.3
Git commit: 774336d/1.13.1
Built: Wed Mar 7 17:06:16 2018
OS/Arch: linux/amd64

Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: <unknown>
Go version: go1.8.3
Git commit: 774336d/1.13.1
Built: Wed Mar 7 17:06:16 2018
OS/Arch: linux/amd64
Experimental: false

kubectl版本:
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.5", GitCommit:"f01a2bf98249a4db383560443a59bed0c13575df", GitTreeState:"clean", BuildDate:"2018-03-19T15:59:24Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.0", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2017-12-15T20:55:30Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}

gitlab版本: 10.6-ce

gitlab运行程序图像: gitlab / gitlab-runner:alpine-v10.3.0

我只是将kubernetes集群(不是GKE,而是我自己部署的k8s集群)集成到了gitlab项目中,然后在上面安装了gitlab-runner。

所有这些都遵循 Adding an existing Kubernetes cluster

之后,我在一个阶段添加了一个 .gitlab-ci.yml,并将其推送到存储库中。这里是内容:
build-img:
stage: docker-build
script:
# - docker build -t $CONTAINER_RELEASE_IMAGE .
# - docker tag $CONTAINER_RELEASE_IMAGE $CONTAINER_LATEST_IMAGE
# - docker push $CONTAINER_IMAGE
- env | grep KUBE
- kubectl --help
tags:
- kubernetes
only:
- develop

然后我得到了:
$ env | grep KUBE
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT=tcp://10.96.0.1:443
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
$ kubectl --help
/bin/bash: line 62: kubectl: command not found
ERROR: Job failed: error executing remote command: command terminated with non-zero exit code: Error executing in Docker Container: 1

尚未在运行器中安装 kubectl,也未找到某些环境变量,例如 KUBE_TOKENKUBE_CA_PEM_FILEKUBECONFIG(请参阅 Deployment variables)。

搜索了gitlab的官方文档,一无所获。

那么,如何通过该运行程序部署项目?

最佳答案

gitlab-runner没有内置命令,它旋转具有预定义图像的容器,然后从该容器中的脚本远程执行命令。

您尚未定义图片,因此将使用gitlab-runner设置中定义的默认图片。

所以,
您可以在script:before_script:中使用Install kubectl binary using curl之前

build-img:
stage: docker-build
before_script:
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
- chmod +x ./kubectl
script:
- ...
- ./kubectl --version

或使用带有 kubectl的镜像创建单独的部署阶段,例如 roffe/kubectl:
stages:
- docker-build
- deploy

build-img:
stage: docker-build
script:
- docker build -t $CONTAINER_RELEASE_IMAGE .
- docker tag $CONTAINER_RELEASE_IMAGE $CONTAINER_LATEST_IMAGE
- docker push $CONTAINER_IMAGE
tags:
- kubernetes

deploy:dev:
stage: deploy
image: roffe/kubectl
script:
- kubectl .....
tags:
- kubernetes

关于deployment - 如何通过k8s gitlab-ci Runner将某些东西部署到k8s集群?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49801781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com