exec command in Kubernetes

Colored Words Example
  
bala:~ bala$ kubectl get pods
NAME                             READY   STATUS    RESTARTS   AGE
redis-master-5ccf554d96-jlpvp    1/1     Running   0          10m
redis-master-5ccf554d96-k7qcw    1/1     Running   0          10m
redis-master-5ccf554d96-rsf9r    1/1     Running   0          10m
redis-master-5ccf554d96-vnpkk    1/1     Running   0          10m
redis-replica-858fc45586-2gslf   1/1     Running   0          10m
redis-replica-858fc45586-45n7w   1/1     Running   0          10m
redis-replica-858fc45586-5d4xm   1/1     Running   0          10m
redis-replica-858fc45586-bqlt4   1/1     Running   0          10m

bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- ls
appendonly.aof
dump.rdb
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- cat appendonly.aof
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- "cat appendonly.aof"
error: Internal error occurred: Internal error occurred: error executing command in container: failed to exec in container: failed to start exe
test
c "f0dd560038bf6837b6270bbbc35f5a4c4c693f4d5bbfe8b19cfbedc9c549db11": OCI runtime exec failed: exec failed: unable to start container process: exec: "cat appendonly.aof": executable file not found in $PATH: unknown
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- ls -lrt
total 4
-rw------- 1 redis redis   0 Jan  6 16:04 appendonly.aof
-rw------- 1 redis redis 176 Jan  6 16:05 dump.rdb
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- tail appendonly.aof
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- tail dump.rdb

bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay          59G  4.4G   52G   8% /
tmpfs            64M     0   64M   0% /dev
/dev/vda1        59G  4.4G   52G   8% /data
shm              64M     0   64M   0% /dev/shm
tmpfs           3.9G   12K  3.9G   1% /run/secrets/kubernetes.io/serviceaccount
tmpfs           2.0G     0  2.0G   0% /proc/acpi
tmpfs           2.0G     0  2.0G   0% /sys/firmware
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- uname -r
6.10.14-linuxkit
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- vi bala
error: Internal error occurred: Internal error occurred: error executing command in container: failed to exec in container: failed to start exec "04dd708175a40ea0121d1036a56b9598f4fe0e9bc511c1343ddc69ca9e799bf5": OCI runtime exec failed: exec failed: unable to start container process: exec: "vi": executable file not found in $PATH: unknown
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- touch bala
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- vi  bala
error: Internal error occurred: Internal error occurred: error executing command in container: failed to exec in container: failed to start exec "dafae56e105f60328c4f5a6937ff7f312b750a453163194c048a577bca652669": OCI runtime exec failed: exec failed: unable to start container process: exec: "vi": executable file not found in $PATH: unknown
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- which vim
command terminated with exit code 1
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- which nano
command terminated with exit code 1
bala:~ bala$ vi bala
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk
bala:~ bala$ kubectl cp redis-master-5ccf554d96-vnpkk:/path/to/bala ./bala
tar: Removing leading `/' from member names
tar: /path/to/bala: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
bala:~ bala$ kubectl cp redis-master-5ccf554d96-vnpkk:/path/to/bala ./bala
bala:~ bala$ kubectl cp ./bala redis-master-5ccf554d96-vnpkk:/path/to/bala
tar: /path/to: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
command terminated with exit code 2
bala:~ bala$ kubectl cp bala redis-master-5ccf554d96-vnpkk:
error: filepath can not be empty
bala:~ bala$ kubectl cp bala redis-master-5ccf554d96-vnpkk:/
bala:~ bala$ kubectl exec redis-master-5ccf554d96-vnpkk -- cat /bala
test

login

bala:~ bala$ kubectl exec -it redis-master-5ccf554d96-vnpkk -- /bin/bash root@redis-master-5ccf554d96-vnpkk:/data#

Installing packages in pod

  root@redis-master-5ccf554d96-vnpkk:/data# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@redis-master-5ccf554d96-vnpkk:/data# apt-get update
Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB]
Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:4 http://deb.debian.org/debian bookworm/main amd64 Packages [8789 kB]
Get:5 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [8856 B]
Get:6 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [240 kB]
Fetched 9292 kB in 3s (2736 kB/s)
Reading package lists... Done
root@redis-master-5ccf554d96-vnpkk:/data# apt-get install -y vim
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libgpm2 libsodium23 vim-common vim-runtime xxd
Suggested packages:
  gpm ctags vim-doc vim-scripts
The following NEW packages will be installed:
  libgpm2 libsodium23 vim vim-common vim-runtime xxd
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 8976 kB of archives.
After this operation, 41.9 MB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bookworm/main amd64 vim-common all 2:9.0.1378-2 [124 kB]
Get:2 http://deb.debian.org/debian bookworm/main amd64 libgpm2 amd64 1.20.7-10+b1 [14.2 kB]
Get:3 http://deb.debian.org/debian bookworm/main amd64 libsodium23 amd64 1.0.18-1 [161 kB]
Get:4 http://deb.debian.org/debian bookworm/main amd64 vim-runtime all 2:9.0.1378-2 [7025 kB]
Get:5 http://deb.debian.org/debian bookworm/main amd64 vim amd64 2:9.0.1378-2 [1567 kB]
Get:6 http://deb.debian.org/debian bookworm/main amd64 xxd amd64 2:9.0.1378-2 [83.7 kB]
Fetched 8976 kB in 1s (6715 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package vim-common.
(Reading database ... 6100 files and directories currently installed.)
Preparing to unpack .../0-vim-common_2%3a9.0.1378-2_all.deb ...
Unpacking vim-common (2:9.0.1378-2) ...
Selecting previously unselected package libgpm2:amd64.
Preparing to unpack .../1-libgpm2_1.20.7-10+b1_amd64.deb ...
Unpacking libgpm2:amd64 (1.20.7-10+b1) ...
Selecting previously unselected package libsodium23:amd64.
Preparing to unpack .../2-libsodium23_1.0.18-1_amd64.deb ...
Unpacking libsodium23:amd64 (1.0.18-1) ...
Selecting previously unselected package vim-runtime.
Preparing to unpack .../3-vim-runtime_2%3a9.0.1378-2_all.deb ...
Adding 'diversion of /usr/share/vim/vim90/doc/help.txt to /usr/share/vim/vim90/doc/help.txt.vim-tiny by vim-runtime'
Adding 'diversion of /usr/share/vim/vim90/doc/tags to /usr/share/vim/vim90/doc/tags.vim-tiny by vim-runtime'
Unpacking vim-runtime (2:9.0.1378-2) ...
Selecting previously unselected package vim.
Preparing to unpack .../4-vim_2%3a9.0.1378-2_amd64.deb ...
Unpacking vim (2:9.0.1378-2) ...
Selecting previously unselected package xxd.
Preparing to unpack .../5-xxd_2%3a9.0.1378-2_amd64.deb ...
Unpacking xxd (2:9.0.1378-2) ...
Setting up libsodium23:amd64 (1.0.18-1) ...
Setting up libgpm2:amd64 (1.20.7-10+b1) ...
Setting up xxd (2:9.0.1378-2) ...
Setting up vim-common (2:9.0.1378-2) ...
Setting up vim-runtime (2:9.0.1378-2) ...
Setting up vim (2:9.0.1378-2) ...
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/editor.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/da/man1/editor.1.gz because associated file /usr/share/man/da/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/de/man1/editor.1.gz because associated file /usr/share/man/de/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/fr/man1/editor.1.gz because associated file /usr/share/man/fr/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/it/man1/editor.1.gz because associated file /usr/share/man/it/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ja/man1/editor.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/pl/man1/editor.1.gz because associated file /usr/share/man/pl/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ru/man1/editor.1.gz because associated file /usr/share/man/ru/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/tr/man1/editor.1.gz because associated file /usr/share/man/tr/man1/vim.1.gz (of link group editor) doesn't exist
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/ex.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/da/man1/ex.1.gz because associated file /usr/share/man/da/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/de/man1/ex.1.gz because associated file /usr/share/man/de/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/fr/man1/ex.1.gz because associated file /usr/share/man/fr/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/it/man1/ex.1.gz because associated file /usr/share/man/it/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ja/man1/ex.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/pl/man1/ex.1.gz because associated file /usr/share/man/pl/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ru/man1/ex.1.gz because associated file /usr/share/man/ru/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/tr/man1/ex.1.gz because associated file /usr/share/man/tr/man1/vim.1.gz (of link group ex) doesn't exist
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/vi.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/da/man1/vi.1.gz because associated file /usr/share/man/da/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/de/man1/vi.1.gz because associated file /usr/share/man/de/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/fr/man1/vi.1.gz because associated file /usr/share/man/fr/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/it/man1/vi.1.gz because associated file /usr/share/man/it/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ja/man1/vi.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/pl/man1/vi.1.gz because associated file /usr/share/man/pl/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ru/man1/vi.1.gz because associated file /usr/share/man/ru/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/tr/man1/vi.1.gz because associated file /usr/share/man/tr/man1/vim.1.gz (of link group vi) doesn't exist
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/view.1.gz because associated file /usr/share/man/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/da/man1/view.1.gz because associated file /usr/share/man/da/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/de/man1/view.1.gz because associated file /usr/share/man/de/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/fr/man1/view.1.gz because associated file /usr/share/man/fr/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/it/man1/view.1.gz because associated file /usr/share/man/it/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ja/man1/view.1.gz because associated file /usr/share/man/ja/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/pl/man1/view.1.gz because associated file /usr/share/man/pl/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/ru/man1/view.1.gz because associated file /usr/share/man/ru/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/tr/man1/view.1.gz because associated file /usr/share/man/tr/man1/vim.1.gz (of link group view) doesn't exist
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode
Processing triggers for libc-bin (2.36-9+deb12u9) ...
root@redis-master-5ccf554d96-vnpkk:/data# vim --version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 04 2023 10:24:44)
Included patches: 1-1378, 1499
root@redis-master-5ccf554d96-vnpkk:/data# vim bala
  
  

Comments