2.2.2. Accessing kubeconfig by using the oc CLI
You can use the oc CLI to log in to your OpenShift cluster and retrieve a kubeconfig file for accessing the cluster from the command line.
Prerequisites
- You have access to the OpenShift Container Platform web console or API server endpoint.
Procedure
Log in to your OpenShift cluster by running the following command:
$ oc login <api-server-url> -u <username> -p <password>1 2 3 - 1
- Specify the full API server URL. For example:
https://api.my-cluster.example.com:6443. - 2
- Specify a valid username. For example:
kubeadmin. - 3
- Provide the password for the specified user. For example, the
kubeadminpassword generated during cluster installation.
Save the cluster configuration to a local file by running the following command:
$ oc config view --raw > kubeconfigSet the
KUBECONFIGenvironment variable to point to the exported file by running the following command:$ export KUBECONFIG=./kubeconfigUse
octo interact with your OpenShift cluster by running the following command:$ oc get nodes
If you plan to reuse the exported kubeconfig file across sessions or machines, store it securely and avoid committing it to source control.