You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting with Kubernetes 1.11, kubectl uses server-side printing. The server decides which
354
+
columns are shown by the `kubectl get` command. You can customize these columns using a
355
+
CustomResourceDefinition. The following example adds the `Spec`, `Replicas`, and `Age`
356
+
columns.
357
+
358
+
1. Save the CustomResourceDefinition to `resourcedefinition.yaml`.
359
+
```yaml
360
+
apiVersion: apiextensions.k8s.io/v1beta1
361
+
kind: CustomResourceDefinition
362
+
metadata:
363
+
name: crontabs.stable.example.com
364
+
spec:
365
+
group: stable.example.com
366
+
version: v1
367
+
scope: Namespaced
368
+
names:
369
+
plural: crontabs
370
+
singular: crontab
371
+
kind: CronTab
372
+
shortNames:
373
+
- ct
374
+
additionalPrinterColumns:
375
+
- name: Spec
376
+
type: string
377
+
description: The cron spec defining the interval a CronJob is run
378
+
JSONPath: .spec.cronSpec
379
+
- name: Replicas
380
+
type: integer
381
+
description: The number of jobs launched by the CronJob
382
+
JSONPath: .spec.replicas
383
+
- name: Age
384
+
type: date
385
+
JSONPath: .metadata.creationTimestamp
386
+
```
387
+
388
+
2. Create the CustomResourceDefinition:
389
+
390
+
```shell
391
+
kubectl create -f resourcedefinition.yaml
392
+
```
393
+
394
+
3. Create an instance using the `my-crontab.yaml` from the previous section.
395
+
396
+
4. Invoke the server-side printing:
397
+
398
+
```shell
399
+
kubectl get crontab my-new-cron-object
400
+
```
401
+
402
+
Notice the `NAME`, `SPEC`, `REPLICAS`, and `AGE` columns in the output:
403
+
404
+
```
405
+
NAME SPEC REPLICAS AGE
406
+
my-new-cron-object * * * * * 1 7s
407
+
```
408
+
409
+
The `NAME` column is implicit and does not need to be defined in the CustomResourceDefinition.
410
+
411
+
#### Priority
412
+
413
+
Each column includes a `priority` field for each column. Currently, the priority
414
+
differentiates between columns shown in standard view or wide view (using the `-o wide` flag).
415
+
416
+
- Columns with priority `0` are shown in standard view.
417
+
- Columns with priority greater than `0` are shown only in wide view.
418
+
419
+
#### Type
420
+
421
+
A column's `type` field can be any of the following (compare [OpenAPI v3 data types](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#dataTypes)):
422
+
423
+
- `integer`– non-floating-point numbers
424
+
- `number`– floating point numbers
425
+
- `string`– strings
426
+
- `boolean`– true or false
427
+
- `date`– rendered differentially as time since this timestamp.
428
+
429
+
If the value inside a CustomResource does not match the type specified for the column,
430
+
the value is omitted. Use CustomResource validation to ensure that the value
431
+
types are correct.
432
+
433
+
#### Format
434
+
435
+
A column's `format` field can be any of the following:
436
+
437
+
- `int32`
438
+
- `int64`
439
+
- `float`
440
+
- `double`
441
+
- `byte`
442
+
- `date`
443
+
- `date-time`
444
+
- `password`
445
+
446
+
The column's `format` controls the style used when `kubectl` prints the value.
447
+
349
448
### Subresources
350
449
351
450
Custom resources support `/status` and `/scale` subresources.
0 commit comments