0

when I ran this command

kubectl exec -it $(kubectl get pods | grep container-name | awk '{print $1}') /bin/sh

I ssh into my container,

/src #

Now - I want to add 2 more commands so I did

kubectl exec -it $(kubectl get pods | grep container-name | awk '{print $1}') /bin/sh ; cd app/Http/Controllers; ls -lrt; 

but I still see this

/src #

I am supposed to see this

/src # cd app/Http/Controllers; ls -lrt;                                                
total 44                                                                                
-rw-r--r--    1 root     root           361 Jun 11 11:27 Controller.php                   
-rw-r--r--    1 root     root          1734 Jun 11 11:27 ClientController.php             
-rw-r--r--    1 root     root          1702 Jun 11 11:27 BroadcastController.php        
-rw-r--r--    1 root     root          5257 Jun 17 15:24 NodeController.php              
-rw-r--r--    1 root     root          2844 Jun 17 20:21 AccountController.php          
/src/app/Http/Controllers #
code-8
  • 54,650
  • 106
  • 352
  • 604
  • can you try : `kubectl exec -it $(kubectl get pods | grep container-name | awk '{print $1}') -- bash -c "cd app/Http/Controllers && ls -lrt" ` or `kubectl exec -it $(kubectl get pods | grep container-name | awk '{print $1}') -- sh -c "cd app/Http/Controllers && ls -lrt"` – Thanh Nguyen Van Jun 18 '19 at 02:51
  • @ThanhNguyenVan : it doesn't seem to work... see this https://i.imgur.com/ZVe47O4.png – code-8 Jun 18 '19 at 13:18

1 Answers1

1

There is no need to go inside docker container do as below

kubectl exec -it $(kubectl get pods | grep container-name | awk '{print $1}') -- ls -lrt /app/Http/Controllers;

kubectl will execute every command inside container which comes after --. also you can mount your target directory and perform ls on localhost. create a yaml file like the one here.

apiVersion: v1
kind: Pod
metadata:
  name: test-container
spec:
  containers:
  - name: my-container
    image: my-container
    volumeMounts:
    - name: my-storage
      mountPath: /data/
  volumes:
  - name: my-storage
    hostPath:
        # directory location on host
        path: /opt/data
        # this field is optional
        type: Directory

then run this command kubectl apply -f your-file.yaml

Siyavash vaez afshar
  • 1,303
  • 10
  • 12