When a Kubernetes Job runs on elastic container instances (virtual nodes), DaemonSets cannot collect its logs. Unlike ECS-based nodes, elastic container instances have no node-level agent. To make matters worse, once a Job completes, its pods exit immediately — before any log agent can flush the data.
The solution is to persist logs outside the pod lifecycle: mount a File Storage NAS (NAS) file system to the Job so its output is written directly to NAS, then create a separate pod that reads from the same NAS mount and forwards the data to Simple Log Service.
Data flow: Job → NAS file system → log-collection pod → Simple Log Service
If Simple Log Service is already enabled for your cluster, an alternative is available: mount a volume to the Job, then configure environment variables to sync log data to Simple Log Service. For details, see Configure log collection for an elastic container instance.
Prerequisites
Before you begin, ensure that you have:
-
An ACK Serverless cluster. See ACK Serverless quick start
-
A virtual node deployed in the cluster. See Schedule pods to elastic container instances that are deployed as virtual nodes
-
A NAS file system with a mount target added. See Create a file system and Manage mount targets
Collect the Job log using NAS
Step 1: Create the Job
Create a file named job.yaml with the following content. This example Job calculates pi to 1,000 decimal places and writes the result to /eci/a.log on the NAS mount.
Replace 04edd48c7c-****.cn-hangzhou.nas.aliyuncs.com with your NAS mount target address.
apiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
spec:
containers:
- name: pi
image: resouer/ubuntu-bc
command: ["sh", "-c", "echo 'scale=1000; 4*a(1)' | bc -l > /eci/a.log 2>&1"] # Saves output to NAS
volumeMounts:
- name: log-volume
mountPath: /eci
readOnly: false
restartPolicy: Never
volumes:
- name: log-volume
nfs:
path: /eci
server: 04edd48c7c-****.cn-hangzhou.nas.aliyuncs.com
readOnly: false
backoffLimit: 4
Step 2: Deploy the Job to a virtual node
Apply the Job manifest to the fvt-eci namespace. For instructions on scheduling pods to virtual nodes, see Schedule pods to elastic container instances that are deployed as virtual nodes.
kubectl apply -f job.yaml -n fvt-eci
Step 3: Verify the Job completes
Check pod status to confirm the Job is running:
kubectl get pod -n fvt-eci
Wait until the pod status shows Completed before proceeding. At that point, the log file has been written to the NAS file system.
Step 4: Create the log-collection pod
Create a file named log-collection.yaml with the following content. This pod mounts the same NAS path and prints the Job's log output.
Replace 04edd48c7c-****.cn-hangzhou.nas.aliyuncs.com with your NAS mount target address.
apiVersion: v1
kind: Pod
metadata:
name: log-collection
spec:
containers:
- image: nginx:latest
name: log-collection
command: ['/bin/sh', '-c', 'echo &(cat /eci/a.log)'] # Prints the Job log
volumeMounts:
- mountPath: /eci
name: log-volume
restartPolicy: Never
volumes:
- name: log-volume
nfs:
server: 04edd48c7c-****.cn-hangzhou.nas.aliyuncs.com
path: /eci
readOnly: false
Deploy the pod:
kubectl apply -f log-collection.yaml -n fvt-eci
Next steps
-
To route logs from the log-collection pod to Simple Log Service, configure the pod with Simple Log Service environment variables. For details, see Configure log collection for an elastic container instance.
-
To schedule additional workloads on virtual nodes, see Schedule pods to elastic container instances that are deployed as virtual nodes.