kubectl cp 命令排錯

2021-09-30 17:18:02 字數 3613 閱讀 2368

場景1,

emambp:static-html ema$ kubectl cp index-kubernetes.html  learnci/performance-ap564-xr952:/usr/share/nginx/html

defaulting container name to retrieve-instance-data.

^[[atar: index-kubernetes.html: cannot open: permission denied

tar: exiting with failure status due to previous errors

command terminated with exit code 2

emambp:static-html ema$ kubectl cp index-kubernetes.html  learnci/performance-ap564-xr952:/usr/share/nginx/html/

defaulting container name to retrieve-instance-data.

kubectl cp 不需要使用-n 指定namespace 但需要copy的目標路徑 顯示指出 哪個namespace/哪個pod:目錄

切記 目標路徑必須是目錄"/"結尾

場景2,

從pod內部copy檔案到本地檔案系統

emambp:tian ema$ kubectl version

client version: version.info

server version: version.info

當前kubectl 客戶端版本  伺服器版本

幾種錯誤的做法:

emambp:tian ema$ pwd

/users/ema/work/bb_cicd/starter/kubernetes/tian

emambp:tian ema$ kubectl cp learn-deployments/lrn145033-learn-tomca7956c-g9k8q:/usr/local/blackboard/logs/bb-email-log.txt  ./

defaulting container name to learn.

tar: removing leading `/' from member names

error: open .: is a directory

emambp:tian ema$ kubectl cp learn-deployments/lrn145033-learn-tomca7956c-g9k8q:/usr/local/blackboard/logs/bb-email-log.txt  /users/ema/work/bb_cicd/starter/kubernetes/tian

defaulting container name to learn.

tar: removing leading `/' from member names

error: open /users/ema/work/bb_cicd/starter/kubernetes/tian: is a directory

emambp:tian ema$ kubectl cp learn-deployments/lrn145033-learn-tomca7956c-g9k8q:/usr/local/blackboard/logs/bb-email-log.txt  /users/ema/work/bb_cicd/starter/kubernetes/tian/

defaulting container name to learn.

tar: removing leading `/' from member names

error: open /users/ema/work/bb_cicd/starter/kubernetes/tian: is a directory

emambp:tian ema$ kubectl cp learn-deployments/lrn145033-learn-tomca7956c-g9k8q:bb-email-log.txt  /users/ema/work/bb_cicd/starter/kubernetes/tian/

defaulting container name to learn.

error: open /users/ema/work/bb_cicd/starter/kubernetes/tian: is a directory

需求:想從pod內部  目錄 /usr/local/blackboard/logs/ 下的檔案bb-email-log.txt copy到本地檔案系統 這個目錄下 /users/ema/work/bb_cicd/starter/kubernetes/tian/

源目錄是pod 目錄時,:後只能跟檔名,不能是以/ 開頭的路徑,所以需要先用kubectl exec  ssh到pod上,copy檔案到工作目錄下workdir, (此example種workdir為  /home/bbuser)

emambp:tian ema$ kubectl -n learn-deployments exec -it lrn145033-learn-tomca7956c-g9k8q -- /bin/bash

defaulting container name to learn.

use 'kubectl describe pod/lrn145033-learn-tomcat-5c69c7956c-g9k8q' to see all of the containers in this pod.

bbuser@lrn145033-learn-tom7956c-g9k8q:~$ cp /usr/local/blackboard/logs/bb-email-log.txt  .

bbuser@lrn145033-learn-tom7956c-g9k8q:~$ pwd

/home/bbuser

bbuser@lrn145033-learn-tomca7956c-g9k8q:~$ ls

bb-email-log.txt  bin  learn-installer    learn-installer.properties

bbuser@lrn145033-learn-tomca7956c-g9k8q:~$

emambp:tian ema$ kubectl cp learn-deployments/lrn145033-learn-tom7956c-g9k8q:bb-email-log.txt  /users/ema/work/bb_cicd/starter/kubernetes/tian/

defaulting container name to learn.

error: open /users/ema/work/bb_cicd/starter/kubernetes/tian: is a directory

目標引數必須為檔案 不能是乙個目錄

解決,emambp:tian ema$ kubectl cp learn-deployments/lrn145033-learn-tom7956c-g9k8q:bb-email-log.txt  /users/ema/work/bb_cicd/starter/kubernetes/tian/bb-email-log.txt

總結:源引數 不能是以「/」 開頭的,所以可以把需要copy的檔案先拷貝到pod的工作目錄下

目標引數必須為檔案  不能是目錄

Linux命令學習 Crontab 排錯篇

當 crontab 1回顯no crontab for root時 先確保設定沒問題 kali請使用 crontab e設定定時命令 正常情況下 預設情況crontab是沒有日誌的,開啟 etc rsyslog.d 50 default.conf 檔案 vim etc rsyslog.d 50 de...

個人 排錯記

2007年03月07日 18 12 00 魚dd和茂dd最後選擇了離開,我能夠理解他們,與他們認識已經5年多了,知道他們的煩惱憂愁,不想去阻攔他們,除了不捨,只想祝願他們盡快找到自己的另一半,穩定下來。這是體制和企業文化要解決的問題。程式設計師雜誌在第2和第3期發了我的兩篇文章,在排版時都有不少的錯...

個人 排錯記

2007年03月07日 18 12 00 魚dd和茂dd最後選擇了離開,我能夠理解他們,與他們認識已經5年多了,知道他們的煩惱憂愁,不想去阻攔他們,除了不捨,只想祝願他們盡快找到自己的另一半,穩定下來。這是體制和企業文化要解決的問題。程式設計師雜誌在第2和第3期發了我的兩篇文章,在排版時都有不少的錯...