Skip to content

OCPBUGS-54613: Added acessing to kubeconfig using oc CLI module #95219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cli_reference/openshift_cli/configuring-cli.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ include::modules/cli-configuring-completion.adoc[leveloffset=+2]

// Enabling tab completion for Zsh
include::modules/cli-configuring-completion-zsh.adoc[leveloffset=+2]

[id="cli-configuring-kubeconfig_{context}"]
== Configuring a kubeconfig file by using the oc CLI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
== Configuring a kubeconfig file by using the oc CLI
== Retrieving and managing `kubeconfig` data by using the openshift client i.e. `oc`

or

Suggested change
== Configuring a kubeconfig file by using the oc CLI
Generating a kubeconfig file by logging in with the oc CLI

Could you re-word it (similar to the suggestion) as we do not configure the kubeconfig file?


You can use the `oc` Command-Line Interface (CLI) to log in to your OpenShift cluster and retrieve the `kubeconfig` file. The `kubeconfig` file contains the configuration information required to interact with the cluster using CLI tools such as `kubectl` or `oc`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can use the `oc` Command-Line Interface (CLI) to log in to your OpenShift cluster and retrieve the `kubeconfig` file. The `kubeconfig` file contains the configuration information required to interact with the cluster using CLI tools such as `kubectl` or `oc`.
You can use the oc command-line interface (CLI) to log in to your OpenShift cluster and generate or update a kubeconfig file. This file contains the configuration details—such as cluster, user credentials, and context—required to interact with the cluster using CLI tools like oc or kubectl.


include::modules/cli-configuring-kubeconfig-using-cli.adoc[leveloffset=+2]
50 changes: 50 additions & 0 deletions modules/cli-configuring-kubeconfig-using-cli.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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` 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Use the `oc` command-line interface (CLI) to log in to your OpenShift cluster and generate a `kubeconfig` file. This file enables command-line access to the cluster with tools such as `oc` or `kubectl`.


.Prerequisites

* You have access to the {product-title} web console or API server endpoint.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* You have access to the {product-title} web console or API server endpoint.
* You have a valid user credentials to access 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 <api-server-url> -u <username> -p <password> <1>
----
+
<1> Replace `<api-server-url>` with the full API server URL, such as `https://api.my-cluster.example.com:6443`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also mention/give an example of <username> and <password> as well?


. Save the cluster configuration to a local file by running the following command:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think by running the following command need not be repeated on all the steps

Suggested change
. Save the cluster configuration to a local file by running the following command:
. Save the cluster configuration to a local file

+
[source,terminal]
----
$ oc config view --raw > kubeconfig
----

. Set the `KUBECONFIG` environment variable to point to the exported file by running the following command:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
. Set the `KUBECONFIG` environment variable to point to the exported file by running the following command:
. Set the `KUBECONFIG` environment variable to point to the exported file

+
[source,terminal]
----
$ export KUBECONFIG=./kubeconfig
----

. You can now use `kubectl` to interact with your OpenShift cluster by running the following command:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
. You can now use `kubectl` to interact with your OpenShift cluster by running the following command:
. You can now use `kubectl` or `oc` to interact with your OpenShift cluster

+
[source,terminal]
----
$ kubectl 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.
====