1OC(1)                              June 2016                             OC(1)
2
3
4

NAME

6       oc observe - Observe changes to resources and react to them (experimen‐
7       tal)
8
9
10

SYNOPSIS

12       oc observe [OPTIONS]
13
14
15

DESCRIPTION

17       Observe changes to resources and take action on them
18
19
20       This command assists in building scripted  reactions  to  changes  that
21       occur in Kubernetes or OpenShift resources. This is frequently referred
22       to as a 'controller' in Kubernetes and acts to ensure particular condi‐
23       tions  are  maintained.  On  startup,  observe  will  list  all  of the
24       resources of a particular type and execute the provided script on  each
25       one.  Observe  watches  the  server for changes, and will reexecute the
26       script for each update.
27
28
29       Observe works best for problems of the form "for every resource X, make
30       sure Y is true". Some examples of ways observe can be used include:
31
32              · Ensure every namespace has a quota or limit range object
33
34              · Ensure every service is registered in DNS by making calls to a
35              DNS API
36
37              · Send an email alert whenever a node reports 'NotReady'
38
39              · Watch for the 'FailedScheduling' event and write an  IRC  mes‐
40              sage
41
42              ·  Dynamically  provision  persistent  volumes when a new PVC is
43              created
44
45              · Delete pods that have reached successful  completion  after  a
46              period of time.
47
48       The  simplest  pattern  is  maintaining an invariant on an object - for
49       instance, "every namespace should have an annotation that indicates its
50       owner".  If the object is deleted no reaction is necessary. A variation
51       on that pattern is creating another  object:  "every  namespace  should
52       have a quota object based on the resources allowed for an owner".
53
54
55       $ cat set_owner.sh
56         #!/bin/sh
57         if  [[  "$(oc  get  namespace  "$1"  --template='{{ .metadata.annota‐
58       tions.owner }}')" == "" ]]; then
59           oc annotate namespace "$1" owner=bob
60         fi
61
62
63       $ oc observe namespaces -- ./set_owner.sh
64
65
66       The set _owner.sh script is invoked with a single argument (the  names‐
67       pace name) for each namespace. This simple script ensures that any user
68       without the "owner" annotation gets one set, but preserves any existing
69       value.
70
71
72       The  next common of controller pattern is provisioning - making changes
73       in an external system to match the  state  of  a  Kubernetes  resource.
74       These  scripts  need to account for deletions that may take place while
75       the observe command is not running. You can provide the list  of  known
76       objects  via  the --names command, which should return a newline-delim‐
77       ited list of names  or  namespace/name  pairs.  Your  command  will  be
78       invoked  whenever  observe  checks the latest state on the server - any
79       resources returned by --names that are not found on the server will  be
80       passed to your --delete command.
81
82
83       For  example,  you  may wish to ensure that every node that is added to
84       Kubernetes is added to your cluster inventory along with its IP:
85
86
87       $ cat add_to_inventory.sh
88         #!/bin/sh
89         echo "$1 $2" >> inventory
90         sort -u inventory -o inventory
91
92
93       $ cat remove_from_inventory.sh
94         #!/bin/sh
95         grep -vE "^$1 " inventory > /tmp/newinventory
96         mv -f /tmp/newinventory inventory
97
98
99       $ cat known_nodes.sh
100         #!/bin/sh
101         touch inventory
102         cut -f 1-1 -d ' ' inventory
103
104
105       $ oc observe nodes -a '{ .status.addresses[0].address }' \
106           --names ./known_nodes.sh \
107           --delete ./remove_from_inventory.sh \
108           -- ./add_to_inventory.sh
109
110
111       If you stop the observe command and then delete a node, when you launch
112       observe again the contents of inventory will be compared to the list of
113       nodes from the server, and any node  in  the  inventory  file  that  no
114       longer  exists will trigger a call to remove from inventory.sh with the
115       name of the node.
116
117
118       Important: when handling deletes, the previous state of the object  may
119       not  be  available  and  only  the name/namespace of the object will be
120       passed to   your --delete command as arguments  (all  custom  arguments
121       are omitted).
122
123
124       More  complicated  interactions  build on the two examples above - your
125       inventory script could make a call to allocate storage on  your  infra‐
126       structure  as  a service, or register node names in DNS, or set complex
127       firewalls. The more complex your integration, the more important it  is
128       to  record  enough data in the remote system that you can identify when
129       resources on either side are deleted.
130
131
132

