Dra-M Dra-M
首页
技术
冥思
哲学
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

莫小龙

保持理智,相信未来。
首页
技术
冥思
哲学
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • Java

  • Golang

  • 编程思想

  • 微服务

  • 中间件

  • Python

  • 运维

    • Linux

    • Bash

    • DevOps

      • 前言:搭建一套自有的围绕K8S的DevOps工具
      • 部署K8S -- kubeasz
      • 部署NFS服务器
      • 为K8S添加StorageClass
      • 学习用NodePort暴露K8S服务
      • 外部nginx代理到nodeport
      • 使用Docker安装LDAP
      • 使用K8S部署LDAP管理面板
      • 使用Docker部署第三方K8S面板Kuboard,并连接LDAP
      • 使用K8S部署GitLab,并连接LDAP
      • 使用K8S部署Jenkins,并连接LDAP
      • 使用K8S部署Nexus,并连接LDAP
      • Nexus Maven私服配置
      • Nexus Docker私服配置+K8S拉取私服镜像
      • Jenkins Pipeline 从 K8s Agent 启动构建
      • Jenkins Pipeline 拉取Git代码 获取提交信息
      • Jenkins Pipeline Maven打包
      • Jenkins Pipeline BuildDockerImage 推送到私服
      • Jenkins Pipeline 部署程序到K8S
      • Jenkins Pipeline 共享库
      • Loki日志收集+K8S
      • SkyWalking链路追踪+K8S、
      • SpringCloud+K8S联调说明
      • DevOps WebHook汇总 (Gitlab,Jenkins,K8S Event)
        • jenkins pipeline
        • gitlab push
        • k8s evnet
          • 配置config map
          • 部署kube-eventer
  • 技术
  • 运维
  • DevOps
莫小龙
2022-04-11
目录

DevOps WebHook汇总 (Gitlab,Jenkins,K8S Event)

# jenkins pipeline

这里我写了一个服务做中转,只记录一下jenkins pipeline如何发起HTTP请求,具体格式需自定义。

发起HTTP请求:

def send() {
    //return
    def body = """
       {
       "buildStatus": "${env.BUILD_STATUS}",
       "jobName": "${env.appName}",
       "buildUser": "${env.BUILD_USER}",
       "gitBranch": "${env.GIT_BRANCH}",
       "gitCommit": "${env.GIT_COMMIT}",
       "gitCommitUser": "${env.GIT_COMMITER}",
       "gitCommitMessage": "${env.GIT_MESSAGE}",
       "jobUrl": "${env.BUILD_URL}"
       }
       """
    httpRequest(customHeaders: [[name: 'Content-Type', value: 'application/json;charset=UTF-8']],
            httpMode: 'POST',
            requestBody: body,
            url: "http://feishu-adapter:8080/jenkins/push")
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# gitlab push

系统设置,系统钩子设置 admin/hooks

Push Events Gitlab的请求如下:

{
  "object_kind": "push",
  "event_name": "push",
  "before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
  "after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
  "ref": "refs/heads/master",
  "checkout_sha": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
  "message": "Hello World",
  "user_id": 4,
  "user_name": "John Smith",
  "user_email": "[email protected]",
  "user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
  "project_id": 15,
  "project": {
    "id": 15,
    "name": "gitlab",
    "description": "",
    "web_url": "http://test.example.com/gitlab/gitlab",
    "avatar_url": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80",
    "git_ssh_url": "[email protected]:gitlab/gitlab.git",
    "git_http_url": "http://test.example.com/gitlab/gitlab.git",
    "namespace": "gitlab",
    "visibility_level": 0,
    "path_with_namespace": "gitlab/gitlab",
    "default_branch": "master"
  },
  "commits": [
    {
      "id": "c5feabde2d8cd023215af4d2ceeb7a64839fc428",
      "message": "Add simple search to projects in public area\n\ncommit message body",
      "title": "Add simple search to projects in public area",
      "timestamp": "2013-05-13T18:18:08+00:00",
      "url": "https://test.example.com/gitlab/gitlab/-/commit/c5feabde2d8cd023215af4d2ceeb7a64839fc428",
      "author": {
        "name": "Test User",
        "email": "[email protected]"
      }
    }
  ],
  "total_commits_count": 1,
  "push_options": {
    "ci": {
      "skip": true
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

发到中转适配程序上转格,在适配过程中我关注到的是:

  • 项目名:.project.name
  • 分支:.ref
  • 用户名:.user_name
  • 提交数量:.commits.size
  • 最后提交hash:.commits[commits.size-1].id
  • 提交信息:.commits[n].message

# k8s evnet

https://github.com/AliyunContainerService/kube-eventer

我过滤了pod的killing和started事件,下面是推到飞书的配置:

# 配置config map

apiVersion: v1
data:
  content: '{ "msg_type": "interactive", "card": { "config": { "wide_screen_mode":
    true, "enable_forward": true }, "header": { "title": { "tag": "plain_text", "content":
    "{{ .Message }}" }, "template": "Blue" }, "elements": [ { "tag": "div", "text":
    { "tag": "lark_md", "content":  "**EventType:**  {{ .Type }}\n**EventKind:**  {{
    .InvolvedObject.Kind }}\n**EventReason:**  {{ .Reason }}\n**EventTime:**  {{ .LastTimestamp
    }}\n**EventMessage:**  {{ .Message }}" } } ] } }'
kind: ConfigMap
metadata:
  name: custom-webhook
  namespace: kube-system
  resourceVersion: "13695490"
  selfLink: /api/v1/namespaces/kube-system/configmaps/custom-webhook
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 部署kube-eventer

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    k8s.kuboard.cn/name: kube-eventer
    name: kube-eventer
  name: kube-eventer
  namespace: kube-system
spec:
  selector:
    matchLabels:
      app: kube-eventer
  template:
    labels:
      app: kube-eventer
    spec:
      containers:
        - command:
            - /kube-eventer
            - '--source=kubernetes:https://kubernetes.default'
            - >-
              --sink=webhook:https://open.feishu.cn/open-apis/bot/v2/hook/******************?level=Normal&kinds=Pod&reason=Killing,Started&method=POST&header=Content-Type=application/json&custom_body_configmap=custom-webhook&custom_body_configmap_namespace=kube-system
          env:
            - name: TZ
              value: Asia/Shanghai
          image: 'registry.aliyuncs.com/acs/kube-eventer-amd64:v1.2.0-484d9cd-aliyun'
          imagePullPolicy: IfNotPresent
          name: kube-eventer
          resources:
            limits:
              cpu: 500m
              memory: 250Mi
            requests:
              cpu: 100m
              memory: 100Mi
          volumeMounts:
            - mountPath: /etc/localtime
              name: localtime
              readOnly: true
            - mountPath: /usr/share/zoneinfo
              name: zoneinfo
              readOnly: true
      volumes:
        - hostPath:
            path: /etc/localtime
            type: ''
          name: localtime
        - hostPath:
            path: /usr/share/zoneinfo
            type: ''
          name: zoneinfo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

#DevOps#K8S#运维#WebHook
上次更新: 10/23/2024
SpringCloud+K8S联调说明

← SpringCloud+K8S联调说明

最近更新
01
mosquito配置ws协议
10-23
02
Pip包的离线下载和安装
10-23
03
stable diffusion 相关收藏
02-24
更多文章>
Theme by Vdoing | Copyright © 2019-2024 Dra-M
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式