1、概述

  由于一些项目使用了rancher进行部署发布,所以使用Rancher的流水线自动部署功能实现CICD,从gitlab、harbor安装,到流水线配置和中间的一些问题一一进行详细介绍解答。

2、准备工作

  前期的Docker和Rancher安装就不在描述,直接进入正题

  2.1 gitlab安装

     gitlab安装很简单,配置到相应pvc和external_url即可

      yaml文件如下

     

apiVersion: apps/v1beta2
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
field.cattle.io/creatorId: user-ff6zz
field.cattle.io/publicEndpoints: '[{"addresses":["10.10.1.3"],"port":31901,"protocol":"TCP","serviceName":"gitlab:gitlab-nodeport","allNodes":true}]'
creationTimestamp: "2019-12-02T12:48:28Z"
generation: 2
labels:
cattle.io/creator: norman
workload.user.cattle.io/workloadselector: deployment-gitlab-gitlab
name: gitlab
namespace: gitlab
resourceVersion: "3780"
selfLink: /apis/apps/v1beta2/namespaces/gitlab/deployments/gitlab
uid: 68d9ca46-80bf-4b2b-af50-a9e69aadf12a
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
workload.user.cattle.io/workloadselector: deployment-gitlab-gitlab
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
annotations:
cattle.io/timestamp: "2019-12-02T12:48:37Z"
field.cattle.io/ports: '[[{"containerPort":31901,"dnsName":"gitlab-nodeport","kind":"NodePort","name":"31901tcp319011","protocol":"TCP","sourcePort":31901}]]'
creationTimestamp: null
labels:
workload.user.cattle.io/workloadselector: deployment-gitlab-gitlab
spec:
containers:
- env:
- name: GITLAB_OMNIBUS_CONFIG
value: external_url 'http://10.10.1.3:31901'
image: gitlab/gitlab-ce:12.4.5-ce.0
imagePullPolicy: Always
name: gitlab
ports:
- containerPort: 31901
name: 31901tcp319011
protocol: TCP
resources: {}
securityContext:
allowPrivilegeEscalation: false
capabilities: {}
privileged: false
readOnlyRootFilesystem: false
runAsNonRoot: false
stdin: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
tty: true
volumeMounts:
- mountPath: /etc/gitlab
name: vol1
- mountPath: /var/log/gitlab
name: vol2
- mountPath: /var/opt/gitlab
name: vol3
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- name: vol1
persistentVolumeClaim:
claimName: gitlab-config
- name: vol2
persistentVolumeClaim:
claimName: gitlab-log
- name: vol3
persistentVolumeClaim:
claimName: gitlab-data
status:
availableReplicas: 1
conditions:
- lastTransitionTime: "2019-12-02T12:51:23Z"
lastUpdateTime: "2019-12-02T12:51:23Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: "2019-12-02T12:48:28Z"
lastUpdateTime: "2019-12-02T12:51:23Z"
message: ReplicaSet "gitlab-db7b54f5c" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 2
readyReplicas: 1
replicas: 1
updatedReplicas: 12.2

  2.2 harbor安装

     harbor私有docker镜像仓库安装,为了做到持久化,先行安装pgsql和redis。pgsql安装好后先创建registry,clair,notary_server,notary_signer4个数据库然后在商店选择harbor,配置相关选项,然后在harbor启动后,如果没有使用https,需要在node主机上的docker配置文件daemon.json中加入harbor私用镜像库地址 "insecure-registries":["10.10.1.3:30003"],不然docker会报证书问题的错误。然后在rancher的资源->镜像库凭证中添加相关凭证。最后把接下来需要的镜像上传到harbor,上传前需要docker login。

docker pull mcr.microsoft.com/dotnet/core/sdk:3.0
docker tag mcr.microsoft.com/dotnet/core/sdk:3.0 10.10.1.3:/jfwang/mcr.microsoft.com/dotnet/core/sdk:3.0
docker push 10.10.1.3:/jfwang/mcr.microsoft.com/dotnet/core/sdk:3.0

     

             

3、配置流水线

  配置rancher的token和key在后续自动部署的时候直接操作容器,

点击添加key,然后记住token和key。

然后在工作负载->流水线->配置代码库->认证&同步代码库,我这里选择的gitlab,按照配置即可

授权成功后,需要在setting->network->Outbound requests下勾选Allow requests to the local network from web hooks and services,这样代码的pull命令才会触发钩子。

