IT-LIFEブログ

主にIT系のことや時事ネタや、たまに雑記

【Kubernetes】ポッドとホスト間でファイル転送

pod.ymlを以下のように作成します。

apiVersion: v1
kind: Pod
metadata:
  name: debug
  namespace: default
  labels:
    env: study
spec:
  containers:
    - name: debug
      image: centos:7
      command:
        - "sh"
        - "-c"
      args:
        - |
          while true
          do
            sleep ${DELAY}
          done
      env:
        - name: "DELAY"
          value: "86400"

以下のコマンドを実行してPodを立ち上げる

kubectl apply -f pod.yml

起動しているpodを確認してみましょう

kubectl get pod

f:id:nok-0930-ss:20200502165033p:plain

ファイルを作成します

touch sample1.txt

以下のコマンドでファイルをPodに転送できます。

kubectl cp sample1.txt debug:/var/tmp/sample1.txt

転送されているかを確認するためにPodの中に入ってみましょう

kubectl exec -it debug sh
ls /var/tmp/

f:id:nok-0930-ss:20200502165345p:plain

Pod内にsample1.txtがあることが確認できましたね。