Skip to content

Commit b4187c5

Browse files
authored
Add clear mongo log (#4757)
* update kafka monitor * clear mongo log * clear mongo log * clear mongo log
1 parent 9a4f321 commit b4187c5

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

Diff for: deploy/cloud/manifests/clear-mongo-log.yaml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: clear-mongo-logs-sa
5+
namespace: sealos
6+
---
7+
apiVersion: rbac.authorization.k8s.io/v1
8+
kind: ClusterRole
9+
metadata:
10+
name: clear-mongo-logs-role
11+
namespace: sealos
12+
rules:
13+
- apiGroups: ["apps.kubeblocks.io"]
14+
resources: ["clusters"]
15+
verbs: ["get", "list", "watch"]
16+
- apiGroups: [""]
17+
resources: ["pods","pods/exec"]
18+
verbs: ["*"]
19+
---
20+
apiVersion: rbac.authorization.k8s.io/v1
21+
kind: ClusterRoleBinding
22+
metadata:
23+
name: clear-mongo-logs-rolebinding
24+
namespace: sealos
25+
subjects:
26+
- kind: ServiceAccount
27+
name: clear-mongo-logs-sa
28+
namespace: sealos
29+
roleRef:
30+
kind: ClusterRole
31+
name: clear-mongo-logs-role
32+
apiGroup: rbac.authorization.k8s.io
33+
---
34+
apiVersion: batch/v1
35+
kind: CronJob
36+
metadata:
37+
name: clear-mongo-logs
38+
namespace: sealos
39+
spec:
40+
schedule: "0 0 * * *"
41+
jobTemplate:
42+
spec:
43+
template:
44+
spec:
45+
serviceAccountName: clear-mongo-logs-sa
46+
containers:
47+
- name: clear-logs
48+
image: bitnami/kubectl:1.28
49+
command:
50+
- /bin/bash
51+
- -c
52+
- |
53+
clusters=$(kubectl get cluster.apps.kubeblocks.io -A -l clusterdefinition.kubeblocks.io/name=mongodb)
54+
echo "$clusters" | while read -r line; do
55+
namespace=$(echo "$line" | awk '{print $1}')
56+
cluster_name=$(echo "$line" | awk '{print $2}')
57+
pods=$(kubectl get pod -n "${namespace}" -o=custom-columns=NAME:.metadata.name,NODE:.spec.nodeName | grep "${cluster_name}")
58+
echo "$pods" | while read -r pod_line; do
59+
pod_name=$(echo "$pod_line" | awk '{print $1}')
60+
if [ -n "$pod_name" ]; then
61+
kubectl exec -it ${pod_name} -n ${namespace} -- /bin/bash -c 'if [ -d /data/mongodb/logs ]; then cat /dev/null > /data/mongodb/logs/mongodb.log; fi'
62+
fi
63+
done
64+
done
65+
securityContext:
66+
runAsUser: 0
67+
allowPrivilegeEscalation: false
68+
runAsNonRoot: true
69+
restartPolicy: OnFailure

Diff for: deploy/cloud/scripts/init.sh

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ function prepare {
2323
# apply notifications crd
2424
kubectl apply -f manifests/notifications_crd.yaml
2525

26+
# clear mongo log by cronjob,temporary solution
27+
kubectl apply -f manifests/clear-mongo-log.yaml
28+
2629
# gen mongodb uri
2730
gen_mongodbUri
2831

0 commit comments

Comments
 (0)