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
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.
11
12
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.
14
16
15
-
## aliases
17
+
Currently, this file allows you to define two types of user preferences:
16
18
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.
19
23
20
-
### name
24
+
##Aliases
21
25
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.
23
29
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`.
34
32
35
33
```yaml
36
-
apiVersion: kubectl.config.k8s.io/v1alpha1
34
+
apiVersion: kubectl.config.k8s.io/v1beta1
37
35
kind: Preference
38
36
aliases:
39
37
- name: getn
40
38
command: get
41
-
flags:
39
+
options:
42
40
- name: output
43
41
default: json
44
42
```
45
43
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`.
47
52
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.
49
55
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/).
51
57
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).
53
61
54
62
```yaml
55
-
apiVersion: kubectl.config.k8s.io/v1alpha1
63
+
apiVersion: kubectl.config.k8s.io/v1beta1
56
64
kind: Preference
57
65
aliases:
58
66
- name: getn
59
67
command: get
60
-
prependArgs:
61
-
- namespace
62
-
flags:
68
+
options:
63
69
- name: output
64
70
default: json
71
+
prependArgs:
72
+
- namespace
65
73
```
66
74
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:
68
76
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`.
70
85
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.
74
88
75
89
```yaml
76
-
apiVersion: kubectl.config.k8s.io/v1alpha1
90
+
apiVersion: kubectl.config.k8s.io/v1beta1
77
91
kind: Preference
78
92
aliases:
79
93
- name: runx
80
94
command: run
81
-
flags:
95
+
options:
82
96
- name: image
83
97
default: busybox
84
98
- name: namespace
@@ -88,65 +102,76 @@ aliases:
88
102
- custom-arg
89
103
```
90
104
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:
94
106
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`.
96
115
97
-
### command
116
+
## Defaults
98
117
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.
100
120
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:
117
123
118
124
```yaml
119
-
apiVersion: kubectl.config.k8s.io/v1alpha1
125
+
apiVersion: kubectl.config.k8s.io/v1beta1
120
126
kind: Preference
121
-
overrides:
127
+
defaults:
122
128
- command: delete
123
-
flags:
129
+
options:
124
130
- name: interactive
125
131
default: "true"
126
132
```
127
133
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.
129
142
However, `kubectl delete pod/test-pod --interactive=false` will bypass the confirmation.
130
143
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:
132
147
133
148
```yaml
134
-
apiVersion: kubectl.config.k8s.io/v1alpha1
149
+
apiVersion: kubectl.config.k8s.io/v1beta1
135
150
kind: Preference
136
-
overrides:
151
+
defaults:
152
+
# (1) default server-side apply
137
153
- command: apply
138
-
flags:
154
+
options:
139
155
- name: server-side
140
156
default: "true"
157
+
158
+
# (2) default interactive deletion
141
159
- command: delete
142
-
flags:
160
+
options:
143
161
- name: interactive
144
162
default: "true"
145
163
```
146
164
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
+
147
171
## Disable kuberc
148
172
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
0 commit comments