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 <xxx@xxx.com>
#切換映象目錄,進入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