k8s config in use

To check which Kubernetes configuration is currently being used and which cluster it is pointing to, you can follow these steps:

1. Check the Active Context

The kubectl command-line tool uses a kubeconfig file to determine the configuration to use when interacting with a Kubernetes cluster. The active context in this file determines which cluster and user kubectl communicates with.

To see the currently active context, run:

   kubectl config current-context

This command will return the name of the context that is currently active.

2. Get Details of the Active Context

To get more details about the current context, such as the cluster and user it’s associated with, use the following command:

   kubectl config view --minify

The --minify flag restricts the output to only the active context, making it easier to see which cluster and user are currently being used.

3. Inspect the Full Kubeconfig File

If you want to see all contexts and clusters defined in your kubeconfig file, you can view the entire configuration with:

   kubectl config view

This will list all the clusters, contexts, and users defined in the kubeconfig file, along with the active context.

4. Check for Multiple Kubeconfig Files

Sometimes, multiple kubeconfig files are used. The KUBECONFIG environment variable can be set to a list of files, separated by colons. To check if multiple kubeconfig files are being used, you can run:

   echo $KUBECONFIG

If this variable is set, it will display the paths to all the kubeconfig files that are being used. If it’s not set, the default kubeconfig file located at ~/.kube/config is used.

5. Check Cluster Information

If you want to check more information about the cluster itself (like its server URL), you can use:

   kubectl cluster-info

This will provide you with details about the Kubernetes master and services running in your cluster.

Summary of Steps:

  1. kubectl config current-context – Check the active context.
  2. kubectl config view --minify – Get details of the active context.
  3. kubectl config view – View the entire kubeconfig file.
  4. echo $KUBECONFIG – Check if multiple kubeconfig files are used.
  5. kubectl cluster-info – Get information about the cluster.

These commands will help you determine which kubeconfig is being used and to which cluster it is pointing.