From d91ec003800ea4c5617fd62838ea46597d8c7514 Mon Sep 17 00:00:00 2001 From: subhtk Date: Wed, 25 Jun 2025 21:11:34 +0530 Subject: [PATCH] Added acessing to kubeconfig using oc CLI --- .../openshift_cli/configuring-cli.adoc | 3 ++ .../cli-configuring-kubeconfig-using-cli.adoc | 52 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 modules/cli-configuring-kubeconfig-using-cli.adoc diff --git a/cli_reference/openshift_cli/configuring-cli.adoc b/cli_reference/openshift_cli/configuring-cli.adoc index 7b91e26c25..1ff8e0ba60 100644 --- a/cli_reference/openshift_cli/configuring-cli.adoc +++ b/cli_reference/openshift_cli/configuring-cli.adoc @@ -16,3 +16,6 @@ include::modules/cli-configuring-completion.adoc[leveloffset=+2] // Enabling tab completion for Zsh include::modules/cli-configuring-completion-zsh.adoc[leveloffset=+2] + +// Configuring a kubeconfig file by using the oc CLI +include::modules/cli-configuring-kubeconfig-using-cli.adoc[leveloffset=+1] diff --git a/modules/cli-configuring-kubeconfig-using-cli.adoc b/modules/cli-configuring-kubeconfig-using-cli.adoc new file mode 100644 index 0000000000..e1fd4c465b --- /dev/null +++ b/modules/cli-configuring-kubeconfig-using-cli.adoc @@ -0,0 +1,52 @@ +// Module included in the following assemblies: +// +// * cli_reference/openshift_cli/configuring-cli.adoc + +:_mod-docs-content-type: PROCEDURE +[id="cli-accessing-kubeconfig-using-cli_{context}"] += 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 {product-title} web console or API server endpoint. + +.Procedure + +. Log in to your OpenShift cluster by running the following command: ++ +[source,terminal] +---- +$ oc login -u -p <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 `kubeadmin` password generated during cluster installation. + +. Save the cluster configuration to a local file by running the following command: ++ +[source,terminal] +---- +$ oc config view --raw > kubeconfig +---- + +. Set the `KUBECONFIG` environment variable to point to the exported file by running the following command: ++ +[source,terminal] +---- +$ export KUBECONFIG=./kubeconfig +---- + +. Use `oc` to interact with your OpenShift cluster by running the following command: ++ +[source,terminal] +---- +$ oc get nodes +---- + +[NOTE] +==== +If you plan to reuse the exported `kubeconfig` file across sessions or machines, store it securely and avoid committing it to source control. +==== \ No newline at end of file