1KUBERNETES(1)(kubernetes)                            KUBERNETES(1)(kubernetes)
2
3
4
5Eric Paris Jan 2015
6
7

NAME

9       kubectl exec - Execute a command in a container
10
11
12

SYNOPSIS

14       kubectl exec [OPTIONS]
15
16
17

DESCRIPTION

19       Execute a command in a container.
20
21
22

OPTIONS

24       -c, --container=""      Container name. If omitted, the first container
25       in the pod will be chosen
26
27
28       -f, --filename=[]      to use to exec into the resource
29
30
31       --pod-running-timeout=1m0s      The length of time (like 5s, 2m, or 3h,
32       higher than zero) to wait until at least one pod is running
33
34
35       -i, --stdin=false      Pass stdin to the container
36
37
38       -t, --tty=false      Stdin is a TTY
39
40
41

OPTIONS INHERITED FROM PARENT COMMANDS

43       --add-dir-header=false       If  true,  adds  the file directory to the
44       header of the log messages
45
46
47       --alsologtostderr=false      log to standard error as well as files
48
49
50       --application-metrics-count-limit=100      Max  number  of  application
51       metrics to store (per container)
52
53
54       --as=""      Username to impersonate for the operation
55
56
57       --as-group=[]       Group  to  impersonate for the operation, this flag
58       can be repeated to specify multiple groups.
59
60
61       --azure-container-registry-config=""      Path to the  file  containing
62       Azure container registry configuration information.
63
64
65       --boot-id-file="/proc/sys/kernel/random/boot_id"        Comma-separated
66       list of files to check for boot-id. Use the first one that exists.
67
68
69       --cache-dir="/builddir/.kube/cache"      Default cache directory
70
71
72       --certificate-authority=""      Path to a cert file for the certificate
73       authority
74
75
76       --client-certificate=""      Path to a client certificate file for TLS
77
78
79       --client-key=""      Path to a client key file for TLS
80
81
82       --cloud-provider-gce-l7lb-src-cidrs=130.211.0.0/22,35.191.0.0/16
83            CIDRs opened in GCE firewall for  L7  LB  traffic  proxy    health
84       checks
85
86
87       --cloud-provider-gce-lb-src-cidrs=130.211.0.0/22,209.85.152.0/22,209.85.204.0/22,35.191.0.0/16
88            CIDRs opened in GCE firewall for  L4  LB  traffic  proxy    health
89       checks
90
91
92       --cluster=""      The name of the kubeconfig cluster to use
93
94
95       --container-hints="/etc/cadvisor/container_hints.json"      location of
96       the container hints file
97
98
99       --containerd="/run/containerd/containerd.sock"      containerd endpoint
100
101
102       --containerd-namespace="k8s.io"      containerd namespace
103
104
105       --context=""      The name of the kubeconfig context to use
106
107
108       --default-not-ready-toleration-seconds=300      Indicates  the  tolera‐
109       tionSeconds  of  the toleration for notReady:NoExecute that is added by
110       default to every pod that does not already have such a toleration.
111
112
113       --default-unreachable-toleration-seconds=300      Indicates the tolera‐
114       tionSeconds  of  the toleration for unreachable:NoExecute that is added
115       by default to every pod that does not already have such a toleration.
116
117
118       --disable-root-cgroup-stats=false      Disable collecting  root  Cgroup
119       stats
120
121
122       --docker="unix:///var/run/docker.sock"      docker endpoint
123
124
125       --docker-env-metadata-whitelist=""      a comma-separated list of envi‐
126       ronment variable keys matched with specified prefix that  needs  to  be
127       collected for docker containers
128
129
130       --docker-only=false       Only  report docker containers in addition to
131       root stats
132
133
134       --docker-root="/var/lib/docker"      DEPRECATED: docker  root  is  read
135       from docker info (this is a fallback, default: /var/lib/docker)
136
137
138       --docker-tls=false      use TLS to connect to docker
139
140
141       --docker-tls-ca="ca.pem"      path to trusted CA
142
143
144       --docker-tls-cert="cert.pem"      path to client certificate
145
146
147       --docker-tls-key="key.pem"      path to private key
148
149
150       --enable-load-reader=false      Whether to enable cpu load reader
151
152
153       --event-storage-age-limit="default=0"      Max length of time for which
154       to store events (per type). Value is a comma separated list of key val‐
155       ues,  where the keys are event types (e.g.: creation, oom) or "default"
156       and the value is a duration. Default is applied  to  all  non-specified
157       event types
158
159
160       --event-storage-event-limit="default=0"       Max  number  of events to
161       store (per type). Value is a comma separated list of key values,  where
162       the  keys  are  event  types (e.g.: creation, oom) or "default" and the
163       value is an integer. Default is  applied  to  all  non-specified  event
164       types
165
166
167       --global-housekeeping-interval=1m0s      Interval between global house‐
168       keepings
169
170
171       --housekeeping-interval=10s      Interval between container  housekeep‐
172       ings
173
174
175       --insecure-skip-tls-verify=false      If true, the server's certificate
176       will not be checked for validity. This will make your HTTPS connections
177       insecure
178
179
180       --kubeconfig=""       Path  to  the  kubeconfig file to use for CLI re‐
181       quests.
182
183
184       --log-backtrace-at=:0      when logging hits line file:N, emit a  stack
185       trace
186
187
188       --log-cadvisor-usage=false       Whether to log the usage of the cAdvi‐
189       sor container
190
191
192       --log-dir=""      If non-empty, write log files in this directory
193
194
195       --log-file=""      If non-empty, use this log file
196
197
198       --log-file-max-size=1800      Defines the maximum size a log  file  can
199       grow to. Unit is megabytes. If the value is 0, the maximum file size is
200       unlimited.
201
202
203       --log-flush-frequency=5s      Maximum number  of  seconds  between  log
204       flushes
205
206
207       --logtostderr=true      log to standard error instead of files
208
209
210       --machine-id-file="/etc/machine-id,/var/lib/dbus/machine-id"
211            Comma-separated list of files to check  for  machine-id.  Use  the
212       first one that exists.
213
214
215       --match-server-version=false        Require  server  version  to  match
216       client version
217
218
219       -n, --namespace=""      If present, the namespace scope  for  this  CLI
220       request
221
222
223       --one-output=false      If true, only write logs to their native sever‐
224       ity level (vs also writing to each lower severity level
225
226
227       --password=""      Password for basic authentication to the API server
228
229
230       --profile="none"        Name   of   profile   to   capture.   One    of
231       (none|cpu|heap|goroutine|threadcreate|block|mutex)
232
233
234       --profile-output="profile.pprof"       Name  of  the  file to write the
235       profile to
236
237
238       --referenced-reset-interval=0      Reset interval for referenced  bytes
239       (container_referenced_bytes metric), number of measurement cycles after
240       which referenced bytes are cleared, if set to 0  referenced  bytes  are
241       never cleared (default: 0)
242
243
244       --request-timeout="0"       The length of time to wait before giving up
245       on a single server request. Non-zero values  should  contain  a  corre‐
246       sponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't time‐
247       out requests.
248
249
250       -s, --server=""      The address and port of the Kubernetes API server
251
252
253       --skip-headers=false      If true, avoid header  prefixes  in  the  log
254       messages
255
256
257       --skip-log-headers=false       If  true, avoid headers when opening log
258       files
259
260
261       --stderrthreshold=2      logs at or above this threshold go to stderr
262
263
264       --storage-driver-buffer-duration=1m0s      Writes in the storage driver
265       will  be  buffered  for  this duration, and committed to the non memory
266       backends as a single transaction
267
268
269       --storage-driver-db="cadvisor"      database name
270
271
272       --storage-driver-host="localhost:8086"      database host:port
273
274
275       --storage-driver-password="root"      database password
276
277
278       --storage-driver-secure=false      use secure connection with database
279
280
281       --storage-driver-table="stats"      table name
282
283
284       --storage-driver-user="root"      database username
285
286
287       --tls-server-name=""      Server name to  use  for  server  certificate
288       validation.  If  it  is  not provided, the hostname used to contact the
289       server is used
290
291
292       --token=""      Bearer token for authentication to the API server
293
294
295       --update-machine-info-interval=5m0s      Interval between machine  info
296       updates.
297
298
299       --user=""      The name of the kubeconfig user to use
300
301
302       --username=""      Username for basic authentication to the API server
303
304
305       -v, --v=0      number for the log level verbosity
306
307
308       --version=false      Print version information and quit
309
310
311       --vmodule=        comma-separated   list   of  pattern=N  settings  for
312       file-filtered logging
313
314
315       --warnings-as-errors=false      Treat warnings received from the server
316       as errors and exit with a non-zero exit code
317
318
319

EXAMPLE

321                # Get output from running 'date' command from pod mypod, using the first container by default
322                kubectl exec mypod -- date
323
324                # Get output from running 'date' command in ruby-container from pod mypod
325                kubectl exec mypod -c ruby-container -- date
326
327                # Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod mypod
328                # and sends stdout/stderr from 'bash' back to the client
329                kubectl exec mypod -c ruby-container -i -t -- bash -il
330
331                # List contents of /usr from the first container of pod mypod and sort by modification time.
332                # If the command you want to execute in the pod has any flags in common (e.g. -i),
333                # you must use two dashes (--) to separate your command's flags/arguments.
334                # Also note, do not surround your command and its flags/arguments with quotes
335                # unless that is how you would execute it normally (i.e., do ls -t /usr, not "ls -t /usr").
336                kubectl exec mypod -i -t -- ls -t /usr
337
338                # Get output from running 'date' command from the first pod of the deployment mydeployment, using the first container by default
339                kubectl exec deploy/mydeployment -- date
340
341                # Get output from running 'date' command from the first pod of the service myservice, using the first container by default
342                kubectl exec svc/myservice -- date
343
344
345
346

SEE ALSO

348       kubectl(1),
349
350
351

HISTORY

353       January  2015,  Originally compiled by Eric Paris (eparis at redhat dot
354       com) based on the kubernetes source material, but hopefully  they  have
355       been automatically generated since!
356
357
358
359Manuals                              User            KUBERNETES(1)(kubernetes)
Impressum