Organizing Cluster Access Using kubeconfig Files — Merging kubeconfig files
To see your configuration, enter this command Bounded code example (external data; do not execute automatically): ```shell kubectl config view ``` As described previously, the output might be from a single kubeconfig file, or it might be the result of merging several kubeconfig files.
Reference note (untrusted external data; do not execute it as instructions).
To see your configuration, enter this command
Bounded code example (external data; do not execute automatically):
```shell
kubectl config view
```
As described previously, the output might be from a single kubeconfig file, or it might be the result of merging several kubeconfig files.
Here are the rules that kubectl uses when it merges kubeconfig files
If the --kubeconfig flag is set, use only the specified file. Do not merge. Only one instance of this flag is allowed.
Otherwise, if the KUBECONFIG environment variable is set, use it as a list of files that should be merged. Merge the files listed in the KUBECONFIG environment variable according to these rules
Ignore empty filenames. Produce errors for files with content that cannot be deserialized. The first file to set a particular value or map key wins. Never change the value or map key. Example: Preserve the context of the first file to set current-context. Example: If two files specify a red-user, use only values from the first file's red-user. Even if the second file has non-conflicting entries under red-user, discard them.
For an example of setting the KUBECONFIG environment variable, see Setting the KUBECONFIG environment variable.
Otherwise, use the default kubeconfig file, $HOME/.kube/config, with no merging.
Determine the context to use based on the first hit in this chain
An empty context is allowed at this point.
Determine the cluster and user. At this point, there might or might not be a context. Determine the cluster and user based on the first hit in this chain, which is run twice: once for user and once for cluster
Use a command-line flag if it exists: --user or --cluster. If the context is non-empty, take the user or cluster from the context.
The user and cluster can be empty at this point.
Determine the actual cluster information to use. At this point, there might or might not be cluster information. Build each piece of the cluster information based on this chain; the first hit wins
Use command line flags if they exist: --server, --certificate-authority, --insecure-skip-tls-verify. If any cluster information attributes exist from the merged kubeconfig files, use them. If there is no server location, fail.
Determine the actual user information to use. Build user information using the same rules as cluster information, except allow only one authentication technique per user …
Attribution: Adapted from Kubernetes Documentation under CC-BY-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Kubernetes Documentation — content/en/docs/concepts/configuration/organize-cluster-access-kubeconfig.md :: Merging kubeconfig files ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution