Prerequisites:

  • The virtual-kubelet node is deployed in the target Kubernetes cluster. Note that a serverless Kubernetes cluster is embedded with the virtual-kubelet node.

Elastic Container Instance (ECI) allows you to mount the standard output stream of a container to the container as a volume and assign the root permissions on the log files to the container by using FlexVolume. Save the following sample code in a YAML file named flexvolume_stdlog.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test-flexvolume-stdlog
spec:
  nodeName: virtual-kubelet
  containers:
  - image: nginx:latest
    name: test-container
    volumeMounts:
    - mountPath: /cache-test
      name: cache-volume
  volumes:
  - name: cache-volume
    flexVolume:
      driver: alicloud/pod-stdlog

Use the kubectl client to create an ECI based on the preceding configuration file.

# kubectl create -f flexvolume_stdlog.yaml
pod/test-flexvolume-stdlog created
# kubectl get pod test-flexvolume-stdlog
NAME                     READY   STATUS    RESTARTS   AGE
test-flexvolume-stdlog   1/1     Running   0          94s
# kubectl exec -it test-flexvolume-stdlog bash
root@test-flexvolume-stdlog:/# ls -l /cache-test/
total 4
drwxr-xr-x 2 root root 4096 Jan 20 07:18 test-container
root@test-flexvolume-stdlog:/# ls -l /cache-test/test-container/
total 0
-rw-r----- 1 root root 0 Jan 20 07:18 0.log

According to the command output, the standard output stream of the container is mounted to the container as a volume, and the container has root permissions on the log files. This allows you to use the log files in the container.