您好,登錄后才能下訂單哦!
在下面示例中,Pod內(nèi)包含兩個(gè)容器:tomcat 和 busybox ,在 Pod 級(jí)別設(shè)置 Volume “app-logs”,用于 tomcat 向其中寫入日志文件,busybox 讀日志文件。
#?cat?pod-volume-applogs.yaml? apiVersion:?v1 kind:?Pod metadata: ??name:?volume-pod spec: ??containers: ??-?name:?tomcat ???image:?tomcat ???ports: ???-?containerPort:?8080 ???volumeMounts: ???-?name:?app-logs ?????mountPath:?/usr/local/tomcat/logs ??-?name:?busybox ???image:?busybox ???command:?["sh","-c","tail?-f?/logs/catalina*.log"] ???volumeMounts: ???-?name:?app-logs ?????mountPath:?/logs ??volumes: ??-?name:?app-logs ???emptyDir:?{}
這里設(shè)置的 Volume 名為 app-logs,類型為 emptyDir(也可以設(shè)置為其他類型),掛載到 tomcat 容器內(nèi)的 /usr/local/tomcat/logs 目錄,同時(shí)掛載到 logreader 容器內(nèi)的 /logs 目錄。tomcat 容器會(huì)在啟動(dòng)后會(huì)向 /usr/log/tomcat/logs 目錄中寫文件,logreader 容器就可以讀取其中的文件了。
可以通過(guò) kubectl logs 命令查看 logreader 容器的輸出內(nèi)容:
#?find?/?-name?app-logs [root@master?other]#?kubectl?logs?volume-pod?-c?busybox 26-Jul-2019?18:06:22.126?INFO?[main]?org.apache.catalina.startup.VersionLoggerListener.log?Command?line?argument:?-Djava.protocol.handler.pkgs=org.apache.catalina.w ebresources26-Jul-2019?18:06:22.126?INFO?[main]?org.apache.catalina.startup.VersionLoggerListener.log?Command?line?argument:?-Dorg.apache.catalina.security.SecurityListener.UM ASK=002726-Jul-2019?18:06:22.144?INFO?[main]?org.apache.catalina.startup.VersionLoggerListener.log?Command?line?argument:?-Dignore.endorsed.dirs= 26-Jul-2019?18:06:22.144?INFO?[main]?org.apache.catalina.startup.VersionLoggerListener.log?Command?line?argument:?-Dcatalina.base=/usr/local/tomcat 26-Jul-2019?18:06:22.144?INFO?[main]? ......
登錄 tomcat 容器進(jìn)行查看:
#?kubectl?exec?-it?volume-pod?-c?tomcat?--?ls?/usr/local/tomcat/logs catalina.2019-07-26.log?????localhost_access_log.2019-07-26.txt host-manager.2019-07-26.log??manager.2019-07-26.log localhost.2019-07-26.log #?kubectl?exec?-it?volume-pod?-c?tomcat?--?tail?/usr/local/tomcat/logs/catalina.2019-07-26.log 26-Jul-2019?18:06:29.935?INFO?[localhost-startStop-1]?org.apache.catalina.startup.HostConfig.deployDirectory?Deployment?of?web?application?directory?[/usr/local/tom cat/webapps/docs]?has?finished?in?[388]?ms26-Jul-2019?18:06:29.936?INFO?[localhost-startStop-1]?org.apache.catalina.startup.HostConfig.deployDirectory?Deploying?web?application?directory?[/usr/local/tomcat/ webapps/examples]26-Jul-2019?18:06:32.777?INFO?[localhost-startStop-1]?org.apache.catalina.startup.HostConfig.deployDirectory?Deployment?of?web?application?directory?[/usr/local/tomcat
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。