Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helm部署moon #123

Merged
merged 6 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@
>
>密码: 123456

#### helm部署

参考[/deploy/helm](./deploy/README.md)

## 3. 功能详解

### 3.1 系统管理
Expand Down
48 changes: 48 additions & 0 deletions deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Moon

Moon 是一款集成prometheus系列的监控管理工具,专为简化Prometheus监控系统的运维工作而设计。该工具提供了一站式的解决方案,能够集中管理和配置多个Prometheus实例及其相关的服务发现、规则集和警报通知。

本 chart 使用 [Helm](https://helm.sh) 包管理器实现在[Kubernetes](https://kubernetes.io) (k8s)集群上部署moon

## 安装Chart

注意: 暂时只支持helm3

- 通过源码安装(本示例默认源码安装)

```
kubectl create ns moon
helm install [RELEASE_NAME] moon/ -n moon
```

- 修改默认参数后, 打包上传到repos后, 例如https://artifacthub.io/, 再行安装

```
helm repo add moon https://xxxx.xxx.xx/moon
helm repo update
helm install [RELEASE_NAME] ./moon -n moon
```

## 卸载Chart

通过以下命令卸载:

```console
helm delete moon -n moon
```

## 更新Chart

```
helm upgrade [RELEASE_NAME] [CHART] -n moon --install
```

## 配置

- 详情请参考: [values.yaml](./values.yaml)

- 自定义参数:

```
helm install moon moon/ --set=service.port=31008,resources.limits.cpu=300m
```
23 changes: 23 additions & 0 deletions deploy/helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions deploy/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: moon
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
22 changes: 22 additions & 0 deletions deploy/helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services moon-server-svc)
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "moon.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "moon.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "moon.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions deploy/helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "moon.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "moon.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "moon.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "moon.labels" -}}
helm.sh/chart: {{ include "moon.chart" . }}
{{ include "moon.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "moon.selectorLabels" -}}
app.kubernetes.io/name: {{ include "moon.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "moon.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "moon.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions deploy/helm/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.moon.server }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Values.moon.server.serviceAccounts }}-role
namespace: {{ .Values.namespace }}
{{- end }}
{{- if .Values.moon.agent }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Values.moon.agent.serviceAccounts }}-role
namespace: {{ .Values.namespace }}
{{- end }}
26 changes: 26 additions & 0 deletions deploy/helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
{{- if .Values.moon.agent }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.moon.agent.name }}-config
namespace: {{ .Values.namespace }}
data:
config.yaml: |-
{{- toYaml .Values.moon.agent.config | nindent 4 }}
{{- end }}

{{- if .Values.moon.server }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.moon.server.name }}-config
namespace: {{ .Values.namespace }}
data:
config.yaml: |-
{{- toYaml .Values.moon.server.config | nindent 4 }}
{{- end }}
121 changes: 121 additions & 0 deletions deploy/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{{- if .Values.moon.agent }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
apps.moon/name: {{ .Values.moon.agent.name }}
name: {{ .Values.moon.agent.name }}
namespace: {{ .Values.namespace }}
spec:
replicas: {{ .Values.repliCount }}
selector:
matchLabels:
apps.moon/name: {{ .Values.moon.agent.name }}
template:
metadata:
labels:
apps.moon/name: {{ .Values.moon.agent.name }}
spec:
containers:
- args:
- --conf=/config/config.yaml
command:
- ./prom_agent
image: {{ .Values.moon.agent.image }}
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /ping
port: 8000
initialDelaySeconds: 15
periodSeconds: 20
name: moon-agent
readinessProbe:
httpGet:
path: /ping
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: "1"
memory: 1Gi
requests:
cpu: 10m
memory: 64Mi
securityContext:
allowPrivilegeEscalation: false
volumeMounts:
- mountPath: /config
name: {{ .Values.moon.agent.name }}-config
serviceAccountName: {{ .Values.moon.agent.serviceAccounts }}
terminationGracePeriodSeconds: 10
volumes:
- configMap:
name: {{ .Values.moon.agent.name }}-config
name: {{ .Values.moon.agent.name }}-config
{{- end }}
{{- if .Values.moon.server }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
apps.moon/name: {{ .Values.moon.server.name }}
name: {{ .Values.moon.server.name }}
namespace: {{ .Values.namespace }}
spec:
replicas: {{ .Values.repliCount }}
selector:
matchLabels:
apps.moon/name: {{ .Values.moon.server.name }}
template:
metadata:
labels:
apps.moon/name: {{ .Values.moon.server.name }}
spec:
containers:
- command:
- bash
- -c
- nginx && ./prom_server --conf=/config/config.yaml
image: {{ .Values.moon.server.image }}
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /ping
port: 8000
initialDelaySeconds: 15
periodSeconds: 20
name: {{ .Values.moon.server.name }}
readinessProbe:
httpGet:
path: /ping
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: "1"
memory: 1Gi
requests:
cpu: 10m
memory: 64Mi
securityContext:
allowPrivilegeEscalation: false
volumeMounts:
- mountPath: /config
name: {{ .Values.moon.server.name }}-config
- mountPath: /app/db
name: {{ .Values.moon.server.name }}-sqlite-volume
serviceAccountName: {{ .Values.moon.server.serviceAccounts }}
terminationGracePeriodSeconds: 10
volumes:
- configMap:
name: {{ .Values.moon.server.serviceAccounts }}-config
name: {{ .Values.moon.server.serviceAccounts }}-config
- name: {{ .Values.moon.server.serviceAccounts }}-sqlite-volume
persistentVolumeClaim:
claimName: moon-sqlite-pvc
{{- end }}
28 changes: 28 additions & 0 deletions deploy/helm/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "moon.fullname" . }}
labels:
{{- include "moon.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "moon.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
Loading
Loading