1KUBERNETES(1)(kubernetes) KUBERNETES(1)(kubernetes)
2
3
4
5Eric Paris Jan 2015
6
7
9 kubectl exec - Execute a command in a container
10
11
12
14 kubectl exec [OPTIONS]
15
16
17
19 Execute a command in a container.
20
21
22
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
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 --disable-compression=false If true, opt-out of response compres‐
82 sion for all requests to the server
83
84
85 --insecure-skip-tls-verify=false If true, the server's certificate
86 will not be checked for validity. This will make your HTTPS connections
87 insecure
88
89
90 --kubeconfig="" Path to the kubeconfig file to use for CLI re‐
91 quests.
92
93
94 --match-server-version=false Require server version to match
95 client version
96
97
98 -n, --namespace="" If present, the namespace scope for this CLI
99 request
100
101
102 --password="" Password for basic authentication to the API server
103
104
105 --profile="none" Name of profile to capture. One of
106 (none|cpu|heap|goroutine|threadcreate|block|mutex)
107
108
109 --profile-output="profile.pprof" Name of the file to write the
110 profile to
111
112
113 --request-timeout="0" The length of time to wait before giving up
114 on a single server request. Non-zero values should contain a corre‐
115 sponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't time‐
116 out requests.
117
118
119 -s, --server="" The address and port of the Kubernetes API server
120
121
122 --tls-server-name="" Server name to use for server certificate
123 validation. If it is not provided, the hostname used to contact the
124 server is used
125
126
127 --token="" Bearer token for authentication to the API server
128
129
130 --user="" The name of the kubeconfig user to use
131
132
133 --username="" Username for basic authentication to the API server
134
135
136 --version=false Print version information and quit
137
138
139 --warnings-as-errors=false Treat warnings received from the server
140 as errors and exit with a non-zero exit code
141
142
143
145 # Get output from running the 'date' command from pod mypod, using the first container by default
146 kubectl exec mypod -- date
147
148 # Get output from running the 'date' command in ruby-container from pod mypod
149 kubectl exec mypod -c ruby-container -- date
150
151 # Switch to raw terminal mode; sends stdin to 'bash' in ruby-container from pod mypod
152 # and sends stdout/stderr from 'bash' back to the client
153 kubectl exec mypod -c ruby-container -i -t -- bash -il
154
155 # List contents of /usr from the first container of pod mypod and sort by modification time
156 # If the command you want to execute in the pod has any flags in common (e.g. -i),
157 # you must use two dashes (--) to separate your command's flags/arguments
158 # Also note, do not surround your command and its flags/arguments with quotes
159 # unless that is how you would execute it normally (i.e., do ls -t /usr, not "ls -t /usr")
160 kubectl exec mypod -i -t -- ls -t /usr
161
162 # Get output from running 'date' command from the first pod of the deployment mydeployment, using the first container by default
163 kubectl exec deploy/mydeployment -- date
164
165 # Get output from running 'date' command from the first pod of the service myservice, using the first container by default
166 kubectl exec svc/myservice -- date
167
168
169
170
172 kubectl(1),
173
174
175
177 January 2015, Originally compiled by Eric Paris (eparis at redhat dot
178 com) based on the kubernetes source material, but hopefully they have
179 been automatically generated since!
180
181
182
183Manuals User KUBERNETES(1)(kubernetes)