K8S部署WGCLOUD运维监控系统

1.WGCLOUD介绍

WGCLOUD属于极简及高效的主机监控系统,支持主机各种指标监测,
并且支持故障告警信息推送,开源系统足以满足我们对测试环境机器的监控,所以用起来。

2.WGCLOUD基于K8S部署
2.1.官网下载v3.4.6版本tar.gz安装包

wgcloud-v3.4.6.tar.gz

2.2.新建数据库,导入数据

(1)解压wgcloud-v3.4.6.tar.gz安装包
(2)在解压目录下会发现wgcloud-MySQL.sql、wgcloud-Oracle.sql和wgcloud-PostgreSQL.sql三份sql文件
(3)根据自己的需要选择对应的sql文件导入,笔者这里以mysql为主
(4)修改server/config/application.yml文件的数据库连接信息,更新为自己的数据库连接信息及对应的驱动即可

2.3.编写server端Dockerfile

#基础镜像
FROM java:8
#作者
MAINTAINER xxx 
#切换镜像目录,进入usr目录
WORKDIR /wgcloud
RUN mkdir wgcloud
ADD . /wgcloud/
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone
CMD ["/wgcloud/wgcloud/server/start.sh"]

2.4.制作镜像

docker buld -t harbor.xxx.xxx/qa-dev/wgcloud/wgcloud:v1 .

2.5.将镜像推送至harbor仓库

docker push harbor.xxx.xxx/qa-dev/wgcloud/wgcloud:v1

2.6.编写k8s yaml文件

kind: Deployment
metadata:
  name: wgcloud-deployment
  labels:
    app: wgcloud
    namespace: k8s-jenkins  #这里根据自己的namespace做调整
spec:
  replicas: 1 #控制管理运行的pod个数
  selector:
    matchLabels:   #标签
      app: wgcloud
  template:
    metadata:
      labels:
        app: wgcloud
    spec:
      containers:
        - name: wgcloud
          image: harbor.xxx.xxx/qa-dev/wgcloud/wgcloud:v1
          imagePullPolicy: Always
          ports:
            - containerPort: 9997  #容器暴露的端口号-1
            - containerPort: 9998  #容器暴露的端口号-2
            - containerPort: 9999  #容器暴露的端口号-3
      imagePullSecrets:
        - name: docker-harbor-slave

---

apiVersion: v1
kind: Service
metadata:
  name: wgcloud-service
spec:
  selector:
    app: wgcloud
  ports:
    - name: http-test1
      port: 9997
      protocol: TCP
      nodePort: xxx-1  #根据自己的nodePort做调整
    - name: http-test2
      port: 9998
      protocol: TCP
      nodePort: xxx-2
    - name: http-test3
      port: 9999
      protocol: TCP
      nodePort: xxx-3  #指定节点开放的端口
  type: NodePort
  selector:
    app: wgcloud

2.7.接入jenkins,pipeline


def label = "slave-${UUID.randomUUID().toString()}"

podTemplate(label: label, serviceAccount: "xxx,拥有某某个角色的账号",imagePullSecrets: [ 'xxx'  拉取镜像的密码],  containers: [
  containerTemplate(name: 'kubectl', image: 'harbor.pwesports.net/qa-dev/kubectl:v1', command: 'cat', ttyEnabled: true)
], volumes: [
  hostPathVolume(mountPath: '/home/jenkins/.kube', hostPath: '/root/.kube'),
],yaml: '''
          spec:
            containers:
            - name: kaniko
              image: harbor.pwesports.net/qa-dev/kaniko:v2
              command:
              - /busybox/cat
              tty: true
              volumeMounts:
              - name: docker-config
                mountPath: /kaniko/.docker
            restartPolicy: Never
            volumes:
            - name: docker-config
              secret:
                secretName: docker-harbor-slave
                items:
                  - key: .dockerconfigjson
                    path: config.json
            hostAliases:
            - ip: "172.16.xxx.xxx"
              hostnames:  #代码仓库地址
              - "gitlab.xxx.xxx"
            - ip: "172.16.xxx.xxx"  ###harbor地址
              hostnames:
              - "harbor.xxx.xxx"
          ''') {
  node(label) {

     stage('运行 Kubectl') {
        git credentialsId: 'xxxx-4c16-479c-8cd3-2b29f828e71b', url: 'http://gitlab.xxx.xxx/QA/xxx.git', branch: 'master'
        container('kubectl') {
             sh """
                kubectl apply -f ${workspace}/k8s-config/wgcloud.yaml
             """
        }
     }
  }
}

3.访问

http://nodeIP:nodePort/wgcloud/login/toLogin 

你可能感兴趣的:(kubernetes)