OPTIONS

134       --all-namespaces=false
135           If true, list the requested object(s) across all projects.  Project
136       in current context is ignored.
137
138
139       -a, --argument=""
140           Template for the arguments to be passed to each command in the for‐
141       mat defined by --output.
142
143
144       -d, --delete=""
145           A command to run when resources are deleted. Specify multiple times
146       to add arguments.
147
148
149       --exit-after=0
150           Exit with status code 0 after the provided duration, optional.
151
152
153       --listen-addr=":11251"
154           The  name of an interface to listen on to expose metrics and health
155       checking.
156
157
158       --maximum-errors=20
159           Exit after this many errors have been detected with. May be set  to
160       -1 for no maximum.
161
162
163       --names=""
164           A  command  that  will  list  all  of  the  currently  known names,
165       optional. Specify multiple times to add arguments. Use to get notifica‐
166       tions when objects are deleted.
167
168
169       --no-headers=false
170           If  true,  skip printing information about each event prior to exe‐
171       cuting the command.
172
173
174       --object-env-var=""
175           The name of an env var to serialize the object to when calling  the
176       command, optional.
177
178
179       --once=false
180           If  true,  exit with a status code 0 after all current objects have
181       been processed.
182
183
184       --output="jsonpath"
185           Controls the template type used for the --argument flags. Supported
186       values are gotemplate and jsonpath.
187
188
189       --print-metrics-on-exit=false
190           If true, on exit write all metrics to stdout.
191
192
193       --resync-period=0
194           When non-zero, periodically reprocess every item from the server as
195       a Sync event. Use to ensure external systems are kept up to date.
196
197
198       --retry-count=2
199           The number of times to retry a failing command before continuing.
200
201
202       --retry-on-exit-code=0
203           If any command returns this exit code, retry  up  to  --retry-count
204       times.
205
206
207       --strict-templates=false
208           If true return an error on any field or map key that is not missing
209       in a template.
210
211
212       --type-env-var=""
213           The name of an env var to set  with  the  type  of  event  received
214       ('Sync',  'Updated',  'Deleted',  'Added')  to  the reaction command or
215       --delete.
216
217
218

OPTIONS INHERITED FROM PARENT COMMANDS

