1KUBERNETES(1)(kubernetes) KUBERNETES(1)(kubernetes)
2
3
4
5Eric Paris Jan 2015
6
7
9 kubectl expose - Take a replication controller, service, deployment or
10 pod and expose it as a new Kubernetes service
11
12
13
15 kubectl expose [OPTIONS]
16
17
18
20 Expose a resource as a new Kubernetes service.
21
22
23 Looks up a deployment, service, replica set, replication controller or
24 pod by name and uses the selector for that resource as the selector for
25 a new service on the specified port. A deployment or replica set will
26 be exposed as a service only if its selector is convertible to a selec‐
27 tor that service supports, i.e. when the selector contains only the
28 matchLabels component. Note that if no port is specified via --port and
29 the exposed resource has multiple ports, all will be re-used by the new
30 service. Also if no labels are specified, the new service will re-use
31 the labels from the resource it exposes.
32
33
34 Possible resources include (case insensitive):
35
36
37 pod (po), service (svc), replicationcontroller (rc), deployment (de‐
38 ploy), replicaset (rs)
39
40
41
43 --allow-missing-template-keys=true If true, ignore any errors in
44 templates when a field or map key is missing in the template. Only ap‐
45 plies to golang and jsonpath output formats.
46
47
48 --cluster-ip="" ClusterIP to be assigned to the service. Leave
49 empty to auto-allocate, or set to 'None' to create a headless service.
50
51
52 --dry-run="none" Must be "none", "server", or "client". If client
53 strategy, only print the object that would be sent, without sending it.
54 If server strategy, submit server-side request without persisting the
55 resource.
56
57
58 --external-ip="" Additional external IP address (not managed by
59 Kubernetes) to accept for the service. If this IP is routed to a node,
60 the service can be accessed by this IP in addition to its generated
61 service IP.
62
63
64 --field-manager="kubectl-expose" Name of the manager used to track
65 field ownership.
66
67
68 -f, --filename=[] Filename, directory, or URL to files identifying
69 the resource to expose a service
70
71
72 -k, --kustomize="" Process the kustomization directory. This flag
73 can't be used together with -f or -R.
74
75
76 -l, --labels="" Labels to apply to the service created by this
77 call.
78
79
80 --load-balancer-ip="" IP to assign to the LoadBalancer. If empty,
81 an ephemeral IP will be created and used (cloud-provider specific).
82
83
84 --name="" The name for the newly created object.
85
86
87 -o, --output="" Output format. One of: (json, yaml, name, go-tem‐
88 plate, go-template-file, template, templatefile, jsonpath, jsonpath-as-
89 json, jsonpath-file).
90
91
92 --override-type="merge" The method used to override the generated
93 object: json, merge, or strategic.
94
95
96 --overrides="" An inline JSON override for the generated object.
97 If this is non-empty, it is used to override the generated object. Re‐
98 quires that the object supply a valid apiVersion field.
99
100
101 --port="" The port that the service should serve on. Copied from
102 the resource being exposed, if unspecified
103
104
105 --protocol="" The network protocol for the service to be created.
106 Default is 'TCP'.
107
108
109 --record=false Record current kubectl command in the resource an‐
110 notation. If set to false, do not record the command. If set to true,
111 record the command. If not set, default to updating the existing anno‐
112 tation value only if one already exists.
113
114
115 -R, --recursive=false Process the directory used in -f, --filename
116 recursively. Useful when you want to manage related manifests organized
117 within the same directory.
118
119
120 --save-config=false If true, the configuration of current object
121 will be saved in its annotation. Otherwise, the annotation will be un‐
122 changed. This flag is useful when you want to perform kubectl apply on
123 this object in the future.
124
125
126 --selector="" A label selector to use for this service. Only
127 equality-based selector requirements are supported. If empty (the de‐
128 fault) infer the selector from the replication controller or replica
129 set.)
130
131
132 --session-affinity="" If non-empty, set the session affinity for
133 the service to this; legal values: 'None', 'ClientIP'
134
135
136 --show-managed-fields=false If true, keep the managedFields when
137 printing objects in JSON or YAML format.
138
139
140 --target-port="" Name or number for the port on the container that
141 the service should direct traffic to. Optional.
142
143
144 --template="" Template string or path to template file to use when
145 -o=go-template, -o=go-template-file. The template format is golang tem‐
146 plates [http://golang.org/pkg/text/template/#pkg-overview].
147
148
149 --type="" Type for this service: ClusterIP, NodePort, LoadBal‐
150 ancer, or ExternalName. Default is 'ClusterIP'.
151
152
153
155 --as="" Username to impersonate for the operation. User could be a
156 regular user or a service account in a namespace.
157
158
159 --as-group=[] Group to impersonate for the operation, this flag
160 can be repeated to specify multiple groups.
161
162
163 --as-uid="" UID to impersonate for the operation.
164
165
166 --azure-container-registry-config="" Path to the file containing
167 Azure container registry configuration information.
168
169
170 --cache-dir="/builddir/.kube/cache" Default cache directory
171
172
173 --certificate-authority="" Path to a cert file for the certificate
174 authority
175
176
177 --client-certificate="" Path to a client certificate file for TLS
178
179
180 --client-key="" Path to a client key file for TLS
181
182
183 --cluster="" The name of the kubeconfig cluster to use
184
185
186 --context="" The name of the kubeconfig context to use
187
188
189 --insecure-skip-tls-verify=false If true, the server's certificate
190 will not be checked for validity. This will make your HTTPS connections
191 insecure
192
193
194 --kubeconfig="" Path to the kubeconfig file to use for CLI re‐
195 quests.
196
197
198 --match-server-version=false Require server version to match
199 client version
200
201
202 -n, --namespace="" If present, the namespace scope for this CLI
203 request
204
205
206 --password="" Password for basic authentication to the API server
207
208
209 --profile="none" Name of profile to capture. One of
210 (none|cpu|heap|goroutine|threadcreate|block|mutex)
211
212
213 --profile-output="profile.pprof" Name of the file to write the
214 profile to
215
216
217 --request-timeout="0" The length of time to wait before giving up
218 on a single server request. Non-zero values should contain a corre‐
219 sponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't time‐
220 out requests.
221
222
223 -s, --server="" The address and port of the Kubernetes API server
224
225
226 --tls-server-name="" Server name to use for server certificate
227 validation. If it is not provided, the hostname used to contact the
228 server is used
229
230
231 --token="" Bearer token for authentication to the API server
232
233
234 --user="" The name of the kubeconfig user to use
235
236
237 --username="" Username for basic authentication to the API server
238
239
240 --version=false Print version information and quit
241
242
243 --warnings-as-errors=false Treat warnings received from the server
244 as errors and exit with a non-zero exit code
245
246
247
249 # Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000
250 kubectl expose rc nginx --port=80 --target-port=8000
251
252 # Create a service for a replication controller identified by type and name specified in "nginx-controller.yaml", which serves on port 80 and connects to the containers on port 8000
253 kubectl expose -f nginx-controller.yaml --port=80 --target-port=8000
254
255 # Create a service for a pod valid-pod, which serves on port 444 with the name "frontend"
256 kubectl expose pod valid-pod --port=444 --name=frontend
257
258 # Create a second service based on the above service, exposing the container port 8443 as port 443 with the name "nginx-https"
259 kubectl expose service nginx --port=443 --target-port=8443 --name=nginx-https
260
261 # Create a service for a replicated streaming application on port 4100 balancing UDP traffic and named 'video-stream'.
262 kubectl expose rc streamer --port=4100 --protocol=UDP --name=video-stream
263
264 # Create a service for a replicated nginx using replica set, which serves on port 80 and connects to the containers on port 8000
265 kubectl expose rs nginx --port=80 --target-port=8000
266
267 # Create a service for an nginx deployment, which serves on port 80 and connects to the containers on port 8000
268 kubectl expose deployment nginx --port=80 --target-port=8000
269
270
271
272
274 kubectl(1),
275
276
277
279 January 2015, Originally compiled by Eric Paris (eparis at redhat dot
280 com) based on the kubernetes source material, but hopefully they have
281 been automatically generated since!
282
283
284
285Manuals User KUBERNETES(1)(kubernetes)