- apiVersion: v1
- kind: Pod
- metadata:
- name: sharevol
- spec:
- containers:
- - name: c1
- image: twleader/host:latest
- volumeMounts:
- - name: xchange
- mountPath: /tmp/logs
- ports:
- - containerPort: 9080
- protocol: TCP
- - name: c2
- image: centos:7
- command:
- - "bin/bash"
- - "-c"
- - "sleep 10000"
- volumeMounts:
- - name: xchange
- mountPath: /tmp/xchange
- volumes:
- - name: xchange
- emptyDir: {}
- 第 24~26 行,在 pod 上建立一個 volume 並命名為 xchange。
- 第 7~14 行,這是借用之前「部署 RESTful service 到 Kubernetes」已經建立好的一個 image twleader/host,建立一個命名為 c1 的 container。
- 第 9~11 行,將 volume xchange 掛載到 /tmp/logs 目錄。
- 第 15~23 行,建立命名為 c2 的 container,僅簡單的包含一個 centos。
- 第 21~23 行,將 volume xchange 掛載到 /tmp/xchange 目錄。
接著利用 exec 指令進入 container c1 於 volume 所在目錄建立一個檔案,如下:
再用 exec 指令進入 container c2,於 volume 所在目錄看看有沒有該檔案? 當然有!
同一個 pod 中不同的 container 透過這個方式就可以簡單的交換、共享資料了!
沒有留言:
張貼留言