【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
ファイルを作成します
touch sample1.txt
以下のコマンドでファイルをPodに転送できます。
kubectl cp sample1.txt debug:/var/tmp/sample1.txt
転送されているかを確認するためにPodの中に入ってみましょう
kubectl exec -it debug sh
ls /var/tmp/
Pod内にsample1.txtがあることが確認できましたね。