Skip to content

Commit 99ae696

Browse files
Merge pull request #97057 from openshift-cherrypick-robot/cherry-pick-95219-to-enterprise-4.19
[enterprise-4.19] : Added acessing to kubeconfig using oc CLI module
2 parents 318c431 + e6f33fa commit 99ae696

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

cli_reference/openshift_cli/configuring-cli.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ include::modules/cli-configuring-completion.adoc[leveloffset=+2]
1616

1717
// Enabling tab completion for Zsh
1818
include::modules/cli-configuring-completion-zsh.adoc[leveloffset=+2]
19+
20+
// Configuring a kubeconfig file by using the oc CLI
21+
include::modules/cli-configuring-kubeconfig-using-cli.adoc[leveloffset=+1]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * cli_reference/openshift_cli/configuring-cli.adoc
4+
5+
:_mod-docs-content-type: PROCEDURE
6+
[id="cli-accessing-kubeconfig-using-cli_{context}"]
7+
= Accessing kubeconfig by using the oc CLI
8+
9+
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.
10+
11+
.Prerequisites
12+
13+
* You have access to the {product-title} web console or API server endpoint.
14+
15+
.Procedure
16+
17+
. Log in to your OpenShift cluster by running the following command:
18+
+
19+
[source,terminal]
20+
----
21+
$ oc login <api-server-url> -u <username> -p <password> <1><2><3>
22+
----
23+
+
24+
<1> Specify the full API server URL. For example: `https://api.my-cluster.example.com:6443`.
25+
<2> Specify a valid username. For example: `kubeadmin`.
26+
<3> Provide the password for the specified user. For example, the `kubeadmin` password generated during cluster installation.
27+
28+
. Save the cluster configuration to a local file by running the following command:
29+
+
30+
[source,terminal]
31+
----
32+
$ oc config view --raw > kubeconfig
33+
----
34+
35+
. Set the `KUBECONFIG` environment variable to point to the exported file by running the following command:
36+
+
37+
[source,terminal]
38+
----
39+
$ export KUBECONFIG=./kubeconfig
40+
----
41+
42+
. Use `oc` to interact with your OpenShift cluster by running the following command:
43+
+
44+
[source,terminal]
45+
----
46+
$ oc get nodes
47+
----
48+
49+
[NOTE]
50+
====
51+
If you plan to reuse the exported `kubeconfig` file across sessions or machines, store it securely and avoid committing it to source control.
52+
====

0 commit comments

Comments
 (0)