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, use the kubectl.ku‐
25       bernetes.io/default-container annotation for selecting the container to
26       be attached or the first container in the pod will be chosen
27
28
29       -f, --filename=[]      to use to exec into the resource
30
31
32       --pod-running-timeout=1m0s      The length of time (like 5s, 2m, or 3h,
33       higher than zero) to wait until at least one pod is running
34
35
36       -q, --quiet=false      Only print output from the remote session
37
38
39       -i, --stdin=false      Pass stdin to the container
40
41
42       -t, --tty=false      Stdin is a TTY
43
44
45

OPTIONS INHERITED FROM PARENT COMMANDS

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

EXAMPLE

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

SEE ALSO

352       kubectl(1),
353
354
355

HISTORY

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