Whilst I have used docker cp numerous times to copy files from a running container to the host ( or vice versa ), I had the need to do the same with a container running in a Pod orchestrated by Kubernetes.
The syntax for Docker is: -
docker cp <<container ID>>:/from-path /to-path
e.g.
docker cp 97ee4c182ece:/opt/ibm/db2/V11.1/java/db2jcc4.jar .
For containers running in Pods via Kubernetes, it's a little different.
The first trick is to inspect the Pod: -
kubectl get pod
NAME READY STATUS RESTARTS AGE
db2trader-ibm-db2oltp-dev-2298094317-fgn0b 1/1 Running 0 3h
jenkins-jenkins-662520783-jq60z 1/1 Running 0 18h
loyalty-level-2196446665-hnsnv 1/1 Running 0 12m
mqtraader-ibm-mqadvanced-0 1/1 Running 0 2h
notification-3317998672-qsgvj 0/1 secrets "openwhisk" not found 0 11m
portfolio-1784192597-588s1 1/1 Running 0 11m
redistrader-redis-0 1/1 Running 0 2h
redistrader-redis-1 1/1 Running 0 2h
redistrader-redis-2 1/1 Running 0 2h
stock-quote-2259670618-z0400 1/1 Running 0 11m
trader-2151312948-zfvch 1/1 Running 0 12m
Name: mqtraader-ibm-mqadvanced-0
Namespace: default
Node: 10.0.0.3/10.0.0.3
Start Time: Wed, 22 Nov 2017 03:07:48 -0800
Labels: QM_IDENTIFIER=mqtraader
app=mqtraader-ibm-mqadvanced
chart=ibm-mqadvanced-server-dev-1.0.1
controller-revision-hash=mqtraader-ibm-mqadvanced-1107708458
heritage=Tiller
release=mqtraader
Annotations: kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"StatefulSet","namespace":"default","name":"mqtraader-ibm-mqadvanced","uid":"5f5a8bc6-cf75-11e7-82cf-005056...
kubernetes.io/psp=default
Status: Running
IP: 10.1.88.143
Created By: StatefulSet/mqtraader-ibm-mqadvanced
Controlled By: StatefulSet/mqtraader-ibm-mqadvanced
Containers:
qmgr:
Container ID: docker://fe7c9127776da0bdea9953dd4d804af17318b019f68aac521222a795d06bf1a3
Image: ibmcom/mq:9
Image ID: docker-pullable://ibmcom/mq@sha256:76d74d07ccd6fa49297ba01f199ac95e0f89d8c4a068ccb655380c6a5d8aec93
Ports: 1414/TCP, 9443/TCP
State: Running
Started: Wed, 22 Nov 2017 03:07:50 -0800
Ready: True
Restart Count: 0
Limits:
cpu: 500m
memory: 512Mi
Requests:
cpu: 500m
memory: 512Mi
Environment:
LICENSE: accept
MQ_QMGR_NAME: admin
MQ_ADMIN_PASSWORD: <set to the key 'adminPassword' in secret 'mqtraader-ibm-mqadvanced'> Optional: false
MQ_APP_PASSWORD: <set to the key 'appPassword' in secret 'mqtraader-ibm-mqadvanced'> Optional: false
Mounts:
/mnt/mqm from mqtraader-ibm-mqadvanced-mqvol1 (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-l601r (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
mqtraader-ibm-mqadvanced-mqvol1:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: mqtraader-ibm-mqadvanced-mqvol1-mqtraader-ibm-mqadvanced-0
ReadOnly: false
default-token-l601r:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-l601r
Optional: false
QoS Class: Guaranteed
Node-Selectors: <none>
Tolerations: node.alpha.kubernetes.io/notReady:NoExecute for 300s
node.alpha.kubernetes.io/unreachable:NoExecute for 300s
Events: <none>
Namespace: default
Node: 10.0.0.3/10.0.0.3
Start Time: Wed, 22 Nov 2017 03:07:48 -0800
Labels: QM_IDENTIFIER=mqtraader
app=mqtraader-ibm-mqadvanced
chart=ibm-mqadvanced-server-dev-1.0.1
controller-revision-hash=mqtraader-ibm-mqadvanced-1107708458
heritage=Tiller
release=mqtraader
Annotations: kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"StatefulSet","namespace":"default","name":"mqtraader-ibm-mqadvanced","uid":"5f5a8bc6-cf75-11e7-82cf-005056...
kubernetes.io/psp=default
Status: Running
IP: 10.1.88.143
Created By: StatefulSet/mqtraader-ibm-mqadvanced
Controlled By: StatefulSet/mqtraader-ibm-mqadvanced
Containers:
qmgr:
Container ID: docker://fe7c9127776da0bdea9953dd4d804af17318b019f68aac521222a795d06bf1a3
Image: ibmcom/mq:9
Image ID: docker-pullable://ibmcom/mq@sha256:76d74d07ccd6fa49297ba01f199ac95e0f89d8c4a068ccb655380c6a5d8aec93
Ports: 1414/TCP, 9443/TCP
State: Running
Started: Wed, 22 Nov 2017 03:07:50 -0800
Ready: True
Restart Count: 0
Limits:
cpu: 500m
memory: 512Mi
Requests:
cpu: 500m
memory: 512Mi
Environment:
LICENSE: accept
MQ_QMGR_NAME: admin
MQ_ADMIN_PASSWORD: <set to the key 'adminPassword' in secret 'mqtraader-ibm-mqadvanced'> Optional: false
MQ_APP_PASSWORD: <set to the key 'appPassword' in secret 'mqtraader-ibm-mqadvanced'> Optional: false
Mounts:
/mnt/mqm from mqtraader-ibm-mqadvanced-mqvol1 (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-l601r (ro)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
mqtraader-ibm-mqadvanced-mqvol1:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: mqtraader-ibm-mqadvanced-mqvol1-mqtraader-ibm-mqadvanced-0
ReadOnly: false
default-token-l601r:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-l601r
Optional: false
QoS Class: Guaranteed
Node-Selectors: <none>
Tolerations: node.alpha.kubernetes.io/notReady:NoExecute for 300s
node.alpha.kubernetes.io/unreachable:NoExecute for 300s
Events: <none>
grabbing the Name and the Namespace, and then using kubectl cp as per the following example: -
kubectl cp default/mqtraader-ibm-mqadvanced-0:/opt/mqm/java/lib/jca/wmq.jmsra.rar ./wmq.jmsra.rar
tar: Removing leading `/' from member names
However, notice one nuance - it's necessary to specify the destination file name as well as the destination path.
Otherwise, if you do this: -
kubectl cp default/mqtraader-ibm-mqadvanced-0:/opt/mqm/java/lib/jca/wmq.jmsra.rar .
you get this: -
tar: Removing leading `/' from member names
error: open .: is a directory
error: open .: is a directory
which took me a while to work around.
:-)
No comments:
Post a Comment