Kubectl user preferences (kuberc) [page]deterministic
A Kubernetes `kuberc` configuration file allows you to define preferences for [kubectl](#gloss:kubectl), such as default options and command aliases. Unlike the kubeconfig file, a `kuberc` configuration file does not contain cluster details, usernames or passwords.
On Linux / POSIX computers, the default location of this configuration file is `$HOME/.kube/kuberc`. The default path on Windows is similar: `%USERPROFILE%\.kube\kuberc`. To provide kubectl with a path to a custom kuberc file, use the `--kuberc` command line option, or set the `KUBERC` environment variable.
A `kuberc` using the `kubectl.config.k8s.io/v1beta1` format allows you to define the following types of user preferences:
1. [Aliases](#aliases) - allow you to create shorter versions of your favorite commands, optionally setting options and arguments. 2. [Defaults](#defaults) - allow you to configure default option values for your favorite commands. 3. [Credential Plugin Policy](#credential-plugin-policy) - allow you to configure a policy for exec credential plugins.
## aliases
Within a `kuberc` configuration, the _aliases_ section allows you to define custom shortcuts for kubectl commands, optionally with preset command line arguments and flags.
This next example defines a `kubectl getn` alias for the `kubectl get` subcommand, additionally specifying JSON output format: `--output=json`.
```yaml apiVersion: kubectl.config.k8s.io/v1beta1 kind: Preference aliases: - name: getn command: get options: - name: output default: json ```
In this example, the following settings were used:
1. `name` - Alias name must not collide with the built-in commands. 1. `command` - Specify the underlying built-in command that your alias will execute. This includes support for subcommands like `create role`. 1. `options` - Specify default values for options. If you explicitly specify an option when you run `kubectl`, the value you provide takes precedence over the default one defined in `kuberc`.
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.
Full `kuberc` schema is available [here](/docs/reference/config-api/kuberc.v1beta1/).
### prependArgs
This next example, will expand the previous one, introducing `prependArgs` section, which allows inserting arbitrary arguments immediately after the kubectl command and its subcommand (if any).
```yaml apiVersion: kubectl.config.k8s.io/v1beta1 kind: Preference aliases: - name: getn command: get options: - name: output default: json prependArgs: - namespace ```
In this example, the following settings were used:
1. `name` - Alias name must not collide with the built-in commands. 1. `command` - Specify the underlying built-in command that your alias will execute. This includes support for subcommands like `create role`. 1. `options` - Specify default values for options. If you explicitly specify an option when you run `kubectl`, the value you provide takes precedence over the default one defined in `kuberc`. 1. `prependArgs` - Specify explicit argument that will be placed right after the command. Here, this will be translated to `kubectl get namespace test-ns --output json`.
### appendArgs
This next example, will introduce a mechanism similar to prepending arguments, this time, though, we will append arguments to the end of the kubectl command.
```yaml apiVersion: kubectl.config.k8s.io/v1beta1 kind: Preference aliases: - name: runx command: run options: - name: image default: busybox - name: namespace default: test-ns appendArgs: - -- - custom-arg ```
In this example, the following settings were used:
1. `name` - Alias name must not collide with the built-in commands. 1. `command` - Specify the underlying built-in command that your alias will execute. This includes support for subcommands like `create r …(trimmed)