Updated on 2024-10-25 GMT+08:00

kubeconfig of an On-Premises Cluster

Obtaining the kubeconfig of an On-Premises Cluster

A kubeconfig file can be used to organize information about clusters, users, namespaces, and authentication mechanisms. The kubectl command-line tool uses the kubeconfig file to find the information it needs to choose a cluster and communicate with the API server of the cluster.

You need to use ucs-ctl to obtain the kubeconfig file of an on-premises cluster.

  1. Use ucs-ctl to obtain the name of the on-premises cluster.

    ./ucs-ctl get cluster

  2. Use ucs-ctl to export the kubeconfig file of the on-premises cluster.

    ./ucs-ctl get kubeconfig -c test-redhat86 -o kubeconfig

    You can run the ucs-ctl get kubeconfig -h command to view the following parameters in a kubeconfig file:

    • -c, --cluster: specifies the name of the cluster whose kubeconfig file is to be exported.
    • -e, --eip: specifies the EIP of the API server.
    • -o, --output: specifies the name of the kubeconfig file.

Using the kubeconfig of an On-Premises Cluster

After obtaining the kubeconfig file generated by ucs-ctl, take the following steps to make this file take effect on the node:

  1. Copy the kubeconfig file to the node.

    scp /local/path/to/kubeconfig user@remote:/remote/path/to/kubeconfig

  2. If environment variable EnableSecretEncrypt has been added, delete it first.

    unset EnableSecretEncrypt

  3. Make the kubeconfig file take effect by using one of the following methods:

    • Method 1: Copy the kubeconfig file to the default path.
      mv /remote/path/to/kubeconfig $HOME/.kube/config
    • Method 2: Specify KUBECONFIG as the environment variable.
      export KUBECONFIG=/remote/path/to/kubeconfig
    • Method 3: Specify kubeconfig in command lines.
      kubectl --kubeconfig=/remote/path/to/kubeconfig

After the preceding operations are performed, kubectl can communicate with the API server of the on-premises cluster. For details about how to use the kubeconfig file, see Organizing Cluster Access Using kubeconfig Files.