How to connect to POD in K8S

Lets try to connect to the POD nginx running .

List the pods in the cluster and see if it is running or not

root@master:/tmp# k get pods
NAME READY STATUS RESTARTS AGE

myapp-rc-4bbr9 1/1 Running 0 166m
myapp-rc-hx69f 1/1 Running 0 166m
myapp-rc-taint-2srpp 1/1 Running 0 26h
myapp-rc-taint-2zrlh 1/1 Running 0 26h
myapp-rc-taint-a-7bblg 1/1 Running 0 25h
myapp-rc-taint-a-t98wz 1/1 Running 0 25h
myapp-rc-taint-b-2pbhq 1/1 Running 0 166m
myapp-rc-taint-b-fp6c2 1/1 Running 0 166m
myapp-rc-taint-bgt88 1/1 Running 0 26h
myapp-rc-taint-c-2m2kg 1/1 Running 0 166m
myapp-rc-taint-c-hj75n 1/1 Running 0 166m
myapp-rc-taint-cg7hr 1/1 Running 0 26h
myapp-rc-taint-d-wbdn9 1/1 Running 0 166m
myapp-rc-taint-d76lj 1/1 Running 0 26h
myapp-rc-taint-l2qnr 1/1 Running 0 26h
myapp-rc-taint-lt2rd 1/1 Running 0 26h
myapp-rc-taint-rbtjk 1/1 Running 0 26h
myapp-rc-taint-t2blq 1/1 Running 0 26h
myapp-rc-taint-xhb45 1/1 Running 0 26h
nginx 1/1 Running 0 82m

root@master:/tmp#
root@master:/tmp#
root@master:/tmp# k exec nginx -it – /bin/bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
error: Internal error occurred: error executing command in container: failed to exec in container: failed to start exec "6169b8f1c91a68c5ebc99b8cb36b5be89871f6b6afdace67535a09bd3d4fc629": OCI runtime exec failed: exec failed: unable to start container process: exec: "-": executable file not found in $PATH: unknown

Correct the syntax and run again


root@master:/tmp# k exec nginx -it — /bin/bash
root@nginx:/#
root@nginx:/# ls -lrt
total 80
drwxr-xr-x 2 root root 4096 Dec 9 19:15 home
drwxr-xr-x 2 root root 4096 Dec 9 19:15 boot
drwxr-xr-x 1 root root 4096 Apr 11 00:00 var
drwxr-xr-x 1 root root 4096 Apr 11 00:00 usr
drwxr-xr-x 2 root root 4096 Apr 11 00:00 srv
drwxr-xr-x 2 root root 4096 Apr 11 00:00 sbin
drwx------ 2 root root 4096 Apr 11 00:00 root
drwxr-xr-x 2 root root 4096 Apr 11 00:00 opt
drwxr-xr-x 2 root root 4096 Apr 11 00:00 mnt
drwxr-xr-x 2 root root 4096 Apr 11 00:00 media
drwxr-xr-x 2 root root 4096 Apr 11 00:00 lib64
drwxr-xr-x 1 root root 4096 Apr 11 00:00 lib
drwxr-xr-x 2 root root 4096 Apr 11 00:00 bin
-rwxrwxr-x 1 root root 1616 Apr 12 08:51 docker-entrypoint.sh
drwxrwxrwt 1 root root 4096 Apr 12 08:51 tmp
drwxr-xr-x 1 root root 4096 Apr 12 08:51 docker-entrypoint.d
dr-xr-xr-x 13 root root 0 Apr 20 07:02 sys
dr-xr-xr-x 231 root root 0 Apr 20 07:02 proc
drwxr-xr-x 1 root root 4096 Apr 20 07:02 etc
drwxr-xr-x 5 root root 360 Apr 20 07:02 dev
drwxr-xr-x 1 root root 4096 Apr 20 07:02 run

root@nginx:/#

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *