Skip to content

Commit edac5db

Browse files
committed
Add kuberc dedicated page
1 parent a9f08fc commit edac5db

File tree

5 files changed

+171
-0
lines changed

5 files changed

+171
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
---
2+
title: Kubectl user preferences (kuberc)
3+
content_type: concept
4+
weight: 70
5+
---
6+
7+
{{< feature-state state="alpha" for_k8s_version="1.33" >}}
8+
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.
11+
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.
14+
15+
## aliases
16+
17+
Within a `kuberc` configuration, _aliases_ allow you to define custom shortcuts
18+
for kubectl commands, optionally with preset command line arguments.
19+
20+
### name
21+
22+
Alias name must not collide with the built-in commands.
23+
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:
34+
35+
```yaml
36+
apiVersion: kubectl.config.k8s.io/v1alpha1
37+
kind: Preference
38+
aliases:
39+
- name: getn
40+
command: get
41+
flags:
42+
- name: output
43+
default: json
44+
```
45+
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.
47+
48+
### prependArgs
49+
50+
Insert arbitrary arguments immediately after the kubectl command and its subcommand (if any).
51+
52+
#### Example:
53+
54+
```yaml
55+
apiVersion: kubectl.config.k8s.io/v1alpha1
56+
kind: Preference
57+
aliases:
58+
- name: getn
59+
command: get
60+
prependArgs:
61+
- namespace
62+
flags:
63+
- name: output
64+
default: json
65+
```
66+
67+
`kubectl getn test-ns` will be translated to `kubectl get namespace test-ns --output json`.
68+
69+
### appendArgs
70+
71+
Append arbitrary arguments to the end of the kubectl command.
72+
73+
#### Example:
74+
75+
```yaml
76+
apiVersion: kubectl.config.k8s.io/v1alpha1
77+
kind: Preference
78+
aliases:
79+
- name: runx
80+
command: run
81+
flags:
82+
- name: image
83+
default: busybox
84+
- name: namespace
85+
default: test-ns
86+
appendArgs:
87+
- --
88+
- custom-arg
89+
```
90+
91+
`kubectl runx test-pod` will be translated to `kubectl run test-pod --namespace test-ns --image busybox -- custom-arg`.
92+
93+
## Command Overrides
94+
95+
Within a `kuberc` configuration, _command overrides_ let you specify custom values for command line arguments.
96+
97+
### command
98+
99+
Specify the built-in command. This includes support for subcommands like `create role`.
100+
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 the value you defined in kuberc using `overrides`.
107+
108+
{{< note >}}
109+
You cannot use `kuberc` to override the value of a command line argument to take precedence over what the user specifies on the command line. The term `overrides`
110+
in this context refers to specifying a default value that is different from the
111+
compiled-in default value.
112+
{{< /note >}}
113+
114+
#### Example:
115+
116+
```yaml
117+
apiVersion: kubectl.config.k8s.io/v1alpha1
118+
kind: Preference
119+
overrides:
120+
- command: delete
121+
flags:
122+
- name: interactive
123+
default: "true"
124+
```
125+
126+
With this override, running `kubectl delete pod/test-pod` will default to prompting for confirmation.
127+
However, `kubectl delete pod/test-pod --interactive=false` will bypass the confirmation.
128+
129+
The kubectl maintainers encourage you to adopt kuberc with the given defaults:
130+
131+
```yaml
132+
apiVersion: kubectl.config.k8s.io/v1alpha1
133+
kind: Preference
134+
overrides:
135+
- command: apply
136+
flags:
137+
- name: server-side
138+
default: "true"
139+
- command: delete
140+
flags:
141+
- name: interactive
142+
default: "true"
143+
```
144+
145+
## Disable kuberc
146+
147+
To temporarily disable the kuberc functionality, simply export the environment variable `KUBERC` with the value `off`:
148+
149+
```shell
150+
export KUBERC=off
151+
```
152+
153+
or disable the feature gate:
154+
155+
```shell
156+
export KUBECTL_KUBERC=false
157+
```

content/en/docs/reference/kubectl/quick-reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ Verbosity | Description
506506

507507
* See [kubectl](/docs/reference/kubectl/kubectl/) options.
508508

509+
* See [kuberc](/docs/reference/kubectl/kuberc) options.
510+
509511
* Also read [kubectl Usage Conventions](/docs/reference/kubectl/conventions/) to understand how to use kubectl in reusable scripts.
510512

511513
* See more community [kubectl cheatsheets](https://github.com/dennyzhang/cheatsheet-kubernetes-A4).

content/en/docs/tasks/tools/install-kubectl-linux.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
309309
{{< tab name="Zsh" include="included/optional-kubectl-configs-zsh.md" />}}
310310
{{< /tabs >}}
311311
312+
### Configure kuberc
313+
314+
See [kuberc](/docs/reference/kubectl/kuberc) for more information.
315+
312316
### Install `kubectl convert` plugin
313317
314318
{{< include "included/kubectl-convert-overview.md" >}}

content/en/docs/tasks/tools/install-kubectl-macos.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
189189
{{< tab name="Zsh" include="included/optional-kubectl-configs-zsh.md" />}}
190190
{{< /tabs >}}
191191

192+
### Configure kuberc
193+
194+
See [kuberc](/docs/reference/kubectl/kuberc) for more information.
195+
192196
### Install `kubectl convert` plugin
193197

194198
{{< include "included/kubectl-convert-overview.md" >}}

content/en/docs/tasks/tools/install-kubectl-windows.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ Below are the procedures to set up autocompletion for PowerShell.
163163

164164
{{< include "included/optional-kubectl-configs-pwsh.md" >}}
165165

166+
### Configure kuberc
167+
168+
See [kuberc](/docs/reference/kubectl/kuberc) for more information.
169+
166170
### Install `kubectl convert` plugin
167171

168172
{{< include "included/kubectl-convert-overview.md" >}}

0 commit comments

Comments
 (0)