Skip to content

Commit aae6e60

Browse files
committed
Added acessing to kubeconfig using oc CLI
1 parent c13644c commit aae6e60

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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ 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+
[id="cli-configuring-kubeconfig_{context}"]
21+
== Accessing kubeconfig using the oc CLI
22+
23+
include::modules/cli-configuring-kubeconfig-using-cli.adoc[leveloffset=+2]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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` using the `oc` CLI
8+
9+
You can use the `oc` Command-Line Interface (CLI) to retrieve and configure a `kubeconfig` file for accessing your OpenShift 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>
22+
----
23+
+
24+
<1> Replace `<api-server-url>` with the full API server URL, such as `https://api.my-cluster.example.com:6443`.
25+
26+
. Save the cluster configuration to a local file by running the following command:
27+
+
28+
[source,terminal]
29+
----
30+
$ oc config view --raw > kubeconfig
31+
----
32+
33+
. Set the `KUBECONFIG` environment variable to point to the exported file by running the following command:
34+
+
35+
[source,terminal]
36+
----
37+
$ export KUBECONFIG=./kubeconfig
38+
----
39+
40+
. You can now use `kubectl` to interact with your OpenShift cluster by running the following command:
41+
+
42+
[source,terminal]
43+
----
44+
$ kubectl get nodes
45+
----
46+
47+
[NOTE]
48+
====
49+
If you plan to reuse the exported `kubeconfig` file across sessions or machines, store it securely and avoid committing it to source control.
50+
====

0 commit comments

Comments
 (0)