1KUBERNETES(1)                      Jan 2015                      KUBERNETES(1)
2
3
4

NAME

6       kubectl  expose - Take a replication controller, service, deployment or
7       pod and expose it as a new Kubernetes Service
8
9
10

SYNOPSIS

12       kubectl expose [OPTIONS]
13
14
15

DESCRIPTION

17       Expose a resource as a new Kubernetes service.
18
19
20       Looks up a deployment, service, replica set, replication controller  or
21       pod by name and uses the selector for that resource as the selector for
22       a new service on the specified port. A deployment or replica  set  will
23       be exposed as a service only if its selector is convertible to a selec‐
24       tor that service supports, i.e. when the  selector  contains  only  the
25       matchLabels component. Note that if no port is specified via --port and
26       the exposed resource has multiple ports, all will be re-used by the new
27       service.  Also  if no labels are specified, the new service will re-use
28       the labels from the resource it exposes.
29
30
31       Possible resources include (case insensitive):
32
33
34       pod  (po),  service  (svc),  replicationcontroller   (rc),   deployment
35       (deploy), replicaset (rs)
36
37
38

OPTIONS

40       --allow-missing-template-keys=true
41           If  true, ignore any errors in templates when a field or map key is
42       missing in the template. Only applies to  golang  and  jsonpath  output
43       formats.
44
45
46       --cluster-ip=""
47           ClusterIP  to be assigned to the service. Leave empty to auto-allo‐
48       cate, or set to 'None' to create a headless service.
49
50
51       --container-port=""
52           Synonym for --target-port
53
54
55       --dry-run=false
56           If true, only print the object that would be sent, without  sending
57       it.
58
59
60       --external-ip=""
61           Additional  external  IP  address  (not  managed  by Kubernetes) to
62       accept for the service. If this IP is routed to a node, the service can
63       be accessed by this IP in addition to its generated service IP.
64
65
66       -f, --filename=[]
67           Filename,  directory,  or  URL to files identifying the resource to
68       expose a service
69
70
71       --generator="service/v2"
72           The name of the API generator to use. There are 2 generators: 'ser‐
73       vice/v1'  and  'service/v2'.  The  only difference between them is that
74       service port in v1 is named 'default', while it is left unnamed in  v2.
75       Default is 'service/v2'.
76
77
78       -k, --kustomize=""
79           Process  the  kustomization  directory.  This  flag  can't  be used
80       together with -f or -R.
81
82
83       -l, --labels=""
84           Labels to apply to the service created by this call.
85
86
87       --load-balancer-ip=""
88           IP to assign to the LoadBalancer. If empty, an ephemeral IP will be
89       created and used (cloud-provider specific).
90
91
92       --name=""
93           The name for the newly created object.
94
95
96       -o, --output=""
97           Output    format.    One   of:   json|yaml|name|go-template|go-tem‐
98       plate-file|template|templatefile|jsonpath|jsonpath-file.
99
100
101       --overrides=""
102           An inline JSON override  for  the  generated  object.  If  this  is
103       non-empty,  it  is used to override the generated object. Requires that
104       the object supply a valid apiVersion field.
105
106
107       --port=""
108           The port that the service should serve on. Copied from the resource
109       being exposed, if unspecified
110
111
112       --protocol=""
113           The  network  protocol  for  the  service to be created. Default is
114       'TCP'.
115
116
117       --record=false
118           Record current kubectl command in the resource annotation.  If  set
119       to  false,  do  not record the command. If set to true, record the com‐
120       mand. If not set, default to updating  the  existing  annotation  value
121       only if one already exists.
122
123
124       -R, --recursive=false
125           Process  the  directory  used in -f, --filename recursively. Useful
126       when you want to manage related manifests  organized  within  the  same
127       directory.
128
129
130       --save-config=false
131           If  true,  the configuration of current object will be saved in its
132       annotation. Otherwise, the annotation will be unchanged. This  flag  is
133       useful  when  you  want  to perform kubectl apply on this object in the
134       future.
135
136
137       --selector=""
138           A label selector to  use  for  this  service.  Only  equality-based
139       selector  requirements  are supported. If empty (the default) infer the
140       selector from the replication controller or replica set.)
141
142
143       --session-affinity=""
144           If non-empty, set the session affinity for  the  service  to  this;
145       legal values: 'None', 'ClientIP'
146
147
148       --target-port=""
149           Name  or  number  for  the  port  on the container that the service
150       should direct traffic to. Optional.
151
152
153       --template=""
154           Template string or path to template file  to  use  when  -o=go-tem‐
155       plate,  -o=go-template-file.  The template format is golang templates [
156http://golang.org/pkg/text/template/#pkg-overview⟩].
157
158
159       --type=""
160           Type for this service: ClusterIP, NodePort, LoadBalancer, or Exter‐
161       nalName. Default is 'ClusterIP'.
162
163
164

OPTIONS INHERITED FROM PARENT COMMANDS

166       --alsologtostderr=false
167           log to standard error as well as files
168
169
170       --application-metrics-count-limit=100
171           Max number of application metrics to store (per container)
172
173
174       --as=""
175           Username to impersonate for the operation
176
177
178       --as-group=[]
179           Group  to  impersonate for the operation, this flag can be repeated
180       to specify multiple groups.
181
182
183       --azure-container-registry-config=""
184           Path to the file containing Azure container registry  configuration
185       information.
186
187
188       --boot-id-file="/proc/sys/kernel/random/boot_id"
189           Comma-separated  list  of files to check for boot-id. Use the first
190       one that exists.
191
192
193       --cache-dir="/builddir/.kube/http-cache"
194           Default HTTP cache directory
195
196
197       --certificate-authority=""
198           Path to a cert file for the certificate authority
199
200
201       --client-certificate=""
202           Path to a client certificate file for TLS
203
204
205       --client-key=""
206           Path to a client key file for TLS
207
208
209       --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
210           CIDRs opened in GCE firewall for LB traffic proxy  health checks
211
212
213       --cluster=""
214           The name of the kubeconfig cluster to use
215
216
217       --container-hints="/etc/cadvisor/container_hints.json"
218           location of the container hints file
219
220
221       --containerd="/run/containerd/containerd.sock"
222           containerd endpoint
223
224
225       --containerd-namespace="k8s.io"
226           containerd namespace
227
228
229       --context=""
230           The name of the kubeconfig context to use
231
232
233       --default-not-ready-toleration-seconds=300
234           Indicates    the    tolerationSeconds   of   the   toleration   for
235       notReady:NoExecute that is added by default to every pod that does  not
236       already have such a toleration.
237
238
239       --default-unreachable-toleration-seconds=300
240           Indicates  the  tolerationSeconds  of  the  toleration for unreach‐
241       able:NoExecute that is added by default to  every  pod  that  does  not
242       already have such a toleration.
243
244
245       --docker="unix:///var/run/docker.sock"
246           docker endpoint
247
248
249       --docker-env-metadata-whitelist=""
250           a  comma-separated  list of environment variable keys that needs to
251       be collected for docker containers
252
253
254       --docker-only=false
255           Only report docker containers in addition to root stats
256
257
258       --docker-root="/var/lib/docker"
259           DEPRECATED: docker root is read from docker info (this is  a  fall‐
260       back, default: /var/lib/docker)
261
262
263       --docker-tls=false
264           use TLS to connect to docker
265
266
267       --docker-tls-ca="ca.pem"
268           path to trusted CA
269
270
271       --docker-tls-cert="cert.pem"
272           path to client certificate
273
274
275       --docker-tls-key="key.pem"
276           path to private key
277
278
279       --enable-load-reader=false
280           Whether to enable cpu load reader
281
282
283       --event-storage-age-limit="default=0"
284           Max length of time for which to store events (per type). Value is a
285       comma separated list of key values, where  the  keys  are  event  types
286       (e.g.: creation, oom) or "default" and the value is a duration. Default
287       is applied to all non-specified event types
288
289
290       --event-storage-event-limit="default=0"
291           Max number of events to store (per type). Value is  a  comma  sepa‐
292       rated  list  of  key values, where the keys are event types (e.g.: cre‐
293       ation, oom) or "default" and  the  value  is  an  integer.  Default  is
294       applied to all non-specified event types
295
296
297       --global-housekeeping-interval=1m0s
298           Interval between global housekeepings
299
300
301       --housekeeping-interval=10s
302           Interval between container housekeepings
303
304
305       --insecure-skip-tls-verify=false
306           If true, the server's certificate will not be checked for validity.
307       This will make your HTTPS connections insecure
308
309
310       --kubeconfig=""
311           Path to the kubeconfig file to use for CLI requests.
312
313
314       --log-backtrace-at=:0
315           when logging hits line file:N, emit a stack trace
316
317
318       --log-cadvisor-usage=false
319           Whether to log the usage of the cAdvisor container
320
321
322       --log-dir=""
323           If non-empty, write log files in this directory
324
325
326       --log-file=""
327           If non-empty, use this log file
328
329
330       --log-file-max-size=1800
331           Defines the maximum size a log file can grow to. Unit is megabytes.
332       If the value is 0, the maximum file size is unlimited.
333
334
335       --log-flush-frequency=5s
336           Maximum number of seconds between log flushes
337
338
339       --logtostderr=true
340           log to standard error instead of files
341
342
343       --machine-id-file="/etc/machine-id,/var/lib/dbus/machine-id"
344           Comma-separated  list  of  files  to  check for machine-id. Use the
345       first one that exists.
346
347
348       --match-server-version=false
349           Require server version to match client version
350
351
352       -n, --namespace=""
353           If present, the namespace scope for this CLI request
354
355
356       --password=""
357           Password for basic authentication to the API server
358
359
360       --profile="none"
361           Name of profile to capture. One of (none|cpu|heap|goroutine|thread‐
362       create|block|mutex)
363
364
365       --profile-output="profile.pprof"
366           Name of the file to write the profile to
367
368
369       --request-timeout="0"
370           The  length  of  time  to  wait before giving up on a single server
371       request. Non-zero values should contain a corresponding time unit (e.g.
372       1s, 2m, 3h). A value of zero means don't timeout requests.
373
374
375       -s, --server=""
376           The address and port of the Kubernetes API server
377
378
379       --skip-headers=false
380           If true, avoid header prefixes in the log messages
381
382
383       --skip-log-headers=false
384           If true, avoid headers when opening log files
385
386
387       --stderrthreshold=2
388           logs at or above this threshold go to stderr
389
390
391       --storage-driver-buffer-duration=1m0s
392           Writes  in  the  storage driver will be buffered for this duration,
393       and committed to the non memory backends as a single transaction
394
395
396       --storage-driver-db="cadvisor"
397           database name
398
399
400       --storage-driver-host="localhost:8086"
401           database host:port
402
403
404       --storage-driver-password="root"
405           database password
406
407
408       --storage-driver-secure=false
409           use secure connection with database
410
411
412       --storage-driver-table="stats"
413           table name
414
415
416       --storage-driver-user="root"
417           database username
418
419
420       --token=""
421           Bearer token for authentication to the API server
422
423
424       --update-machine-info-interval=5m0s
425           Interval between machine info updates.
426
427
428       --user=""
429           The name of the kubeconfig user to use
430
431
432       --username=""
433           Username for basic authentication to the API server
434
435
436       -v, --v=0
437           number for the log level verbosity
438
439
440       --version=false
441           Print version information and quit
442
443
444       --vmodule=
445           comma-separated list of pattern=N settings for  file-filtered  log‐
446       ging
447
448
449

EXAMPLE

451                # Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000.
452                kubectl expose rc nginx --port=80 --target-port=8000
453
454                # 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.
455                kubectl expose -f nginx-controller.yaml --port=80 --target-port=8000
456
457                # Create a service for a pod valid-pod, which serves on port 444 with the name "frontend"
458                kubectl expose pod valid-pod --port=444 --name=frontend
459
460                # Create a second service based on the above service, exposing the container port 8443 as port 443 with the name "nginx-https"
461                kubectl expose service nginx --port=443 --target-port=8443 --name=nginx-https
462
463                # Create a service for a replicated streaming application on port 4100 balancing UDP traffic and named 'video-stream'.
464                kubectl expose rc streamer --port=4100 --protocol=UDP --name=video-stream
465
466                # Create a service for a replicated nginx using replica set, which serves on port 80 and connects to the containers on port 8000.
467                kubectl expose rs nginx --port=80 --target-port=8000
468
469                # Create a service for an nginx deployment, which serves on port 80 and connects to the containers on port 8000.
470                kubectl expose deployment nginx --port=80 --target-port=8000
471
472
473
474

SEE ALSO

476       kubectl(1),
477
478
479

HISTORY

481       January  2015,  Originally compiled by Eric Paris (eparis at redhat dot
482       com) based on the kubernetes source material, but hopefully  they  have
483       been automatically generated since!
484
485
486
487Eric Paris                  kubernetes User Manuals              KUBERNETES(1)
Impressum