我最近和Docker,Kubernetes,Google Cloud Platform(GCP)和Gitlab一起玩,以实现从commit到staging的CI/CD。到目前为止,我已经成功地将testing、building和pushing的图像传给了Container registry of Gitlab。
我有一个小节点和码头应用程序,它输出'Hello world'。此外,我已经建立了我的码头形象在Container registry of Gitlab。在这个时刻,这个过程是码头-在码头。我想把我的形象从Gitlab container registry推到Kubernetes engine。我已经安装了kubectl和gcloud sdk。自动DevOps看起来很有希望,但我想实现自己的.gitlab-ci.yml文件。
下面是我的.gitlab-ci.yml:
stages:
- testing
- build
- staging
variables:
CONTAINER_TEST_IMAGE: registry.gitlab.com/surajneupane55/node-app-
testing
CONTAINER_RELEASE_IMAGE: registry.gitlab.com/surajneupane55/node-
app-testing:latest
test:
stage: testing
image: node:boron
script:
- npm install
- npm test
build_image:
stage: build
only: [master]
image: docker:git
services:
- docker:dind
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN
registry.gitlab.com/surajneupane55
- docker build -t $CONTAINER_TEST_IMAGE .
- docker push $CONTAINER_TEST_IMAGE
staging_site:
//I need help here!!!
//For staging my project in Kubernetes cluster in GCP
//Already created node-app Kubernetes cluster请告诉我,如果我的方法是错误的,因为这是我的第一个学习项目与CI/CD。
发布于 2017-12-29 20:17:30
一个简单的gitlab-ci.yml文件,可以用Google Container Registry(GCR)在GKE中构建和部署。首先,我们建立图像并将其推送到GCR。使用有效的凭据,我们可以轻松地将GKE与GCR连接起来并进行部署。
stages:
- build
- deploy
variables:
CONTAINER_TEST_IMAGE: gcr.io/node-testing-189614/node-testing:latest
build_image:
stage: build
only: [master]
image: google/cloud-sdk
services:
- docker:dind
script:
- echo "$GOOGLE_KEY_SECRET" > key.json # Google Cloud service accounts
- gcloud auth activate-service-account --key-file key.json
- gcloud config set project node-testing-189614
- gcloud container builds submit -t $CONTAINER_TEST_IMAGE .
deploy_staging:
image: google/cloud-sdk
stage: deploy
script:
- echo "$GOOGLE_KEY_SECRET" > key.json # Google Cloud service accounts
- gcloud auth activate-service-account --key-file key.json
- gcloud config set project node-testing-189614
- gcloud config set compute/zone europe-west1-b
- gcloud config set container/use_client_certificate True
- gcloud container clusters get-credentials node-testing
- kubectl delete pods --all
- kubectl apply -f staging.yml
environment:
name: staging
url: http://***.***.**.***:****/ //External IP from Kubernetes
only:
- master上面我们删除了GKE中的豆荚,因为我们总是想用最新的标签来更新图像。到目前为止,最好的解决方案是删除豆荚,让staging.yml文件在不可用的情况下创建新的文件。
最后,staging.yml看起来如下所示:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: node-testing
spec:
replicas: 2
template:
metadata:
labels:
app: node-testing
spec:
containers:
- name: node-testing
image: gcr.io/node-testing-189614/node-testing:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
imagePullSecrets:
- name: gcr.io/node-testing-189614/node-testing发布于 2017-12-19 15:12:11
宇不需要图像实际上被存储在GCR中才能在您的GKE中使用它,尽管有它在附近是很好的。您需要在gcloud上设置一个服务帐户,这样您的GCR就可以有一个未到期的auth (或者您需要使用gcloud cli对GCR进行标记),然后标记图像并将其推送。
在kubernetes上运行它是另一回事,我强烈要求您也查看Helm,以便为您的应用程序创建可在多个环境中重用的安装图表。
https://stackoverflow.com/questions/47888027
复制相似问题