Skip to content

Commit b7eec54

Browse files
authored
Serve --server-log in API server helm deployment (#7226)
* Server server log in container and rotate it Signed-off-by: Aylei <[email protected]> * Update Signed-off-by: Aylei <[email protected]> * Update doc Signed-off-by: Aylei <[email protected]> * Update Signed-off-by: Aylei <[email protected]> * Tune defaults Signed-off-by: Aylei <[email protected]> * Update Signed-off-by: Aylei <[email protected]> --------- Signed-off-by: Aylei <[email protected]>
1 parent ba9944c commit b7eec54

File tree

5 files changed

+125
-8
lines changed

5 files changed

+125
-8
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ARG NEXT_BASE_PATH=/dashboard
6868
RUN apt-get update -y && \
6969
apt-get install --no-install-recommends -y \
7070
git gcc rsync sudo patch openssh-server \
71-
pciutils nano fuse socat netcat-openbsd curl tini autossh jq && \
71+
pciutils nano fuse socat netcat-openbsd curl tini autossh jq logrotate && \
7272
apt-get clean && rm -rf /var/lib/apt/lists/*
7373

7474
# Install the session manager plugin for AWS CLI.

charts/skypilot/templates/api-deployment.yaml

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ spec:
213213
{{- end }}
214214
215215
if sky api start -h | grep -q -- "--foreground"; then
216-
exec sky api start {{ include "skypilot.apiArgs" . }} --foreground
216+
mkdir -p /root/.sky/api_server
217+
exec sky api start {{ include "skypilot.apiArgs" . }} --foreground 2>&1 | tee -a /root/.sky/api_server/server.log
217218
else
218219
# For backward compatibility, run in background if --foreground is not supported.
219220
# TODO(aylei): this will be dropped in 0.11.0.
@@ -249,10 +250,10 @@ spec:
249250
periodSeconds: 5
250251
initialDelaySeconds: 5
251252
volumeMounts:
252-
{{- if .Values.storage.enabled }}
253253
- name: state-volume
254254
mountPath: /root/.sky
255255
subPath: .sky
256+
{{- if .Values.storage.enabled }}
256257
- name: state-volume
257258
mountPath: /root/.ssh # To preserve the SSH keys for the user when using the API server
258259
subPath: .ssh
@@ -320,6 +321,38 @@ spec:
320321
{{- if .Values.apiService.extraVolumeMounts }}
321322
{{- toYaml .Values.apiService.extraVolumeMounts | nindent 8 }}
322323
{{- end }}
324+
{{- if .Values.apiService.logs.retention.enabled }}
325+
- name: logrotate
326+
image: {{ .Values.apiService.image }}
327+
command: ["/bin/sh", "-c"]
328+
# Warn if logrotate is missing in the image and keep the sidecar running
329+
args:
330+
- |
331+
if ! command -v logrotate >/dev/null 2>&1; then
332+
echo "warning: logrotate not found; skipping log retention" >&2
333+
while true; do
334+
sleep 3600
335+
done
336+
fi
337+
set -x
338+
cat > /etc/logrotate.conf <<EOF
339+
/root/.sky/api_server/server.log {
340+
size {{ .Values.apiService.logs.retention.size }}
341+
rotate 1
342+
missingok
343+
notifempty
344+
copytruncate
345+
}
346+
EOF
347+
while true; do
348+
logrotate -s /var/lib/logrotate/status /etc/logrotate.conf
349+
sleep 60;
350+
done
351+
volumeMounts:
352+
- name: state-volume
353+
mountPath: /root/.sky
354+
subPath: .sky
355+
{{- end }}
323356
initContainers:
324357
{{- if .Values.awsCredentials.enabled }}
325358
- name: create-aws-credentials
@@ -369,19 +402,19 @@ spec:
369402
set -e
370403
echo "Setting up R2 credentials..."
371404
mkdir -p /root/.cloudflare
372-
405+
373406
# Direct echo of environment variables (no quotes around EOF)
374407
cat > /root/.cloudflare/r2.credentials <<EOF
375408
$R2_CREDENTIALS
376409
EOF
377-
410+
378411
cat > /root/.cloudflare/accountid <<EOF
379412
$R2_ACCOUNT_ID
380413
EOF
381-
414+
382415
chmod 600 /root/.cloudflare/r2.credentials
383416
chmod 600 /root/.cloudflare/accountid
384-
417+
385418
echo "R2 credentials setup complete:"
386419
ls -la /root/.cloudflare/
387420
echo "First line of r2.credentials:"
@@ -571,7 +604,7 @@ spec:
571604
- name: skypilot-ssh-identity
572605
secret:
573606
secretName: {{ .Values.apiService.sshKeySecret }}
574-
defaultMode: 0600
607+
defaultMode: 0600
575608
{{- end }}
576609
{{- if .Values.apiService.extraVolumes }}
577610
{{- toYaml .Values.apiService.extraVolumes | nindent 6 }}

charts/skypilot/values.schema.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@
8080
"null"
8181
]
8282
},
83+
"logs": {
84+
"type": "object",
85+
"properties": {
86+
"retention": {
87+
"type": "object",
88+
"properties": {
89+
"enabled": {
90+
"type": "boolean"
91+
},
92+
"size": {
93+
"type": "string"
94+
}
95+
}
96+
}
97+
}
98+
},
8399
"metrics": {
84100
"type": "object",
85101
"properties": {

charts/skypilot/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ apiService:
153153
# [Internal] Enable developer mode for SkyPilot
154154
skypilotDev: false
155155

156+
# Configure how to manage API server logs
157+
logs:
158+
retention:
159+
# Whether to enable log retention
160+
enabled: true
161+
# The size of the log file to retain
162+
size: 10M
163+
156164
# Authentication configuration for the API server
157165
# Refer to https://docs.skypilot.co/en/latest/reference/auth.html for more details.
158166
# @schema type: [object, null]

docs/source/reference/api-server/helm-values-spec.rst

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ Below is the available helm value keys and the default value of each key:
7373
:ref:`extraEnvs <helm-values-apiService-extraEnvs>`: null
7474
:ref:`extraVolumes <helm-values-apiService-extraVolumes>`: null
7575
:ref:`extraVolumeMounts <helm-values-apiService-extraVolumeMounts>`: null
76+
:ref:`logs <helm-values-apiService-logs>`:
77+
:ref:`retention <helm-values-apiService-logs-retention>`:
78+
:ref:`enabled <helm-values-apiService-logs-retention-enabled>`: false
79+
:ref:`size <helm-values-apiService-logs-retention-size>`: 10M
7680
7781
:ref:`auth <helm-values-auth>`:
7882
:ref:`oauth <helm-values-auth-oauth>`:
@@ -691,6 +695,62 @@ Default: ``null``
691695
mountPath: /my-path
692696
subPath: my-file
693697
698+
.. _helm-values-apiService-logs:
699+
700+
``apiService.logs``
701+
^^^^^^^^^^^^^^^^^^^
702+
703+
Configuration for managing API server logs.
704+
705+
Default: see the yaml below.
706+
707+
.. code-block:: yaml
708+
709+
apiService:
710+
logs:
711+
retention:
712+
enabled: false
713+
size: 10M
714+
715+
.. _helm-values-apiService-logs-retention:
716+
717+
``apiService.logs.retention``
718+
'''''''''''''''''''''''''''''
719+
720+
Configuration for log retention settings.
721+
722+
.. _helm-values-apiService-logs-retention-enabled:
723+
724+
``apiService.logs.retention.enabled``
725+
''''''''''''''''''''''''''''''''''''''
726+
727+
Whether to enable log retention for the API server. When enabled, logs will be automatically rotated and managed according to the specified size limit.
728+
729+
Default: ``false``
730+
731+
.. code-block:: yaml
732+
733+
apiService:
734+
logs:
735+
retention:
736+
enabled: true
737+
738+
.. _helm-values-apiService-logs-retention-size:
739+
740+
``apiService.logs.retention.size``
741+
'''''''''''''''''''''''''''''''''''
742+
743+
The maximum size of the log file before rotation. When the log file reaches this size, it will be rotated to preserve disk space. Only used when ``enabled`` is ``true``.
744+
745+
Default: ``10M``
746+
747+
.. code-block:: yaml
748+
749+
apiService:
750+
logs:
751+
retention:
752+
size: 50M
753+
694754
695755
.. _helm-values-auth:
696756

0 commit comments

Comments
 (0)