Skip to content

Commit

Permalink
Add clear mongo log (#4757)
Browse files Browse the repository at this point in the history
* update kafka monitor

* clear mongo log

* clear mongo log

* clear mongo log
  • Loading branch information
wallyxjh authored May 28, 2024
1 parent 9a4f321 commit b4187c5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
69 changes: 69 additions & 0 deletions deploy/cloud/manifests/clear-mongo-log.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: clear-mongo-logs-sa
namespace: sealos
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: clear-mongo-logs-role
namespace: sealos
rules:
- apiGroups: ["apps.kubeblocks.io"]
resources: ["clusters"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["pods","pods/exec"]
verbs: ["*"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: clear-mongo-logs-rolebinding
namespace: sealos
subjects:
- kind: ServiceAccount
name: clear-mongo-logs-sa
namespace: sealos
roleRef:
kind: ClusterRole
name: clear-mongo-logs-role
apiGroup: rbac.authorization.k8s.io
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: clear-mongo-logs
namespace: sealos
spec:
schedule: "0 0 * * *"
jobTemplate:
spec:
template:
spec:
serviceAccountName: clear-mongo-logs-sa
containers:
- name: clear-logs
image: bitnami/kubectl:1.28
command:
- /bin/bash
- -c
- |
clusters=$(kubectl get cluster.apps.kubeblocks.io -A -l clusterdefinition.kubeblocks.io/name=mongodb)
echo "$clusters" | while read -r line; do
namespace=$(echo "$line" | awk '{print $1}')
cluster_name=$(echo "$line" | awk '{print $2}')
pods=$(kubectl get pod -n "${namespace}" -o=custom-columns=NAME:.metadata.name,NODE:.spec.nodeName | grep "${cluster_name}")
echo "$pods" | while read -r pod_line; do
pod_name=$(echo "$pod_line" | awk '{print $1}')
if [ -n "$pod_name" ]; then
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'
fi
done
done
securityContext:
runAsUser: 0
allowPrivilegeEscalation: false
runAsNonRoot: true
restartPolicy: OnFailure
3 changes: 3 additions & 0 deletions deploy/cloud/scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ function prepare {
# apply notifications crd
kubectl apply -f manifests/notifications_crd.yaml

# clear mongo log by cronjob,temporary solution
kubectl apply -f manifests/clear-mongo-log.yaml

# gen mongodb uri
gen_mongodbUri

Expand Down

0 comments on commit b4187c5

Please sign in to comment.