From 3caf4995319ae277053623ae909601b19076ccb6 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 11:12:14 -0500 Subject: [PATCH 01/22] Add Daily Regboot Cronjob Requires the k8s deployment to be in the palworld namespace. This launches a cronjob to run a shell script (defined in cm.yaml), which sends a broadcast notifying players that the server is saving. After 30 seconds, it does a formal backup using the established 'exec pod/podnamehere backup' command in the repo. After 30 seconds later, it sends a broadcast notifying players that the server will reboot in 60 seconds; 30 seconds; then each second for the last 10 seconds. It the runs the "Shutdown 1" command via rcon-cli, waits 30 additional seconds, then redeploys the application. Currently, it is set to run at 9:30am UTC daily. I'm newer to configuring such things, and will work to improve/cleanup a little bit. :) --- k8s/cronjob-reboot/cm.yaml | 43 ++++++++++++++++++++++++++ k8s/cronjob-reboot/cronjob.yaml | 36 +++++++++++++++++++++ k8s/cronjob-reboot/role.yaml | 13 ++++++++ k8s/cronjob-reboot/rolebinding.yaml | 13 ++++++++ k8s/cronjob-reboot/serviceaccount.yaml | 5 +++ 5 files changed, 110 insertions(+) create mode 100644 k8s/cronjob-reboot/cm.yaml create mode 100644 k8s/cronjob-reboot/cronjob.yaml create mode 100644 k8s/cronjob-reboot/role.yaml create mode 100644 k8s/cronjob-reboot/rolebinding.yaml create mode 100644 k8s/cronjob-reboot/serviceaccount.yaml diff --git a/k8s/cronjob-reboot/cm.yaml b/k8s/cronjob-reboot/cm.yaml new file mode 100644 index 000000000..1a5bbde4f --- /dev/null +++ b/k8s/cronjob-reboot/cm.yaml @@ -0,0 +1,43 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: restart-deployment-configmap + namespace: palworld +data: + restart-deployment.sh: | + #!/bin/bash + cont=$(kubectl -n palworld get pods -o=jsonpath='{.items[?(@.metadata.labels.app=="palworld-server")].metadata.name}') + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Saving_Server_Data..." + kubectl exec -n palworld -i pod/$cont rcon-cli save + sleep 30 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Backing_up_Server_Data..." + kubectl exec -n palworld -i pod/$cont backup + sleep 30 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Backup_Complete!_Rebooting_in_30_seconds..." + sleep 15 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_15_seconds..." + sleep 5 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_10_seconds..." + sleep 1 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_9_seconds..." + sleep 1 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_8_seconds..." + sleep 1 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_7_seconds..." + sleep 1 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_6_seconds..." + sleep 1 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_5_seconds..." + sleep 1 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_4_seconds..." + sleep 1 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_3_seconds..." + sleep 1 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_2_seconds..." + sleep 1 + kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_1_seconds..." + sleep 1 + kubectl exec -n palworld -i pod/$cont rcon-cli "Shutdown 1" + sleep 30 + kubectl -n palworld rollout restart deployment/palworld-server + diff --git a/k8s/cronjob-reboot/cronjob.yaml b/k8s/cronjob-reboot/cronjob.yaml new file mode 100644 index 000000000..723e1da14 --- /dev/null +++ b/k8s/cronjob-reboot/cronjob.yaml @@ -0,0 +1,36 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: restart-deployment + namespace: palworld +spec: + concurrencyPolicy: Forbid +# schedule: '30 4 * * *' + 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" diff --git a/k8s/cronjob-reboot/role.yaml b/k8s/cronjob-reboot/role.yaml new file mode 100644 index 000000000..34230681d --- /dev/null +++ b/k8s/cronjob-reboot/role.yaml @@ -0,0 +1,13 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: restart-deployment + namespace: palworld +rules: + - apiGroups: ["apps", "extensions"] + resources: ["deployments", "pods"] + #resourceNames: ["palworld-server"] + verbs: ["get", "patch", "list", "watch"] + - apiGroups: [""] + resources: ["pods/exec", "pods"] + verbs: ["get", "list", "create"] diff --git a/k8s/cronjob-reboot/rolebinding.yaml b/k8s/cronjob-reboot/rolebinding.yaml new file mode 100644 index 000000000..b4b83be42 --- /dev/null +++ b/k8s/cronjob-reboot/rolebinding.yaml @@ -0,0 +1,13 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: restart-deployment + namespace: palworld +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: restart-deployment +subjects: + - kind: ServiceAccount + name: restart-deploy + namespace: palworld diff --git a/k8s/cronjob-reboot/serviceaccount.yaml b/k8s/cronjob-reboot/serviceaccount.yaml new file mode 100644 index 000000000..56e2366d8 --- /dev/null +++ b/k8s/cronjob-reboot/serviceaccount.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: restart-deploy + namespace: palworld From 17d480961077e8af6a855d41da3664787faa9ef6 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 11:25:33 -0500 Subject: [PATCH 02/22] Remove commented-out section --- k8s/cronjob-reboot/cronjob.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/k8s/cronjob-reboot/cronjob.yaml b/k8s/cronjob-reboot/cronjob.yaml index 723e1da14..bb0f0b139 100644 --- a/k8s/cronjob-reboot/cronjob.yaml +++ b/k8s/cronjob-reboot/cronjob.yaml @@ -5,7 +5,6 @@ metadata: namespace: palworld spec: concurrencyPolicy: Forbid -# schedule: '30 4 * * *' schedule: '30 9 * * *' jobTemplate: spec: From e1a8ef0e6594439aea4ea8dd13c0b672299d1e4c Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 11:25:59 -0500 Subject: [PATCH 03/22] Update role.yaml Removed commented out section --- k8s/cronjob-reboot/role.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/k8s/cronjob-reboot/role.yaml b/k8s/cronjob-reboot/role.yaml index 34230681d..444333f70 100644 --- a/k8s/cronjob-reboot/role.yaml +++ b/k8s/cronjob-reboot/role.yaml @@ -6,7 +6,6 @@ metadata: rules: - apiGroups: ["apps", "extensions"] resources: ["deployments", "pods"] - #resourceNames: ["palworld-server"] verbs: ["get", "patch", "list", "watch"] - apiGroups: [""] resources: ["pods/exec", "pods"] From 119598cf92cbc38f1084112330a797475cc47a07 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:43:12 -0500 Subject: [PATCH 04/22] Update serviceaccount.yaml Indentation; namespace adjustment --- k8s/cronjob-reboot/serviceaccount.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/k8s/cronjob-reboot/serviceaccount.yaml b/k8s/cronjob-reboot/serviceaccount.yaml index 56e2366d8..54f422bd8 100644 --- a/k8s/cronjob-reboot/serviceaccount.yaml +++ b/k8s/cronjob-reboot/serviceaccount.yaml @@ -1,5 +1,4 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: restart-deploy - namespace: palworld + name: restart-deploy From 895e647c641283ffe0304515a8f58fa8bb213db8 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:43:36 -0500 Subject: [PATCH 05/22] Update rolebinding.yaml Remove namespace --- k8s/cronjob-reboot/rolebinding.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/k8s/cronjob-reboot/rolebinding.yaml b/k8s/cronjob-reboot/rolebinding.yaml index b4b83be42..4012b1714 100644 --- a/k8s/cronjob-reboot/rolebinding.yaml +++ b/k8s/cronjob-reboot/rolebinding.yaml @@ -2,7 +2,6 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: restart-deployment - namespace: palworld roleRef: apiGroup: rbac.authorization.k8s.io kind: Role From 03f2b47f23a07359f7c8593b44d506803ec99023 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:43:46 -0500 Subject: [PATCH 06/22] Update role.yaml Remove namespace --- k8s/cronjob-reboot/role.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/k8s/cronjob-reboot/role.yaml b/k8s/cronjob-reboot/role.yaml index 444333f70..2e2bc3bfc 100644 --- a/k8s/cronjob-reboot/role.yaml +++ b/k8s/cronjob-reboot/role.yaml @@ -2,7 +2,6 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: restart-deployment - namespace: palworld rules: - apiGroups: ["apps", "extensions"] resources: ["deployments", "pods"] From 888b6114d466f6b3397ba3efd66cdc96e60b12e3 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:44:21 -0500 Subject: [PATCH 07/22] Update cronjob.yaml Remove namespace --- k8s/cronjob-reboot/cronjob.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/k8s/cronjob-reboot/cronjob.yaml b/k8s/cronjob-reboot/cronjob.yaml index bb0f0b139..a52d5dfbd 100644 --- a/k8s/cronjob-reboot/cronjob.yaml +++ b/k8s/cronjob-reboot/cronjob.yaml @@ -2,7 +2,6 @@ apiVersion: batch/v1 kind: CronJob metadata: name: restart-deployment - namespace: palworld spec: concurrencyPolicy: Forbid schedule: '30 9 * * *' From 211b464e4ccdf61ca867599114c01bde120d37bb Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:45:34 -0500 Subject: [PATCH 08/22] Update cm.yaml Remove namespace --- k8s/cronjob-reboot/cm.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/k8s/cronjob-reboot/cm.yaml b/k8s/cronjob-reboot/cm.yaml index 1a5bbde4f..2fd826cfa 100644 --- a/k8s/cronjob-reboot/cm.yaml +++ b/k8s/cronjob-reboot/cm.yaml @@ -2,7 +2,6 @@ apiVersion: v1 kind: ConfigMap metadata: name: restart-deployment-configmap - namespace: palworld data: restart-deployment.sh: | #!/bin/bash From 272677d5bb0b017d5d2830ab50736455fc8c44b1 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:46:36 -0500 Subject: [PATCH 09/22] Update values.yaml Add additional parameters for cronjob --- charts/palworld/values.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/charts/palworld/values.yaml b/charts/palworld/values.yaml index 4f3707433..ef12fbe66 100644 --- a/charts/palworld/values.yaml +++ b/charts/palworld/values.yaml @@ -151,6 +151,17 @@ server: # -- (string) Update/Install the server when the container starts. # THIS HAS TO BE ENABLED THE FIRST TIME YOU RUN THE CONTAINER update_on_boot: true + daily_reboot: + # -- (bool) Enable daily reboot. + # Disabled by default + enable: false + # -- (string) The time (UTC) the server will perform the reboot. + # By default, this schedules the restart at 9:30am UTC. Please note, this is using cron syntax. + time: "30 9 * * *" + # -- (string) The name of the role performing the daily reboot. + role: "daily-reboot" + # -- (string) The name of the Service Account used to perform the reboot. + serviceAccount: "daily-reboot" # -- (object) Configures the game world settings. # The key:values here should represent in game accepted values. # Wrap all values with quotes here to avoid validation issues. From 60d5219198b6ba97b6d8aceebc47a24dcdf3c214 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:48:02 -0500 Subject: [PATCH 10/22] Add cronjob, role, rolebinding, SA yaml --- charts/palworld/templates/cronjob.yaml | 37 +++++++++++++++++++ charts/palworld/templates/role.yaml | 14 +++++++ charts/palworld/templates/rolebinding.yaml | 15 ++++++++ charts/palworld/templates/serviceaccount.yaml | 7 ++++ 4 files changed, 73 insertions(+) create mode 100644 charts/palworld/templates/cronjob.yaml create mode 100644 charts/palworld/templates/role.yaml create mode 100644 charts/palworld/templates/rolebinding.yaml create mode 100644 charts/palworld/templates/serviceaccount.yaml diff --git a/charts/palworld/templates/cronjob.yaml b/charts/palworld/templates/cronjob.yaml new file mode 100644 index 000000000..dbdffb41c --- /dev/null +++ b/charts/palworld/templates/cronjob.yaml @@ -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 }} \ No newline at end of file diff --git a/charts/palworld/templates/role.yaml b/charts/palworld/templates/role.yaml new file mode 100644 index 000000000..f1c955027 --- /dev/null +++ b/charts/palworld/templates/role.yaml @@ -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 }} diff --git a/charts/palworld/templates/rolebinding.yaml b/charts/palworld/templates/rolebinding.yaml new file mode 100644 index 000000000..efd2f3f8b --- /dev/null +++ b/charts/palworld/templates/rolebinding.yaml @@ -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 }} diff --git a/charts/palworld/templates/serviceaccount.yaml b/charts/palworld/templates/serviceaccount.yaml new file mode 100644 index 000000000..03419297a --- /dev/null +++ b/charts/palworld/templates/serviceaccount.yaml @@ -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 }} \ No newline at end of file From 6bd97b675588d685958c49fa5a30daebde006063 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:48:59 -0500 Subject: [PATCH 11/22] Adjust configmaps.yaml for shell script --- charts/palworld/templates/configmaps.yaml | 40 ++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/charts/palworld/templates/configmaps.yaml b/charts/palworld/templates/configmaps.yaml index 58cfd91de..d74625566 100644 --- a/charts/palworld/templates/configmaps.yaml +++ b/charts/palworld/templates/configmaps.yaml @@ -48,4 +48,42 @@ data: {{- with .Values.server.config.world_parameters }} {{- toYaml . | nindent 2 }} {{- end }} - {{ end }} \ No newline at end of file + {{ if .Values.server.config.daily_reboot.enable }} + restart-deployment.sh: | + #!/bin/bash + cont=$(kubectl -n {{ .Values.namespace }} get pods -o=jsonpath='{.items[?(@.metadata.labels.app.kubernetes.io/name=="{{ .Release.Name }}-server")].metadata.name}') + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Saving_Server_Data..." + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli save + sleep 30 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Backing_up_Server_Data..." + kubectl exec -n {{ .Values.namespace }} -i pod/$cont backup + sleep 30 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Backup_Complete!_Rebooting_in_30_seconds..." + sleep 15 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_15_seconds..." + sleep 5 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_10_seconds..." + sleep 1 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_9_seconds..." + sleep 1 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_8_seconds..." + sleep 1 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_7_seconds..." + sleep 1 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_6_seconds..." + sleep 1 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_5_seconds..." + sleep 1 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_4_seconds..." + sleep 1 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_3_seconds..." + sleep 1 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_2_seconds..." + sleep 1 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_1_seconds..." + sleep 1 + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Shutdown 1" + sleep 30 + kubectl -n {{ .Values.namespace }} rollout restart deployment/{{ .Release.Name }}-server + {{ end }} + {{ end }} From 7ad41b97c9e5c9677b6014844d0215322ff33169 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:22:35 -0500 Subject: [PATCH 12/22] Update configmaps.yaml Implemented loop by @PaulusParssinen --- charts/palworld/templates/configmaps.yaml | 46 +++++++++-------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/charts/palworld/templates/configmaps.yaml b/charts/palworld/templates/configmaps.yaml index d74625566..951f3ab88 100644 --- a/charts/palworld/templates/configmaps.yaml +++ b/charts/palworld/templates/configmaps.yaml @@ -52,37 +52,25 @@ data: restart-deployment.sh: | #!/bin/bash cont=$(kubectl -n {{ .Values.namespace }} get pods -o=jsonpath='{.items[?(@.metadata.labels.app.kubernetes.io/name=="{{ .Release.Name }}-server")].metadata.name}') - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Saving_Server_Data..." - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli save + + function exec_rcon_cmd() { + kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "$1" + } + + exec_rcon_cmd "Broadcast Saving_Server_Data..." + exec_rcon_cmd save sleep 30 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Backing_up_Server_Data..." - kubectl exec -n {{ .Values.namespace }} -i pod/$cont backup + exec_rcon_cmd "Broadcast Backing_up_Server_Data..." + exec_rcon_cmd backup sleep 30 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Backup_Complete!_Rebooting_in_30_seconds..." - sleep 15 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_15_seconds..." - sleep 5 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_10_seconds..." - sleep 1 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_9_seconds..." - sleep 1 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_8_seconds..." - sleep 1 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_7_seconds..." - sleep 1 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_6_seconds..." - sleep 1 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_5_seconds..." - sleep 1 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_4_seconds..." - sleep 1 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_3_seconds..." - sleep 1 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_2_seconds..." - sleep 1 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Broadcast Rebooting_in_1_seconds..." - sleep 1 - kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "Shutdown 1" + + 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 {{ .Values.namespace }} rollout restart deployment/{{ .Release.Name }}-server {{ end }} From 98ebcf4fcda1e688736dea4aa56792c9f5a86092 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:02:44 -0500 Subject: [PATCH 13/22] Update configmaps.yaml Forgot escape characters. --- charts/palworld/templates/configmaps.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/palworld/templates/configmaps.yaml b/charts/palworld/templates/configmaps.yaml index 951f3ab88..c9a73eb19 100644 --- a/charts/palworld/templates/configmaps.yaml +++ b/charts/palworld/templates/configmaps.yaml @@ -51,7 +51,7 @@ data: {{ if .Values.server.config.daily_reboot.enable }} restart-deployment.sh: | #!/bin/bash - cont=$(kubectl -n {{ .Values.namespace }} get pods -o=jsonpath='{.items[?(@.metadata.labels.app.kubernetes.io/name=="{{ .Release.Name }}-server")].metadata.name}') + cont=$(kubectl -n {{ .Values.namespace }} get pods -o=jsonpath='{.items[?(@.metadata.labels.app\.kubernetes\.io/name=="{{ .Release.Name }}-server")].metadata.name}') function exec_rcon_cmd() { kubectl exec -n {{ .Values.namespace }} -i pod/$cont rcon-cli "$1" From 744f4c7cd2cdf1f17028e812481e177f936de205 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Tue, 30 Jan 2024 15:52:32 -0500 Subject: [PATCH 14/22] Update k8s/cronjob-reboot/cm.yaml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add suggestion for cronjob CM script cleanup Co-authored-by: Paulus Pärssinen --- k8s/cronjob-reboot/cm.yaml | 44 ++++++++++++++------------------------ 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/k8s/cronjob-reboot/cm.yaml b/k8s/cronjob-reboot/cm.yaml index 2fd826cfa..79ba5e879 100644 --- a/k8s/cronjob-reboot/cm.yaml +++ b/k8s/cronjob-reboot/cm.yaml @@ -6,37 +6,25 @@ data: restart-deployment.sh: | #!/bin/bash cont=$(kubectl -n palworld get pods -o=jsonpath='{.items[?(@.metadata.labels.app=="palworld-server")].metadata.name}') - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Saving_Server_Data..." - kubectl exec -n palworld -i pod/$cont rcon-cli save + + 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 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Backing_up_Server_Data..." + exec_rcon_cmd "Broadcast Backing_up_Server_Data..." kubectl exec -n palworld -i pod/$cont backup sleep 30 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Backup_Complete!_Rebooting_in_30_seconds..." - sleep 15 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_15_seconds..." - sleep 5 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_10_seconds..." - sleep 1 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_9_seconds..." - sleep 1 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_8_seconds..." - sleep 1 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_7_seconds..." - sleep 1 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_6_seconds..." - sleep 1 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_5_seconds..." - sleep 1 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_4_seconds..." - sleep 1 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_3_seconds..." - sleep 1 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_2_seconds..." - sleep 1 - kubectl exec -n palworld -i pod/$cont rcon-cli "Broadcast Rebooting_in_1_seconds..." - sleep 1 - kubectl exec -n palworld -i pod/$cont rcon-cli "Shutdown 1" + + 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 From ddc877c7e843bc6d2e9d9d857757c8b308f1b0af Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Tue, 30 Jan 2024 15:58:35 -0500 Subject: [PATCH 15/22] Create readme.md --- k8s/examples/readme.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 k8s/examples/readme.md diff --git a/k8s/examples/readme.md b/k8s/examples/readme.md new file mode 100644 index 000000000..5953f9d14 --- /dev/null +++ b/k8s/examples/readme.md @@ -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` From 4d9300664d822031edd0116999bf1f9e2b2fc315 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:00:55 -0500 Subject: [PATCH 16/22] Rename k8s/cronjob-reboot/cm.yaml to k8s/examples/cronjob-reboot/cm.yaml --- k8s/{ => examples}/cronjob-reboot/cm.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename k8s/{ => examples}/cronjob-reboot/cm.yaml (100%) diff --git a/k8s/cronjob-reboot/cm.yaml b/k8s/examples/cronjob-reboot/cm.yaml similarity index 100% rename from k8s/cronjob-reboot/cm.yaml rename to k8s/examples/cronjob-reboot/cm.yaml From b19e28ec6ce1bb12fcaef13b8ec5d3c6b255374e Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:01:48 -0500 Subject: [PATCH 17/22] Rename k8s/cronjob-reboot/cronjob.yaml to k8s/examples/cronjob-reboot/cronjob.yaml --- k8s/{ => examples}/cronjob-reboot/cronjob.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename k8s/{ => examples}/cronjob-reboot/cronjob.yaml (100%) diff --git a/k8s/cronjob-reboot/cronjob.yaml b/k8s/examples/cronjob-reboot/cronjob.yaml similarity index 100% rename from k8s/cronjob-reboot/cronjob.yaml rename to k8s/examples/cronjob-reboot/cronjob.yaml From 1807dbbb88e52df69403bfad63ad18639e571265 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:02:42 -0500 Subject: [PATCH 18/22] Rename k8s/cronjob-reboot/role.yaml to k8s/examples/cronjob-reboot/role.yaml --- k8s/{ => examples}/cronjob-reboot/role.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename k8s/{ => examples}/cronjob-reboot/role.yaml (100%) diff --git a/k8s/cronjob-reboot/role.yaml b/k8s/examples/cronjob-reboot/role.yaml similarity index 100% rename from k8s/cronjob-reboot/role.yaml rename to k8s/examples/cronjob-reboot/role.yaml From ff929d24a14078152e733b9128124324900f79d6 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:03:17 -0500 Subject: [PATCH 19/22] Rename k8s/cronjob-reboot/rolebinding.yaml to k8s/examples/cronjob-reboot/rolebinding.yaml --- k8s/{ => examples}/cronjob-reboot/rolebinding.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename k8s/{ => examples}/cronjob-reboot/rolebinding.yaml (100%) diff --git a/k8s/cronjob-reboot/rolebinding.yaml b/k8s/examples/cronjob-reboot/rolebinding.yaml similarity index 100% rename from k8s/cronjob-reboot/rolebinding.yaml rename to k8s/examples/cronjob-reboot/rolebinding.yaml From 90f7a91fce1db2366e2bc8b85bb974a6a81e7778 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:03:46 -0500 Subject: [PATCH 20/22] Rename k8s/cronjob-reboot/serviceaccount.yaml to k8s/examples/cronjob-reboot/serviceaccount.yaml --- k8s/{ => examples}/cronjob-reboot/serviceaccount.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename k8s/{ => examples}/cronjob-reboot/serviceaccount.yaml (100%) diff --git a/k8s/cronjob-reboot/serviceaccount.yaml b/k8s/examples/cronjob-reboot/serviceaccount.yaml similarity index 100% rename from k8s/cronjob-reboot/serviceaccount.yaml rename to k8s/examples/cronjob-reboot/serviceaccount.yaml From 5e994c12f31fc755d26dd57aa2195e49b5df74b4 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:25:19 -0500 Subject: [PATCH 21/22] Update VALUES_SUMMARY.md Generated updated VALUES_SUMMARY with helm-docs --- charts/palworld/VALUES_SUMMARY.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/charts/palworld/VALUES_SUMMARY.md b/charts/palworld/VALUES_SUMMARY.md index 7526ee6bf..af4a31288 100644 --- a/charts/palworld/VALUES_SUMMARY.md +++ b/charts/palworld/VALUES_SUMMARY.md @@ -1,8 +1,6 @@ # palworld -![Version: 0.0.2](https://img.shields.io/badge/Version-0.0.2-informational) -![Type: application](https://img.shields.io/badge/Type-application-informational) -![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational) +![Version: 0.0.2](https://img.shields.io/badge/Version-0.0.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square) This chart will provide a Palworld server installation on a kubernetes cluster. @@ -29,6 +27,10 @@ This chart will provide a Palworld server installation on a kubernetes cluster. | server.config.annotations | object | `{}` | Additional annotations to the resources | | server.config.community.enable | bool | `true` | Enables/disables the visibility of this server on Steam community servers list. | | server.config.community.password | string | `""` | If not provided, a random password will be generated and stored on the secret. | +| server.config.daily_reboot.enable | bool | `false` | Enable daily reboot. Disabled by default | +| server.config.daily_reboot.role | string | `"daily-reboot"` | The name of the role performing the daily reboot. | +| server.config.daily_reboot.serviceAccount | string | `"daily-reboot"` | The name of the Service Account used to perform the reboot. | +| server.config.daily_reboot.time | string | `"30 9 * * *"` | The time (UTC) the server will perform the reboot. By default, this schedules the restart at 9:30am UTC. Please note, this is using cron syntax. | | server.config.labels | object | `{}` | Additional labels to the resources | | server.config.max_players | int | `16` | The max number of players supported. | | server.config.multithreading | bool | `true` | Enables the multithreading, allowing the usage of up to 4 cores (needs citation) | From 91786eae158318ca5ae56e054a4f15c9576cb1a4 Mon Sep 17 00:00:00 2001 From: NotaSF <37776707+NotaSF@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:52:31 -0500 Subject: [PATCH 22/22] Update VALUES_SUMMARY.md Fix markdown linting error --- charts/palworld/VALUES_SUMMARY.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/charts/palworld/VALUES_SUMMARY.md b/charts/palworld/VALUES_SUMMARY.md index af4a31288..656df79d9 100644 --- a/charts/palworld/VALUES_SUMMARY.md +++ b/charts/palworld/VALUES_SUMMARY.md @@ -1,6 +1,8 @@ # palworld -![Version: 0.0.2](https://img.shields.io/badge/Version-0.0.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational?style=flat-square) +![Version: 0.0.2](https://img.shields.io/badge/Version-0.0.2-informational) +![Type: application](https://img.shields.io/badge/Type-application-informational) +![AppVersion: latest](https://img.shields.io/badge/AppVersion-latest-informational) This chart will provide a Palworld server installation on a kubernetes cluster.