同步完代码库后,点击启用,点击编辑配置对流水线进行具体配置。

第一步clone代码是自带的无需配置

第二步执行测试操作,点击添加阶段。然后在阶段里添加步骤,步骤类型为运行脚本,基础镜像填你执行命令的所需镜像,不同程序语言执行不同的脚本

第三步 发布程序,步骤类型和基础镜像和第二步一样,脚本为发布脚本

第四不 构建镜像,步骤类型构建并发布镜像,Dockerfile路径就填写你代码中Dockerfile的路径,镜像名称如果你要push到自己的镜像仓库则规则必须是  镜像项目名/程序名,不然无权限,最后勾选我们最开始配置的私有镜像仓库地址。

Dockerfile

FROM 10.10.1.3:/jfwang/mcr.microsoft.com/dotnet/core/aspnet:3.0 AS runtime
WORKDIR /app
COPY /src/publish ./
ENTRYPOINT ["dotnet", "pipeline-example-dotnetcore.dll"]

第五步,因我们要自动部署应用到rancher,为了重复部署的时候防止端口被占用,名称重复等等,我们直接先通过rancher api 执行删除pod操作。注意如果不是用的https要在最后面加-k参数,不然会报证书错误。

curl -u "{token}:{key}" \
-X DELETE \
-H 'Accept: application/json' \
'https://10.10.1.3/v3/project/c-24h9n:p-f9cxk/workloads/deployment:default:pipeline-example-dotnetcore' -k

第六步 通过yaml部署应用

路径填写代码中的yaml路径

yaml

apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: pipeline-example-dotnetcore
namespace: default
spec:
progressDeadlineSeconds:
replicas:
revisionHistoryLimit:
selector:
matchLabels:
workload.user.cattle.io/workloadselector: deployment-default-pipeline-example-dotnetcore
strategy:
type: Recreate
template:
metadata:
annotations:
cattle.io/timestamp: "2019-12-01T08:37:18Z"
field.cattle.io/ports: '[[{"containerPort":80,"dnsName":"pipeline-example-dotnetcore-hostport","hostPort":5000,"kind":"HostPort","name":"5000tcp50000","protocol":"TCP","sourcePort":5000}]]'
creationTimestamp: null
labels:
workload.user.cattle.io/workloadselector: deployment-default-pipeline-example-dotnetcore
spec:
containers:
- image: ${CICD_IMAGE}:.${CICD_EXECUTION_SEQUENCE}
imagePullPolicy: Always
name: pipeline-example-dotnetcore
ports:
- containerPort:
hostPort:
name: 5000tcp50000
protocol: TCP
resources: {}
securityContext:
allowPrivilegeEscalation: false
capabilities: {}
privileged: false
readOnlyRootFilesystem: false
runAsNonRoot: false
stdin: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
tty: true
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: harbor
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds:
status:
availableReplicas:
conditions:
- lastTransitionTime: "2019-12-01T08:37:21Z"
lastUpdateTime: "2019-12-01T08:37:21Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: "2019-12-01T08:32:53Z"
lastUpdateTime: "2019-12-01T08:37:21Z"
message: ReplicaSet "pipeline-example-dotnetcore-84d4cfbb75" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration:
readyReplicas:
replicas:
updatedReplicas:

至此全部部署完毕。

