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       --as=""      Username to impersonate for the operation. User could be a
48       regular user or a service account in a namespace.
49
50
51       --as-group=[]       Group  to  impersonate for the operation, this flag
52       can be repeated to specify multiple groups.
53
54
55       --as-uid=""      UID to impersonate for the operation.
56
57
58       --azure-container-registry-config=""      Path to the  file  containing
59       Azure container registry configuration information.
60
61
62       --cache-dir="/builddir/.kube/cache"      Default cache directory
63
64
65       --certificate-authority=""      Path to a cert file for the certificate
66       authority
67
68
69       --client-certificate=""      Path to a client certificate file for TLS
70
71
72       --client-key=""      Path to a client key file for TLS
73
74
75       --cluster=""      The name of the kubeconfig cluster to use
76
77
78       --context=""      The name of the kubeconfig context to use
79
80
81       --insecure-skip-tls-verify=false      If true, the server's certificate
82       will not be checked for validity. This will make your HTTPS connections
83       insecure
84
85
86       --kubeconfig=""      Path to the kubeconfig file to  use  for  CLI  re‐
87       quests.
88
89
90       --match-server-version=false        Require  server  version  to  match
91       client version
92
93
94       -n, --namespace=""      If present, the namespace scope  for  this  CLI
95       request
96
97
98       --password=""      Password for basic authentication to the API server
99
100
101       --profile="none"         Name   of   profile   to   capture.   One   of
102       (none|cpu|heap|goroutine|threadcreate|block|mutex)
103
104
105       --profile-output="profile.pprof"      Name of the  file  to  write  the
106       profile to
107
108
109       --request-timeout="0"       The length of time to wait before giving up
110       on a single server request. Non-zero values  should  contain  a  corre‐
111       sponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't time‐
112       out requests.
113
114
115       -s, --server=""      The address and port of the Kubernetes API server
116
117
118       --tls-server-name=""      Server name to  use  for  server  certificate
119       validation.  If  it  is  not provided, the hostname used to contact the
120       server is used
121
122
123       --token=""      Bearer token for authentication to the API server
124
125
126       --user=""      The name of the kubeconfig user to use
127
128
129       --username=""      Username for basic authentication to the API server
130
131
132       --version=false      Print version information and quit
133
134
135       --warnings-as-errors=false      Treat warnings received from the server
136       as errors and exit with a non-zero exit code
137
138
139

EXAMPLE

141                # Get output from running the 'date' command from pod mypod, using the first container by default
142                kubectl exec mypod -- date
143
144                # Get output from running the 'date' command in ruby-container from pod mypod
145                kubectl exec mypod -c ruby-container -- date
146
147                # Switch to raw terminal mode; sends stdin to 'bash' in ruby-container from pod mypod
148                # and sends stdout/stderr from 'bash' back to the client
149                kubectl exec mypod -c ruby-container -i -t -- bash -il
150
151                # List contents of /usr from the first container of pod mypod and sort by modification time
152                # If the command you want to execute in the pod has any flags in common (e.g. -i),
153                # you must use two dashes (--) to separate your command's flags/arguments
154                # Also note, do not surround your command and its flags/arguments with quotes
155                # unless that is how you would execute it normally (i.e., do ls -t /usr, not "ls -t /usr")
156                kubectl exec mypod -i -t -- ls -t /usr
157
158                # Get output from running 'date' command from the first pod of the deployment mydeployment, using the first container by default
159                kubectl exec deploy/mydeployment -- date
160
161                # Get output from running 'date' command from the first pod of the service myservice, using the first container by default
162                kubectl exec svc/myservice -- date
163
164
165
166

SEE ALSO

168       kubectl(1),
169
170
171

HISTORY

173       January  2015,  Originally compiled by Eric Paris (eparis at redhat dot
174       com) based on the kubernetes source material, but hopefully  they  have
175       been automatically generated since!
176
177
178
179Manuals                              User            KUBERNETES(1)(kubernetes)
Impressum