前提条件:

  • K8S集群中正确部署了virtual-kubelet(serverless Kubernetes 默认集成)

ECI直接通过FlexVolume的方式将容器的标准输出日志以root权限挂载到用户容器组内,将以下内容保存在为flexvolume_stdlog.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: test-flexvolume-stdlog
spec:
  # ACK场景下可以通过nodeName指定调度到ECI
  # nodeName: virtual-node-eci-0
  containers:
  - image: nginx:latest
    name: test-container
    volumeMounts:
    - mountPath: /cache-test
      name: cache-volume
  volumes:
  - name: cache-volume
    flexVolume:
      driver: alicloud/pod-stdlog

使用kubectl创建ECI实例:

# 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

可见,已经将容器的标准日志以root:root的权限挂载到了容器内,用户可以在容器内使用相关日志。