У меня есть кластер kubernetes, где я пытаюсь проверить использование диска контейнерами, работающими на нем.
$kubectl version
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.8", GitCommit:"e8c167a115ec662726904265d17f75a6d79d78d8", GitTreeState:"clean", BuildDate:"2017-10-01T00:19:21Z", GoVersion:"go1.7.6", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.8", GitCommit:"e8c167a115ec662726904265d17f75a6d79d78d8", GitTreeState:"clean", BuildDate:"2017-10-01T00:01:59Z", GoVersion:"go1.7.6", Compiler:"gc", Platform:"linux/amd64"}
Это работает для меня
$kubectl -n example-system exec -it example-monitoring-0 df
Filesystem 1K-blocks Used Available Use% Mounted on
overlay 98227828 17592896 76340692 19% /
tmpfs 15701160 0 15701160 0% /dev
tmpfs 15701160 0 15701160 0% /sys/fs/cgroup
/dev/xvdbg 309506048 149730860 146106552 51% /prometheus
/dev/xvda1 98227828 17592896 76340692 19% /dev/termination-log
/dev/xvda1 98227828 17592896 76340692 19% /etc/prometheus
/dev/xvda1 98227828 17592896 76340692 19% /etc/resolv.conf
/dev/xvda1 98227828 17592896 76340692 19% /etc/hostname
/dev/xvda1 98227828 17592896 76340692 19% /etc/hosts
shm 65536 0 65536 0% /dev/shm
tmpfs 15701160 12 15701148 0% /var/run/secrets/kubernetes.io/serviceaccount
tmpfs 15701160 0 15701160 0% /proc/kcore
tmpfs 15701160 0 15701160 0% /proc/timer_list
tmpfs 15701160 0 15701160 0% /proc/timer_stats
tmpfs 15701160 0 15701160 0% /proc/sched_debug
Однако это не работает для меня
$kubectl -n example-system exec -it example-monitoring-0 df -kh
Error: unknown shorthand flag: 'k' in -kh
Examples:
# Get output from running 'date' from pod 123456-7890, using the first container by default
kubectl exec 123456-7890 date
# Get output from running 'date' in ruby-container from pod 123456-7890
kubectl exec 123456-7890 -c ruby-container date
# Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod 123456-7890
# and sends stdout/stderr from 'bash' back to the client
kubectl exec 123456-7890 -c ruby-container -i -t -- bash -il
Options:
-c, --container='': Container name. If omitted, the first container in the pod will be chosen
-p, --pod='': Pod name
-i, --stdin=false: Pass stdin to the container
-t, --tty=false: Stdin is a TTY
Usage:
kubectl exec POD [-c CONTAINER] -- COMMAND [args...] [options]
Use "kubectl options" for a list of global command-line options (applies to all commands).
На самом деле я пробовал следующие комбинации, но не работал.
kubectl -n example-system exec -it example-monitoring-0 `df -kh`
kubectl -n example-system exec -it example-monitoring-0 'df -kh'
kubectl -n example-system exec -it example-monitoring-0 "df -kh"
cmd="df -kh"
kubectl -n example-system exec -it example-monitoring-0 $cmd
kubectl -n example-system exec -it example-monitoring-0 echo $cmd
Надеюсь, кто-то сталкивался с такой проблемой.
Вы можете использовать разделитель с двойным тире, что обычно означает, что больше нет параметров команды, и все, что находится после него, считается строкой с пробелами.
$ kubectl -n example-system exec -it example-monitoring-0 -- df -kh
Вот - популярный вопрос об этом на сайте Unix и Linux.