Skip to content

Commit 3c60431

Browse files
committed
Promote kuberc to beta
Signed-off-by: Maciej Szulik <[email protected]>
1 parent 81beed7 commit 3c60431

File tree

1 file changed

+94
-69
lines changed

1 file changed

+94
-69
lines changed

content/en/docs/reference/kubectl/kuberc.md

Lines changed: 94 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,81 +4,95 @@ content_type: concept
44
weight: 70
55
---
66

7-
{{< feature-state state="alpha" for_k8s_version="1.33" >}}
7+
{{< feature-state state="beta" for_k8s_version="1.34" >}}
88

9-
A Kubernetes `kuberc` configuration file allows you to define preferences for kubectl, such as default options and command aliases.
10-
Unlike the kubeconfig file, a `kuberc` configuration file does **not** contain cluster details, usernames or passwords.
9+
A Kubernetes `kuberc` configuration file allows you to define preferences for kubectl,
10+
such as default options and command aliases. Unlike the kubeconfig file, a `kuberc`
11+
configuration file does **not** contain cluster details, usernames or passwords.
1112

12-
The default location of this configuration file is `$HOME/.kube/kuberc`.
13-
You can instruct `kubectl` to look at a custom path for this configuration using the `--kuberc` command line argument.
13+
The default location of this configuration file is `$HOME/.kube/kuberc`.
14+
You can instruct `kubectl` to look at a custom path for this configuration using
15+
the `--kuberc` command line argument.
1416

15-
## aliases
17+
Currently, this file allows you to define two types of user preferences:
1618

17-
Within a `kuberc` configuration, _aliases_ allow you to define custom shortcuts
18-
for kubectl commands, optionally with preset command line arguments.
19+
1. [Aliases](#aliases) - allow you to create shorter versions of your favorite
20+
commands, optionally setting options and arguments.
21+
2. [Defaults](#defaults) - allow you to configure default option values for your
22+
favorite commands.
1923

20-
### name
24+
## Aliases
2125

22-
Alias name must not collide with the built-in commands.
26+
Within a `kuberc` configuration, _aliases_ section allows you to define custom
27+
shortcuts for kubectl commands, optionally with preset command line arguments
28+
and flags.
2329

24-
### command
25-
26-
Specify the underlying built-in command that your alias will execute. This includes support for subcommands like `create role`.
27-
28-
### flags
29-
30-
Specify default values for command line arguments (which the kuberc format terms _flags_).
31-
If you explicitly specify a command line argument when you run kubectl, the value you provide takes precedence over the default one defined in kuberc.
32-
33-
#### Example {#flags-example}
30+
This next example defines `kubectl getn` alias for `kubectl get` command, additionally
31+
setting output flag `--output=json`.
3432

3533
```yaml
36-
apiVersion: kubectl.config.k8s.io/v1alpha1
34+
apiVersion: kubectl.config.k8s.io/v1beta1
3735
kind: Preference
3836
aliases:
3937
- name: getn
4038
command: get
41-
flags:
39+
options:
4240
- name: output
4341
default: json
4442
```
4543
46-
With this alias, running `kubectl getn pods` will default JSON output. However, if you execute `kubectl getn pods -oyaml`, the output will be in YAML format.
44+
In this example, the following settings were used:
45+
46+
1. `name` - Alias name must not collide with the built-in commands.
47+
1. `command` - Specify the underlying built-in command that your alias will execute.
48+
This includes support for subcommands like `create role`.
49+
1. `options` - Specify default values for options. If you explicitly specify an option
50+
when you run `kubectl`, the value you provide takes precedence over the default
51+
one defined in `kuberc`.
4752

48-
### prependArgs
53+
With this alias, running `kubectl getn pods` will default JSON output. However,
54+
if you execute `kubectl getn pods -oyaml`, the output will be in YAML format.
4955

50-
Insert arbitrary arguments immediately after the kubectl command and its subcommand (if any).
56+
Full `kuberc` schema is available [here](/docs/reference/config-api/kubelet-config.v1beta1/).
5157

52-
#### Example {#prependArgs-example}
58+
This next example, will expand the previous one, introducing `prependArgs` section,
59+
which allows inserting arbitrary arguments immediately after the kubectl command
60+
and its subcommand (if any).
5361

5462
```yaml
55-
apiVersion: kubectl.config.k8s.io/v1alpha1
63+
apiVersion: kubectl.config.k8s.io/v1beta1
5664
kind: Preference
5765
aliases:
5866
- name: getn
5967
command: get
60-
prependArgs:
61-
- namespace
62-
flags:
68+
options:
6369
- name: output
6470
default: json
71+
prependArgs:
72+
- namespace
6573
```
6674

67-
`kubectl getn test-ns` will be translated to `kubectl get namespace test-ns --output json`.
75+
In this example, the following settings were used:
6876

69-
### appendArgs
77+
1. `name` - Alias name must not collide with the built-in commands.
78+
1. `command` - Specify the underlying built-in command that your alias will execute.
79+
This includes support for subcommands like `create role`.
80+
1. `options` - Specify default values for options. If you explicitly specify an option
81+
when you run `kubectl`, the value you provide takes precedence over the default
82+
one defined in `kuberc`.
83+
1. `prependArgs` - Specify explicit argument that will be placed right after the
84+
command. Here, this will be translated to `kubectl get namespace test-ns --output json`.
7085

71-
Append arbitrary arguments to the end of the kubectl command.
72-
73-
#### Example {#appendArgs-example}
86+
This next example, will introduce a mechanism similar to prepending arguments,
87+
this time, though, we will append arguments to the end of the kubectl command.
7488

7589
```yaml
76-
apiVersion: kubectl.config.k8s.io/v1alpha1
90+
apiVersion: kubectl.config.k8s.io/v1beta1
7791
kind: Preference
7892
aliases:
7993
- name: runx
8094
command: run
81-
flags:
95+
options:
8296
- name: image
8397
default: busybox
8498
- name: namespace
@@ -88,65 +102,76 @@ aliases:
88102
- custom-arg
89103
```
90104

91-
`kubectl runx test-pod` will be translated to `kubectl run test-pod --namespace test-ns --image busybox -- custom-arg`.
92-
93-
## Command overrides
105+
In this example, the following settings were used:
94106

95-
Within a `kuberc` configuration, _command overrides_ let you specify custom values for command line arguments.
107+
1. `name` - Alias name must not collide with the built-in commands.
108+
1. `command` - Specify the underlying built-in command that your alias will execute.
109+
This includes support for subcommands like `create role`.
110+
1. `options` - Specify default values for options. If you explicitly specify an option
111+
when you run `kubectl`, the value you provide takes precedence over the default
112+
one defined in `kuberc`.
113+
1. `appendArgs` - Specify explicit arguments that will be placed at the end of the
114+
command. Here, this will be translated to `kubectl run test-pod --namespace test-ns --image busybox -- custom-arg`.
96115

97-
### command
116+
## Defaults
98117

99-
Specify the built-in command. This includes support for subcommands like `create role`.
118+
Within a `kuberc` configuration, `defaults` section lets you specify default values
119+
for command line arguments.
100120

101-
### flags
102-
103-
Within a `kuberc`, configuration, command line arguments are termed _flags_ (even if they do not represent a boolean type).
104-
You can use `flags` to set the default value of a command line argument.
105-
106-
If you explicitly specify a flag on your terminal, explicit value will always take precedence over
107-
the value you defined in kuberc using `overrides`.
108-
109-
{{< note >}}
110-
You cannot use `kuberc` to override the value of a command line argument to take precedence over
111-
what the user specifies on the command line. The term `overrides`
112-
in this context refers to specifying a default value that is different from the
113-
compiled-in default value.
114-
{{< /note >}}
115-
116-
#### Example
121+
This next example makes the interactive removal the default mode for invoking
122+
`kubectl delete` command:
117123

118124
```yaml
119-
apiVersion: kubectl.config.k8s.io/v1alpha1
125+
apiVersion: kubectl.config.k8s.io/v1beta1
120126
kind: Preference
121-
overrides:
127+
defaults:
122128
- command: delete
123-
flags:
129+
options:
124130
- name: interactive
125131
default: "true"
126132
```
127133

128-
With this override, running `kubectl delete pod/test-pod` will default to prompting for confirmation.
134+
In this example, the following settings were used:
135+
136+
1. `command` - Built-in command, this includes support for subcommands like `create role`.
137+
1. `options` - Specify default values for options. If you explicitly specify an option
138+
when you run `kubectl`, the value you provide takes precedence over the default
139+
one defined in `kuberc`.
140+
141+
With this setting, running `kubectl delete pod/test-pod` will default to prompting for confirmation.
129142
However, `kubectl delete pod/test-pod --interactive=false` will bypass the confirmation.
130143

131-
The kubectl maintainers encourage you to adopt kuberc with the given defaults:
144+
## Suggested defaults
145+
146+
The kubectl maintainers encourage you to adopt kuberc with the following defaults:
132147

133148
```yaml
134-
apiVersion: kubectl.config.k8s.io/v1alpha1
149+
apiVersion: kubectl.config.k8s.io/v1beta1
135150
kind: Preference
136-
overrides:
151+
defaults:
152+
# (1) default server-side apply
137153
- command: apply
138-
flags:
154+
options:
139155
- name: server-side
140156
default: "true"
157+
158+
# (2) default interactive deletion
141159
- command: delete
142-
flags:
160+
options:
143161
- name: interactive
144162
default: "true"
145163
```
146164

165+
In this example, the following settings are enforced:
166+
1. Defaults to using [Server-Side Apply](/docs/reference/using-api/server-side-apply/).
167+
1. Defaults to interactive removal whenever invoking `kubectl delete` to prevent
168+
accidental removal of resources from the cluster.
169+
170+
147171
## Disable kuberc
148172

149-
To temporarily disable the kuberc functionality, simply export the environment variable `KUBERC` with the value `off`:
173+
To temporarily disable the kuberc functionality, simply export the environment
174+
variable `KUBERC` with the value `off`:
150175

151176
```shell
152177
export KUBERC=off

0 commit comments

Comments
 (0)