forked from thijsvanloef/palworld-server-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request thijsvanloef#206 from NotaSF/NotaSF-backup-cron
Add Daily Reboot Cronjob (K8s)
- Loading branch information
Showing
13 changed files
with
215 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{{ if .Values.server.config.daily_reboot.enable }} | ||
apiVersion: batch/v1 | ||
kind: CronJob | ||
metadata: | ||
name: "{{ .Values.server.config.daily_reboot.serviceAccount }}" | ||
namespace: {{ .Values.namespace }} | ||
spec: | ||
concurrencyPolicy: Forbid | ||
schedule: "{{ .Values.server.config.daily_reboot.time }}" | ||
jobTemplate: | ||
spec: | ||
backoffLimit: 1 | ||
activeDeadlineSeconds: 600 | ||
template: | ||
spec: | ||
serviceAccountName: "{{ .Values.server.config.daily_reboot.serviceAccount }}" | ||
restartPolicy: Never | ||
containers: | ||
- name: kubectl | ||
image: bitnami/kubectl | ||
command: | ||
- /bin/sh | ||
- -c | ||
- /restart-script/restart-deployment.sh | ||
volumeMounts: | ||
- name: restart-script | ||
mountPath: "/restart-script" | ||
readOnly: true | ||
volumes: | ||
- name: restart-script | ||
configMap: | ||
name: "{{ .Release.Name }}-env-config" | ||
defaultMode: 0777 | ||
items: | ||
- key: "restart-deployment.sh" | ||
path: "restart-deployment.sh" | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{{ if .Values.server.config.daily_reboot.enable }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: "{{ .Values.server.config.daily_reboot.role }}" | ||
namespace: {{ .Values.namespace }} | ||
rules: | ||
- apiGroups: ["apps", "extensions"] | ||
resources: ["deployments", "pods"] | ||
verbs: ["get", "patch", "list", "watch"] | ||
- apiGroups: [""] | ||
resources: ["pods/exec", "pods"] | ||
verbs: ["get", "list", "create"] | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{ if .Values.server.config.daily_reboot.enable }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: "{{ .Values.server.config.daily_reboot.role }}-binding" | ||
namespace: {{ .Values.namespace }} | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: "{{ .Values.server.config.daily_reboot.role }}" | ||
subjects: | ||
- kind: ServiceAccount | ||
name: {{ .Values.server.config.daily_reboot.serviceAccount }} | ||
namespace: {{ .Values.namespace }} | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{ if .Values.server.config.daily_reboot.enable }} | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{ .Values.server.config.daily_reboot.serviceAccount }} | ||
namespace: {{ .Values.namespace }} | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: restart-deployment-configmap | ||
data: | ||
restart-deployment.sh: | | ||
#!/bin/bash | ||
cont=$(kubectl -n palworld get pods -o=jsonpath='{.items[?(@.metadata.labels.app=="palworld-server")].metadata.name}') | ||
function exec_rcon_cmd() { | ||
kubectl exec -n palworld -i pod/$cont rcon-cli "$1" | ||
} | ||
exec_rcon_cmd "Broadcast Saving_Server_Data..." | ||
exec_rcon_cmd save | ||
sleep 30 | ||
exec_rcon_cmd "Broadcast Backing_up_Server_Data..." | ||
kubectl exec -n palworld -i pod/$cont backup | ||
sleep 30 | ||
step = 5 | ||
for i in $(seq 30 -$step 1); do | ||
exec_rcon_cmd "Broadcast Rebooting_in_$i_seconds..." | ||
sleep $step | ||
done | ||
exec_rcon_cmd "Shutdown 1" | ||
sleep 30 | ||
kubectl -n palworld rollout restart deployment/palworld-server | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
apiVersion: batch/v1 | ||
kind: CronJob | ||
metadata: | ||
name: restart-deployment | ||
spec: | ||
concurrencyPolicy: Forbid | ||
schedule: '30 9 * * *' | ||
jobTemplate: | ||
spec: | ||
backoffLimit: 1 | ||
activeDeadlineSeconds: 600 | ||
template: | ||
spec: | ||
serviceAccountName: restart-deploy | ||
restartPolicy: Never | ||
containers: | ||
- name: kubectl | ||
image: bitnami/kubectl | ||
command: | ||
- /bin/sh | ||
- -c | ||
- /restart-script/restart-deployment.sh | ||
volumeMounts: | ||
- name: restart-script | ||
mountPath: "/restart-script" | ||
readOnly: true | ||
volumes: | ||
- name: restart-script | ||
configMap: | ||
name: restart-deployment-configmap | ||
defaultMode: 0777 | ||
items: | ||
- key: "restart-deployment.sh" | ||
path: "restart-deployment.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: restart-deployment | ||
rules: | ||
- apiGroups: ["apps", "extensions"] | ||
resources: ["deployments", "pods"] | ||
verbs: ["get", "patch", "list", "watch"] | ||
- apiGroups: [""] | ||
resources: ["pods/exec", "pods"] | ||
verbs: ["get", "list", "create"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: restart-deployment | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: restart-deployment | ||
subjects: | ||
- kind: ServiceAccount | ||
name: restart-deploy | ||
namespace: palworld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: restart-deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Example CronJob to Reboot Server Daily (9:30am UTC) | ||
|
||
Use the following commands to setup the cron job in the namespace palworld: | ||
|
||
* `kubectl apply -f cm.yaml` | ||
* `kubectl apply -f role.yaml` | ||
* `kubectl apply -f rolebinding.yaml` | ||
* `kubectl apply -f serviceaccount.yaml` | ||
* `kubectl apply -f cronjob.yaml` |