220       --allow_verification_with_non_compliant_keys=false
221           Allow  a  SignatureVerifier  to  use  keys  which  are  technically
222       non-compliant with RFC6962.
223
224
225       --alsologtostderr=false
226           log to standard error as well as files
227
228
229       --application_metrics_count_limit=100
230           Max number of application metrics to store (per container)
231
232
233       --as=""
234           Username to impersonate for the operation
235
236
237       --as-group=[]
238           Group  to  impersonate for the operation, this flag can be repeated
239       to specify multiple groups.
240
241
242       --azure-container-registry-config=""
243           Path to the file containing Azure container registry  configuration
244       information.
245
246
247       --boot_id_file="/proc/sys/kernel/random/boot_id"
248           Comma-separated  list  of files to check for boot-id. Use the first
249       one that exists.
250
251
252       --cache-dir="/builddir/.kube/http-cache"
253           Default HTTP cache directory
254
255
256       --certificate-authority=""
257           Path to a cert file for the certificate authority
258
259
260       --client-certificate=""
261           Path to a client certificate file for TLS
262
263
264       --client-key=""
265           Path to a client key file for TLS
266
267
268       --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
269           CIDRs opened in GCE firewall for LB traffic proxy  health checks
270
271
272       --cluster=""
273           The name of the kubeconfig cluster to use
274
275
276       --container_hints="/etc/cadvisor/container_hints.json"
277           location of the container hints file
278
279
280       --containerd="unix:///var/run/containerd.sock"
281           containerd endpoint
282
283
284       --context=""
285           The name of the kubeconfig context to use
286
287
288       --default-not-ready-toleration-seconds=300
289           Indicates    the    tolerationSeconds   of   the   toleration   for
290       notReady:NoExecute that is added by default to every pod that does  not
291       already have such a toleration.
292
293
294       --default-unreachable-toleration-seconds=300
295           Indicates  the  tolerationSeconds  of  the  toleration for unreach‐
296       able:NoExecute that is added by default to  every  pod  that  does  not
297       already have such a toleration.
298
299
300       --docker="unix:///var/run/docker.sock"
301           docker endpoint
302
303
304       --docker-tls=false
305           use TLS to connect to docker
306
307
308       --docker-tls-ca="ca.pem"
309           path to trusted CA
310
311
312       --docker-tls-cert="cert.pem"
313           path to client certificate
314
315
316       --docker-tls-key="key.pem"
317           path to private key
318
319
320       --docker_env_metadata_whitelist=""
321           a  comma-separated  list of environment variable keys that needs to
322       be collected for docker containers
323
324
325       --docker_only=false
326           Only report docker containers in addition to root stats
327
328
329       --docker_root="/var/lib/docker"
330           DEPRECATED: docker root is read from docker info (this is  a  fall‐
331       back, default: /var/lib/docker)
332
333
334       --enable_load_reader=false
335           Whether to enable cpu load reader
336
337
338       --event_storage_age_limit="default=24h"
339           Max length of time for which to store events (per type). Value is a
340       comma separated list of key values, where  the  keys  are  event  types
341       (e.g.: creation, oom) or "default" and the value is a duration. Default
342       is applied to all non-specified event types
343
344
345       --event_storage_event_limit="default=100000"
346           Max number of events to store (per type). Value is  a  comma  sepa‐
347       rated  list  of  key values, where the keys are event types (e.g.: cre‐
348       ation, oom) or "default" and  the  value  is  an  integer.  Default  is
349       applied to all non-specified event types
350
351
352       --global_housekeeping_interval=0
353           Interval between global housekeepings
354
355
356       --housekeeping_interval=0
357           Interval between container housekeepings
358
359
360       --httptest.serve=""
361           if non-empty, httptest.NewServer serves on this address and blocks
362
363
364       --insecure-skip-tls-verify=false
365           If true, the server's certificate will not be checked for validity.
366       This will make your HTTPS connections insecure
367
368
369       --kubeconfig=""
370           Path to the kubeconfig file to use for CLI requests.
371
372
373       --log-flush-frequency=0
374           Maximum number of seconds between log flushes
375
376
377       --log_backtrace_at=:0
378           when logging hits line file:N, emit a stack trace
379
380
381       --log_cadvisor_usage=false
382           Whether to log the usage of the cAdvisor container
383
384
385       --log_dir=""
386           If non-empty, write log files in this directory
387
388
389       --logtostderr=true
390           log to standard error instead of files
391
392
393       --machine_id_file="/etc/machine-id,/var/lib/dbus/machine-id"
394           Comma-separated list of files to  check  for  machine-id.  Use  the
395       first one that exists.
396
397
398       --match-server-version=false
399           Require server version to match client version
400
401
402       -n, --namespace=""
403           If present, the namespace scope for this CLI request
404
405
406       --request-timeout="0"
407           The  length  of  time  to  wait before giving up on a single server
408       request. Non-zero values should contain a corresponding time unit (e.g.
409       1s, 2m, 3h). A value of zero means don't timeout requests.
410
411
412       -s, --server=""
413           The address and port of the Kubernetes API server
414
415
416       --stderrthreshold=2
417           logs at or above this threshold go to stderr
418
419
420       --storage_driver_buffer_duration=0
421           Writes  in  the  storage driver will be buffered for this duration,
422       and committed to the non memory backends as a single transaction
423
424
425       --storage_driver_db="cadvisor"
426           database name
427
428
429       --storage_driver_host="localhost:8086"
430           database host:port
431
432
433       --storage_driver_password="root"
434           database password
435
436
437       --storage_driver_secure=false
438           use secure connection with database
439
440
441       --storage_driver_table="stats"
442           table name
443
444
445       --storage_driver_user="root"
446           database username
447
448
449       --token=""
450           Bearer token for authentication to the API server
451
452
453       --user=""
454           The name of the kubeconfig user to use
455
456
457       -v, --v=0
458           log level for V logs
459
460
461       --version=false
462           Print version information and quit
463
464
465       --vmodule=
466           comma-separated list of pattern=N settings for  file-filtered  log‐
467       ging
468
469
470

EXAMPLE

472                # Observe changes to services
473                oc observe services
474
475                # Observe changes to services, including the clusterIP and invoke a script for each
476                oc observe services -a '{ .spec.clusterIP }' -- register_dns.sh
477
478
479
480

SEE ALSO

482       oc(1),
483
484
485

HISTORY

487       June 2016, Ported from the Kubernetes man-doc generator
488
489
490
491Openshift                  Openshift CLI User Manuals                    OC(1)
Impressum