A kubeconfig file tells kubectl which cluster endpoint, user credentials, namespace, and context name to use for Kubernetes API requests. Keeping a received kubeconfig in its own file fits temporary or team-specific access from a cluster administrator or managed service without overwriting $HOME/.kube/config.

kubectl reads $HOME/.kube/config by default, but the KUBECONFIG environment variable or the --kubeconfig flag can point it at another file. A session-scoped KUBECONFIG value keeps the change limited to the active shell until the file and context have been checked.

A kubeconfig can contain credential material and can also reference external authentication commands. Use files only from a trusted cluster owner, restrict local permissions, select the intended context, and run a harmless read command before using the context for changes.

Steps to configure kubectl with a kubeconfig file:

  1. Create the kubectl config directory if it is missing.
    $ mkdir -p ~/.kube
  2. Copy the received kubeconfig into a named file.
    $ cp ~/Downloads/team-a.kubeconfig ~/.kube/team-a.kubeconfig

    Use a descriptive filename for each cluster or team so shell history and error messages show which access file is active.

  3. Restrict the kubeconfig file permissions.
    $ chmod 600 ~/.kube/team-a.kubeconfig

    A kubeconfig can include bearer tokens, client certificates, or exec-plugin settings. Do not use a file from an untrusted source.

  4. Point the current shell at the saved kubeconfig file.
    $ export KUBECONFIG=$HOME/.kube/team-a.kubeconfig

    The export applies only to the current shell and child processes. Use --kubeconfig for one command when a shell-wide override is not needed.

  5. List the contexts in the selected kubeconfig.
    $ kubectl config get-contexts -o name
    team-a-admin@team-a
  6. Select the intended context.
    $ kubectl config use-context team-a-admin@team-a
    Switched to context "team-a-admin@team-a".

    Use the exact context name listed by kubectl config get-contexts. This writes the current-context field in the selected kubeconfig file, not in $HOME/.kube/config.

  7. Confirm the active context.
    $ kubectl config current-context
    team-a-admin@team-a
  8. Verify read-only access through the configured file.
    $ kubectl get namespace default
    NAME      STATUS   AGE
    default   Active   71s

    If the cluster grants only namespace-scoped access, replace default with the namespace named by the cluster owner.