DevOps(10)--其他工具链集成
其他工具链集成
1. 自动化测试
1.1 Jmeter
下载地址:http://jmeter.apache.org/download_jmeter.cgi
1.1.1 案例
使用 jmeter 访问百度接口,并查看请求和响应信息
步骤:
添加线程组
添加 HTTP 请求 并 配置
添加查看结果树
运行之后,在结果树中就可以查看结果。
1.1.2 linux运行
一般使用的步骤是:
windows做好测试计划,保存为xxx.jmx
将jmx文件上传linux,使用linux命令执行
sh bin/jmeter.sh -n -t test.jmx -l result.jtl
然后将result.jtl下载到windows电脑,进行结果查看
1.2 Gitlab CI集成
因为我们需要在自动化测试完成后,查看jmeter的结果,所以需要先开启gitlab pages
设置环境变量GITLAB_PAGES_ENABLED=true
和GITLAB_PAGES_DOMAIN=test.com
即可。
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitlab
namespace: gitlab
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "50m"
labels:
name: gitlab
spec:
selector:
matchLabels:
name: gitlab
template:
metadata:
name: gitlab
labels:
name: gitlab
spec:
initContainers:
- name: fix-permissions
image: busybox
command: ["sh", "-c", "chown -R 1000:1000 /home/git/data"]
securityContext:
privileged: true
volumeMounts:
- name: gitlab-data
mountPath: /home/git/data
containers:
- name: gitlab
image: sameersbn/gitlab:15.4.2
imagePullPolicy: IfNotPresent
env:
- name: TZ
value: Asia/Shanghai
- name: GITLAB_TIMEZONE
value: Beijing
- name: GITLAB_SECRETS_DB_KEY_BASE
value: "long-and-random-alpha-numeric-string"
- name: GITLAB_SECRETS_SECRET_KEY_BASE
value: "long-and-random-alpha-numeric-string"
- name: GITLAB_SECRETS_OTP_KEY_BASE
value: "long-and-random-alpha-numeric-string"
- name: GITLAB_ROOT_PASSWORD
value: admin123456789
- name: GITLAB_ROOT_EMAIL
value: admin@test.com
- name: GITLAB_HOST
value: gitlab.test.com
- name: GITLAB_PAGES_DOMAIN
value: test.com
- name: GITLAB_PAGES_PORT
value: "80"
- name: GITLAB_PORT
value: "80"
- name: GITLAB_SSH_PORT
value: "22"
- name: GITLAB_NOTIFY_ON_BROKEN_BUILDS
value: "true"
- name: GITLAB_NOTIFY_PUSHER
value: "false"
- name: GITLAB_BACKUP_SCHEDULE
value: daily
- name: GITLAB_BACKUP_TIME
value: 01:00
- name: DB_TYPE
value: postgres
- name: DB_HOST
value: postgresql
- name: DB_PORT
value: "5432"
- name: DB_USER
value: gitlab
- name: DB_PASS
value: gitlab
- name: DB_NAME
value: gitlab_production
- name: REDIS_HOST
value: redis
- name: REDIS_PORT
value: "6379"
- name: GITLAB_PAGES_ENABLED
value: "true"
ports:
- name: http
containerPort: 80
- name: ssh
containerPort: 22
volumeMounts:
- mountPath: /home/git/data
name: gitlab-data
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 60
timeoutSeconds: 1
volumes:
- name: gitlab-data
nfs:
server: 192.168.200.101
path: /data/gitlab/data
---
apiVersion: v1
kind: Service
metadata:
name: gitlab
namespace: gitlab
labels:
name: gitlab
spec:
ports:
- name: http
port: 80
targetPort: http
- name: ssh
port: 22
targetPort: ssh
nodePort: 30022
type: NodePort
selector:
name: gitlab
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gitlab
namespace: gitlab
labels:
name: gitlab
spec:
ingressClassName: nginx # ingress控制器的名称
rules:
- host: gitlab.test.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: gitlab
port:
number: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gitlab-pages
namespace: gitlab
labels:
name: gitlab
spec:
ingressClassName: nginx # ingress控制器的名称
rules:
- host: "gitlabci.test.com"
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: gitlab
port:
number: 80
1.2.1 配置编写
stages:
- tests
- deploy
interface_test:
stage: tests
image: justb4/jmeter:5.5
tags:
- k8s
script:
- ls
- mkdir -p result/htmlfile/
- jmeter -n -t jmx/test.jmx -l test.jtl -e -o result/htmlfile/
artifacts:
paths:
- result/htmlfile/
pages:
stage: deploy
dependencies:
- interface_test
script:
- mv result/htmlfile/ public/
artifacts:
paths:
- public
expire_in: 30 days
only:
- master
跑完访问:http://gitlabci.test.com/k8s-go-demo/
2. Mattermost
ChatOps
Mattermost 采用 Go 语言开发,这是一个开源的团队通讯服务。为团队带来跨 PC 和移动设备的消息、文件分享,提供归档和搜索功能。
Mattermost可轻松与流行的DevOps工具集成,例如Jira,Jenkins,GitLab,Trac,Redmine和Bitbucket。免费提供数十种开源集成,包括交互式bot应用程序(例如Hubot和whatmost-bot)以及其他通信工具。
Mattermost支持DevOps工作流程,许多DevOps工作流程都依赖实时协作。团队在关键时刻使用消息传递来提高效率—设置基础架构,合并代码分支或解决紧急错误。Mattermost统一了人员,工具,系统数据和自动化,以帮助您的组织发挥最佳性能。
2.1 安装
地址:https://docs.mattermost.com/guides/deployment.html
helm安装:https://github.com/mattermost/mattermost-helm
[root@master mattermost]# helm repo add mattermost https://helm.mattermost.com
"mattermost" has been added to your repositories
[root@master mattermost]# helm search repo -l mattermost/mattermost-team-edition
NAME CHART VERSION APP VERSION DESCRIPTION
mattermost/mattermost-team-edition 6.6.18 7.7.1 Mattermost Team Edition server.
mattermost/mattermost-team-edition 6.6.17 7.7.0 Mattermost Team Edition server.
mattermost/mattermost-team-edition 6.6.16 7.5.2 Mattermost Team Edition server.
先配置一个storageclass用于持久化:
mattermost-storage.yml
apiVersion: storage.k8s.io/v1 ## 创建了一个存储类
kind: StorageClass
metadata:
name: mattermost-nfs-client
annotations:
storageclass.kubernetes.io/is-default-class: "false"
namespace: gitlab
provisioner: mattermost-data #Deployment中spec.template.spec.containers.env.name.PROVISIONER_NAME 保持一致
parameters:
archiveOnDelete: "true" ## 删除pv的时候,pv的内容是否要备份
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mattermost-nfs-client-provisioner
labels:
app: mattermost-nfs-client-provisioner
namespace: gitlab
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app: mattermost-nfs-client-provisioner
template:
metadata:
labels:
app: mattermost-nfs-client-provisioner
spec:
serviceAccountName: mattermost-nfs-client-provisioner
containers:
- name: mattermost-nfs-client-provisioner
image: registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/nfs-subdir-external-provisioner:v4.0.2
volumeMounts:
- name: nfs-client-root
mountPath: /persistentvolumes
env:
- name: PROVISIONER_NAME
value: mattermost-data
- name: NFS_SERVER
value: 192.168.200.101 ## 指定自己nfs服务器地址
- name: NFS_PATH
value: /data/mattermost ## nfs服务器共享的目录
volumes:
- name: nfs-client-root
nfs:
server: 192.168.200.101
path: /data/mattermost
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: mattermost-nfs-client-provisioner
namespace: gitlab
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: mattermost-nfs-client-provisioner-runner
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "watch", "create", "delete"]
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs: ["get", "list", "watch", "update"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: mattermost-run-nfs-client-provisioner
subjects:
- kind: ServiceAccount
name: mattermost-nfs-client-provisioner
namespace: gitlab
roleRef:
kind: ClusterRole
name: mattermost-nfs-client-provisioner-runner
apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: mattermost-leader-locking-nfs-client-provisioner
namespace: gitlab
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: mattermost-leader-locking-nfs-client-provisioner
namespace: gitlab
subjects:
- kind: ServiceAccount
name: mattermost-nfs-client-provisioner
namespace: gitlab
roleRef:
kind: Role
name: mattermost-leader-locking-nfs-client-provisioner
apiGroup: rbac.authorization.k8s.io
helm show values mattermost/mattermost-team-edition > values.yaml
ingress:
enabled: true
hosts:
- mattermost.test.com
mysql:
enabled: true
mysqlRootPassword: ""
mysqlUser: "admin"
mysqlPassword: "admin123456"
mysqlDatabase: mattermost
persistence:
enabled: true
## If defined, storageClassName: <storageClass>
## If set to "-", storageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
## set, choosing the default provisioner. (gp2 on AWS, standard on
## GKE, AWS & OpenStack)
##
storageClass: "mattermost-nfs-client"
persistence:
## This volume persists generated data from users, like images, attachments...
##
data:
enabled: true
size: 10Gi
## If defined, volume.beta.kubernetes.io/storage-class: <storageClass>
## Default: volume.alpha.kubernetes.io/storage-class: default
##
storageClass: mattermost-nfs-client
accessMode: ReadWriteOnce
# existingClaim: ""
plugins:
enabled: true
size: 1Gi
## If defined, volume.beta.kubernetes.io/storage-class: <storageClass>
## Default: volume.alpha.kubernetes.io/storage-class: default
##
storageClass: mattermost-nfs-client
accessMode: ReadWriteOnce
[root@master mattermost]# helm install -f values.yaml mattermost mattermost/mattermost-team-edition -n gitlab
NAME: mattermost
LAST DEPLOYED: Tue Feb 14 04:59:33 2023
NAMESPACE: gitlab
STATUS: deployed
REVISION: 1
NOTES:
You can easily connect to the remote instance from your browser. Forward the webserver port to localhost:8065
- kubectl port-forward --namespace gitlab $(kubectl get pods --namespace gitlab -l "app.kubernetes.io/name=mattermost-team-edition,app.kubernetes.io/instance=mattermost" -o jsonpath='{ .items[0].metadata.name }') 8080:8065
Mattermost will be available at the URL, if you setup the nginx-ingress or other type of ingress:
http://mattermost.test.com
配置hosts:
192.168.200.101 mattermost.test.com
2.2 gitlab CI集成
ChatOps是一种以对话为中心的协作式工作方式,Mattermost ChatOps将不同的工具和工作流程整合在一起,以提供共享的控制台,以简化协作,缩短反馈循环并自动执行重复的手动任务。
Mattermost Notifications Service 允许GitLab项目将事件(例如issue created
)作为通知发送到现有的Mattermost团队。这需要在Mattermost和GitLab中进行配置。
创建WebHook
GitLab 配置
进入项目设置-> 集成 -> Mattermost services 。选中Active,在每个事件复选框的下方,都有一个输入字段,用于输入您要发送该事件消息的Mattermost频道。
最后,填写您最重要的详细信息:
WebHook : 在Mattermost上设置的传入Webhook URL
Username: 可选的用户名,可以在发送给Mattermost的信息中使用。
Notify only broken pipelines: 流水线失败后进行通知。
注意webhook,由于我们在k8s中,所以要填写svc的地址
这时候我们创建一个提交,看看Mattermost的channel中是否有通知
通过命令与GitLab交互
Mattermost命令为用户提供了一个额外的界面,可以在聊天环境中执行GitLab常见操作。例如,创建问题。
GitLab 启用服务
进入项目设置-> 集成 -> Mattermost slash commands。token在下个步骤中获取。
Mattermost 启用服务
token在上面填写
开始交互
在Mattermost中输入/gitlab指令,会提示您点击一个链接进行验证。