K8s安装

2.3、深入pod-基本用法、共享volume

2019-06-11  本文已影响0人  yezide

1、 php + redis容器

pod配置文件: frontend-localredis-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: redis-php
spec:
  containers:
    - name: frontend
      image: kubeguide/guestbook-php-frontend:localredis
      ports:
      - containerPort: 80
    - name: redis
      image: kubeguide/redis-master
      ports:
      - containerPort: 6379

2、 共享volume

pod中包含tomcat和busybox,tomcat写日志, busybox读日志
创建pod-volume-applogs.yaml

apiVersion: v1
kind: Pod
metadata:
  name: volume-pod
spec:
  containers:
    - name: tomcat
      image: tomcat
      ports:
      - containerPort: 8080
      # tomcat挂载目录
      volumeMounts
      - name: app-logs
        mountPath: /usr/local/tomcat/logs

    - name: busybox
      image: busybox
      command: ["sh", "-c", "tail -f /logs/catalina*.log"]
      volumeMounts
      # busybox挂载目录
      - name: app-logs
        mountPath: /logs

    volumes:
    # emptyDir的意思是: 内容为空,无须指定宿主机对应的目录文件,pod从node中移除时也会被永久删除,一般用于临时空间、临时目录
    - name: app-logs
      emptyDir: {}

查看日志

# 查看busybox的日志
kubectl logs volume-pod busybox
# 查看tomcat的日志
kubectl exec -it volume-pod -c tomcat -- ls -l /usr/local/tomcat/logs
kubectl exec -it volume-pod -c tomcat -- tail -200f /usr/local/tomcat/logs/catalina.2019-06-11.log
上一篇下一篇

猜你喜欢

热点阅读