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-ff6zzfield.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: 2labels:cattle.io/creator: normanworkload.user.cattle.io/workloadselector: deployment-gitlab-gitlabname: gitlabnamespace: gitlabresourceVersion: "3780"selfLink: /apis/apps/v1beta2/namespaces/gitlab/deployments/gitlabuid: 68d9ca46-80bf-4b2b-af50-a9e69aadf12a
spec:progressDeadlineSeconds: 600replicas: 1revisionHistoryLimit: 10selector:matchLabels:workload.user.cattle.io/workloadselector: deployment-gitlab-gitlabstrategy:rollingUpdate:maxSurge: 1maxUnavailable: 0type: RollingUpdatetemplate: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: nulllabels:workload.user.cattle.io/workloadselector: deployment-gitlab-gitlabspec:containers:- env:- name: GITLAB_OMNIBUS_CONFIGvalue: external_url 'http://10.10.1.3:31901'image: gitlab/gitlab-ce:12.4.5-ce.0imagePullPolicy: Alwaysname: gitlabports:- containerPort: 31901name: 31901tcp319011protocol: TCPresources: {}securityContext:allowPrivilegeEscalation: falsecapabilities: {}privileged: falsereadOnlyRootFilesystem: falserunAsNonRoot: falsestdin: trueterminationMessagePath: /dev/termination-logterminationMessagePolicy: Filetty: truevolumeMounts:- mountPath: /etc/gitlabname: vol1- mountPath: /var/log/gitlabname: vol2- mountPath: /var/opt/gitlabname: vol3dnsPolicy: ClusterFirstrestartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30volumes:- name: vol1persistentVolumeClaim:claimName: gitlab-config- name: vol2persistentVolumeClaim:claimName: gitlab-log- name: vol3persistentVolumeClaim:claimName: gitlab-data
status:availableReplicas: 1conditions:- lastTransitionTime: "2019-12-02T12:51:23Z"lastUpdateTime: "2019-12-02T12:51:23Z"message: Deployment has minimum availability.reason: MinimumReplicasAvailablestatus: "True"type: Available- lastTransitionTime: "2019-12-02T12:48:28Z"lastUpdateTime: "2019-12-02T12:51:23Z"message: ReplicaSet "gitlab-db7b54f5c" has successfully progressed.reason: NewReplicaSetAvailablestatus: "True"type: ProgressingobservedGeneration: 2readyReplicas: 1replicas: 1updatedReplicas: 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:30003/jfwang/mcr.microsoft.com/dotnet/core/sdk:3.0
docker push 10.10.1.3:30003/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命令才会触发钩子(github在每个仓库的setting->webhooks下)。

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

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

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

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

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

yaml文件中加入

env:
PLUGIN_INSECURE: "true"

Dockerfile

FROM 10.10.1.3:30003/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-dotnetcorenamespace: default
spec:progressDeadlineSeconds: 600replicas: 1revisionHistoryLimit: 10selector:matchLabels:workload.user.cattle.io/workloadselector: deployment-default-pipeline-example-dotnetcorestrategy:type: Recreatetemplate: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: nulllabels:workload.user.cattle.io/workloadselector: deployment-default-pipeline-example-dotnetcorespec:containers:- image: ${CICD_IMAGE}:1.${CICD_EXECUTION_SEQUENCE}imagePullPolicy: Alwaysname: pipeline-example-dotnetcoreports:- containerPort: 80hostPort: 5000name: 5000tcp50000protocol: TCPresources: {}securityContext:allowPrivilegeEscalation: falsecapabilities: {}privileged: falsereadOnlyRootFilesystem: falserunAsNonRoot: falsestdin: trueterminationMessagePath: /dev/termination-logterminationMessagePolicy: Filetty: truednsPolicy: ClusterFirstimagePullSecrets:- name: harborrestartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30
status:availableReplicas: 1conditions:- lastTransitionTime: "2019-12-01T08:37:21Z"lastUpdateTime: "2019-12-01T08:37:21Z"message: Deployment has minimum availability.reason: MinimumReplicasAvailablestatus: "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: NewReplicaSetAvailablestatus: "True"type: ProgressingobservedGeneration: 7readyReplicas: 1replicas: 1updatedReplicas: 1

至此全部部署完毕。

