1、环境规范
builder image 标签
为了保证builder 镜像更新版本后,template用最新的image,我们最好在template中指定image标签为latest。,修改is标签的方法为:
在docker 中执行一下命令:
#更改docker标签,并推送到仓库
[root@registry-node1 ~]# docker tag cabef4ead344 registry.example.com/golang-builder
[root@registry-node1 ~]# docker push registry.example.com/golang-builder
#更改is
vito@caas:~$ oc edit is golang-builder
imagestream "golang-builder" edited
#修改内容如下:增加 annotations 即可
- annotations:
description: Build and run golang 1.8 applications on linux,when you build project,you
must set environment variable,PROJECT_NAME=you_project_name
tags: builder
from:
kind: DockerImage
name: registry.example.com/golang-builder:latest
generation: 4
importPolicy:
insecure: true
name: latest
referencePolicy:
type: Source
持久化存储
postgres 数据库设置持久化存储。为了了解创建持久化的过程,首先我用Postresql Ephemeral模板,创建非持久化的数据库,然后创建pvc,最后把pvc挂载到postgres 数据库中,完成数据持久化过程。
# 查询创建好的pvc名称
vito@caas:~$ oc get pvc
NAME STATUS VOLUME CAPACITY ACCESSMODES STORAGECLASS AGE
peony-storage Bound pvc-a03d1825-c9cb-11e7-b8ec-0050568cc9dc 1Gi RWO ceph-storageclass-slow 19h
# 查询postgres-svc服务volume的设置情况,其中empty directory表示该容器使用的是empty directory卷,数据保存在计算节点上。
vito@caas:~$ oc volumes dc/postgres-svc
deploymentconfigs/postgres-svc
empty directory as postgres-svc-data
mounted at /var/lib/pgsql/data
# 我们执行volume 挂载更新操作:
vito@caas:~$ oc volume dc/postgres-svc --add --name=postgres-svc-data -t pvc --claim-name=peony-storage --overwrite
deploymentconfig "postgres-svc" updated
# 再次查询volume
vito@caas:~/docker$ oc volumes dc/postgres-svc
deploymentconfigs/postgres-svc
pvc/peony-storage (allocated 1GiB) as postgres-svc-data
mounted at /var/lib/pgsql/data
# 我们发现volume 类型变成了pvc/peony-storage,完成持久化操作。
# 重启容器,测试数据是否持久化,重启过程中,提示pvc 挂载失败,需要执行以下脚本,赋予权限。
apiVersion: v1
data:
key: QVFDTWljQlpGN1htS0JBQWluZ2RsQzdKUmJMVm82YVljMkhXbkE9PQ==
kind: Secret
metadata:
name: ceph-secret-openshift
namespace: ecloudcaas-dev
type: kubernetes.io/rbd
#执行创建
oc create -f pvc-sercret.yaml
# 重启容器,成功,测试持久化存储,成功!!
定义SERVICE NAME
服务之间访问,用service name 来传递ip地址和端口,每个服务首先创建service,然后deploy 容器,系统会自动把service的ip和port注入到pod的环境变量中,注意先后顺序,先service,然后创建pod。
增加健康检查
为每个服务创建健康检查,过程不再赘述
导出模板
oc export bc,dc,svc,is,route,pvc -o json –as-template=’dev-template’ >dev-template.json
创建jenkins项目
创建三个项目:
1、ecloudcaas-dev
2、ecloudcaas-sit
3、ecloudcaas-release
赋权:
jenkins需要权限来操作openshift,赋权给他
vito@caas:~$ oc policy add-role-to-user edit system:serviceaccount:ci:default -n ecloudcaas-dev
role "edit" added: "system:serviceaccount:ci:default"
vito@caas:~$ oc policy add-role-to-user edit system:serviceaccount:ci:default -n ecloudcaas-sit
role "edit" added: "system:serviceaccount:ci:default"
vito@caas:~$ oc policy add-role-to-user edit system:serviceaccount:ci:default -n ecloudcaas-release
role "edit" added: "system:serviceaccount:ci:default"
docker register 赋权:
SIT环境和RELEASE环境需要拉取DEV环境的镜像,下面的命令赋权
vito@caas:~$ oc project ecloudcaas-dev
Now using project "ecloudcaas-dev" on server "https://openshift-cluster.example.com:8443".
vito@caas:~$ oc policy add-role-to-user edit system:image-pullersystem:serviceaccount:ecloudcaas-sit:default -n ecloudcaas-dev
role "edit" added: "system:image-pullersystem:serviceaccount:ecloudcaas-sit:default"
vito@caas:~$ oc policy add-role-to-user edit system:image-pullersystem:serviceaccount:ecloudcaas-release:default -n ecloudcaas-dev
role "edit" added: "system:image-pullersystem:serviceaccount:ecloudcaas-release:default"
集成环境部署配置
引用dev开发环境的is,在sit测试环境中创建is,sit环境中的is指向dev环境。
vito@caas:~$ oc tag ecloudcaas-dev/pontus:latest ecloudcaas-sit/pontus:latest
Tag ecloudcaas-sit/pontus:latest set to ecloudcaas-dev/pontus@sha256:50bc72694145fb52dcea08fa46d546d6f49f0680a5e16d391b1ecb7c9ca273f6.
vito@caas:~$ oc tag ecloudcaas-dev/peony:latest ecloudcaas-sit/peony:latest
Tag ecloudcaas-sit/peony:latest set to ecloudcaas-dev/peony@sha256:1fc429ca3e49fa060d12d32f2570ce088a1f794f13f6473211aa7fddf0bb19f7.
#执行部署命令,创建部署任务
oc new-app -i ecloudcaas-sit/pontus:latest
生成环境部署配置
引用sit测试环境的is,在release生成环境中创建is
vito@caas:~$ oc tag ecloudcaas-sit/peony:latest ecloudcaas-release/peony:latest
Tag peony:latest set to ecloudcaas-sit/peony@sha256:1fc429ca3e49fa060d12d32f2570ce088a1f794f13f6473211aa7fddf0bb19f7.
vito@caas:~$ oc tag ecloudcaas-sit/pontus:latest ecloudcaas-release/pontus:latest
Tag pontus:latest set to ecloudcaas-sit/pontus@sha256:50bc72694145fb52dcea08fa46d546d6f49f0680a5e16d391b1ecb7c9ca273f6.
#执行部署命令,创建部署任务
oc new-app -i ecloudcaas-release/pontus:latest
jenkins 配置过程
配置jenkins域名后,访问jenkins页面,输入用户名密码后,登录控制台:
DEV构建jenkins配置
点击上图的新建链接,输入jenkins项目名称,选择自由风格,点击下面的保存,如下图:
选择构建任务,创建构建步骤:
需要写的项目如下图:
SIT构建jenkins配置
点击上图的新建链接,输入jenkins项目名称pontus-sit-ci,选择自由风格,点击下面的保存,进入配置页面,选择tag openshift image条目,如下图,注意,sit测试环境和release生成环境都不需要build,而是直接拉取dev环境build出来的镜像进行工作。
继续添加:Trigger openshift deployment
RELEASE构建jenkins配置
过程参考上面的 SIT构建jenkins配置