Rancher2.x流水线自动化部署的更多相关文章

  1. jenkins 流水线自动化部署 手动下载安装插件包

    如果有些插件不能通过可选插件安装,可以进行选择高级并上传插件包,插件包链接地址为:http://updates.jenkins-ci.org/download/plugins/ 同时在高级中可以更换下 ...

  2. 大厂是如何用DevCloud流水线实现自动化部署Web应用的?

    DevUI是一支兼具设计视角和工程视角的团队,服务于华为云DevCloud平台和华为内部数个中后台系统,服务于设计师和前端工程师. 官方网站:devui.design Ng组件库:ng-devui(欢 ...

  3. 持续集成+自动化部署[代码流水线管理及Jenkins和gitlab集成]

    转载:https://www.abcdocker.com/abcdocker/2065 一.代码流水线管理 Pipeline名词顾名思义就是流水线的意思,因为公司可能会有很多项目.如果使用jenkin ...

  4. .Net Core自动化部署系列(二):使用Jenkins打造镜像发布流水线

    一.简介 之前写过一篇关于Jenkins搭配GitLab实现.net core项目自动发布到IIS的博文,比较简单哈,只是个Demo.本篇我们将会使用Jenkins搭配GitLab实现镜像的自动打包和 ...

  5. 持续集成与自动化部署---代码流水线管理及Jenkins和gitlab集成

    1.代码流水线管理 Pipeline名词顾名思义就是流水线的意思,因为公司可能会有很多项目.如果使用jenkins构建完成后,开发构建项目需要一项一项点击,比较麻烦.所以出现pipeline名词. 代 ...

  6. Linux-GitLab+Jenkins持续集成+自动化部署

    GitLab+Jenkins持续集成+自动化部署 什么是持续集成? (1)Continuous integration (CI) 持续集成是一种软件开发实践,即团队开发成员经常集成他们的工作,通常每个 ...

  7. Jenkins+Gitlab+Ansible自动化部署(六)

    Pipeline Job实现Nginix+MySQL+PHP+Wordpress实现自动化部署交付(Jenkins+Gitlab+Ansible自动化部署(五)https://www.cnblogs. ...

  8. 【nodejs原理&源码赏析(9)】用node-ssh实现轻量级自动化部署

    目录 一. 需求描述 二. 预备知识 IP+端口访问 域名访问 三. Nodejs应用的手动部署 四. 基于nodejs的自动部署 4.1 package.json中的scripts 4.2 自动化发 ...

  9. 【nodejs原理&源码赏析(9)】用node-ssh实现轻量级自动化部署

    [摘要] node脚本实现轻量级自动化部署 示例代码托管在:http://www.github.com/dashnowords/blogs 一. 需求描述 前端工程出包后实现简易的自动化部署. 二. ...

随机推荐

  1. 一条Top10热销品牌MySQL语句

    表t_alibaba_data的数据结构如下: 各列含义分别是: 用户id(user_id),品牌id(brand_id),用户行为(type, 其中,点击为0,购买为1,加入收藏为2,加入购物车为3 ...

  2. MySQL必知必会(Insert into)

    ########################## # Populate customers table ########################## INSERT INTO custome ...

  3. JQuery之Ajax应用

    众所周知JQuery中的Ajax主要用于数据传输,其数据传输格式为JSON格式数据,比XML格式数据传输更快. ajax 是 Asynchronous JavaScript and XML的简写,aj ...

  4. luogu P1754 球迷购票问题

    题目背景 盛况空前的足球赛即将举行.球赛门票售票处排起了球迷购票长龙. 按售票处规定,每位购票者限购一张门票,且每张票售价为50元.在排成长龙的球迷中有N个人手持面值50元的钱币,另有N个人手持面值1 ...

  5. git 使用详解 (1)——历史

    版本控制系统(VCS) 有了它你就可以将某个文件回溯到之前的状态,甚至将整个项目都回退到过去某个时间点的状态.你可以比较文件的变化细节,查出最后是谁修改了哪个地方,从而导致出现怪异问题,又是谁在何时报 ...

  6. 初始CSS3 实例

    <!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...

  7. USB3.0之高速视频传输测试 双目相机(mt9p031、mt9m001)带宽高达300M测试 配合isensor测试 500万像素15fps

    最近完善了下USB3.0的视频开发测试,主要优化了FPGA程序和固件,及其同步方式.对带宽和图像效果进行了仔细的测试 开发板架构(2CMOS+FPGA+2DDR2+USB3.0) 评估板底板配合2个M ...

  8. Spring Boot (二) 整合 Redis

    前言 本文将会基于 springboot 2.1.8.RELEASE 简单整合 Redis ,适合新手小白入门 Spring Boot 整合 Redis 入门 1.pom.xml 中引入 redis ...

  9. 10分钟理解BFC原理

    10 分钟理解 BFC 原理 一.常见定位方案 在讲 BFC 之前,我们先来了解一下常见的定位方案,定位方案是控制元素的布局,有三种常见方案: 普通流 (normal flow) 在普通流中,元素按照 ...

  10. 小胖求学系列之-文档生成利器(上)-smart-doc

    最近小胖上课总是挂着黑眼圈,同桌小张问:你昨晚通宵啦?小胖有气无力的说到:最近开发的项目接口文档没写,昨晚补文档补了很久,哎,昨晚只睡了2个小时.小张说:不是有生成文档工具吗,类似swagger2.s ...