Rancher2.x流水线自动化部署相关推荐

  1. Jenkins 流水线自动化部署 Go 项目

    ????推荐大家关注一个公众号???? 点击上方 "编程技术圈"关注, 星标或置顶一起成长 后台回复"大礼包"有惊喜礼包! 每日英文 The best way ...

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

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

  3. Jenkins 自动化部署流水线优化经验

    Jenkins 自动化部署流水线优化经验 1.1 跳过测试类 1.2 使用较为稳定的jenkins 企业长期支持版本 1.3 限制Jenkins 使用内存大小 这篇博文主要总结下在生产环境使用Jenk ...

  4. 利用gitee仓库的流水线功能实现Java项目的自动化部署

    背景:因为之前每次写完新的BUG之后,需要手动打包然后传到服务器,再进行启动,整个过程太浪费时间,而且没有一点技术含量,所以想做自动化部署. 本次自动化部署采用了gitee退出的仓库流水线功能,可以帮 ...

  5. K8S搭建自动化部署环境(四)Jenkins多分支流水线Blue Ocean的安装和使用

    各位大佬,前文如下: K8S搭建自动化部署环境(一)安装Kubernetes K8S搭建自动化部署环境(二)安装K8S管理工具Kuboard V3 K8S搭建自动化部署环境(三)Jenkins下载.安 ...

  6. Jenkins 流水线 获取git 分支列表_jenkins的安装和配置 自动化部署 码云 gitee

    目前项目使用的jenkins 自动化部署的还是比较多的 ,所以趁着脑瓜子还清醒,来写一下如何使用 jenkins 使用码云更新代码后,重新构建就是最新的代码,费话不多少了 直接上货, 首先要做一下准备 ...

  7. 再见 Jenkins!几行脚本搞定自动化部署,这款神器有点厉害

    title: 再见 Jenkins!几行脚本搞定自动化部署,这款神器有点厉害 date: 2021-04-30 20:42:32 tags: CICD Jenkins 在开发或生产环境中,我们经常会搞 ...

  8. kubernetes+Azure DevOps实现.Net Core项目的自动化部署均衡负载

    1. 前言 前前后后学习kubernetes也有一个来月了,关于kubernetes的博客也写了有十多篇.但是技术如果无法落地到实际的应用场景终归是纸上谈兵,所以就有了这一出:通过结合kubernet ...

  9. 使用TFS CI/CD 完成 VSTS 插件自动化部署和发布

    Visual Studio Team Service 经过了13年的版本演进和5年的在线运营,现在已经是最成熟的商用DevOps工具链,Marketplace作为VSTS为全球开发者提供各种类型的插件 ...

最新文章

  1. linux-多任务同步和互斥
  2. 神经元之间是如何形成“社交网络”的
  3. 用C语言写的万年历---亲手写的。好累哦
  4. Scrapy框架----pipeline---------数据保存EXCEL
  5. 【论文阅读】Clustering by Shift
  6. macOS Mojave Version 10.14 新系统字体问题和修改MAC中Launchpad启动器图标行列的数量
  7. GPU 编程入门到精通(三)之 第一个 GPU 程序
  8. lstm不收敛_20道深度学习面试题,有你不知道的吗?
  9. 关于json_decode乱码及NULL的解决方法
  10. zookeeper 入门讲解实例 转
  11. 【朝夕技术专刊】WebApi部署多服务器配置Nginx负载均衡
  12. 容器化之后如何节省云端成本?(二十七)
  13. linux上mysql分区磁盘位置_Linux下Oracle软件、数据文件等所在的磁盘分区空间不足的解决思路...
  14. 95-50-040-java.nio.channels-NIO-NIO之Buffer(缓冲区)
  15. 【2-SAT】URAL - 2089 - Experienced coach
  16. oracle去除首个字符,oracle如何去除字符串中的重复字符
  17. Node连接MySql数据库写模糊查询接口
  18. UVA-816 Abbott's Revenge (bfs)
  19. 集中不等式 (Concentration inequality)
  20. 用gambit学博弈论--完全信息动态博弈-参与者信息集、博弈树上虚线的解释(三)

热门文章

  1. Python_51job爬虫
  2. 【今日CV 计算机视觉论文速览】 25 Feb 2019
  3. 高可用HAProxy——yum安装部署配置使用
  4. Kubernetes-标签和注解(二十二)
  5. 创建线程方式二 java 1615474026
  6. 0829双层循环嵌套
  7. 爬虫-scrapy框架-起点中文网的爬取
  8. SQL Server执行计划
  9. 区块链加密算法小探(一)
  10. appium入门文档