このトピックでは、stdlog をマウントして、Elastic Container Instance (ECI) Pod 内のコンテナの標準出力ログにファイルとしてアクセスする方法について説明します。ログは root 権限でマウントされます。
設定例
CSI プラグインを使用して、コンテナの標準出力ログを root 権限で ECI Pod にマウントできます。
-
YAML 設定ファイルを作成します。
vim stdlog_demo.yamlapiVersion: v1 kind: Pod metadata: name: test-stdlog-demo spec: containers: - image: registry-vpc.cn-beijing.aliyuncs.com/eci_open/nginx:1.14.2 name: test-container volumeMounts: - mountPath: /cache-test name: cache-volume volumes: - name: cache-volume csi: driver: stdlogplugin.csi.alibabacloud.com -
Pod をデプロイします。
kubectl create -f stdlog_demo.yaml -
結果を確認します。
出力結果から、コンテナの標準出力ログが root 権限で
/cache-testディレクトリにマウントされていることがわかります。これで、コンテナ内からこれらのログにアクセスできます。kubectl get pod test-stdlog-demo kubectl exec -it test-stdlog-demo bash ls -l /cache-test ls -l /cache-test/test-containershell@Alicloud:~$ kubectl get pod test-stdlog-demo NAME READY STATUS RESTARTS AGE test-stdlog-demo 1/1 Running 0 76s shell@Alicloud:~$ kubectl exec -it test-stdlog-demo bash kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in root@test-stdlog-demo:/# ls -l /cache-test total 4 drwxr-xr-x 2 root root 4096 Jul 6 09:04 test-container root@test-stdlog-demo:/# ls -l /cache-test/test-container total 0 -rw-r----- 1 root root 0 Jul 6 09:04 0.log root@test-stdlog-demo:/#