File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
cli_reference/openshift_cli Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -16,3 +16,10 @@ include::modules/cli-configuring-completion.adoc[leveloffset=+2]
16
16
17
17
// Enabling tab completion for Zsh
18
18
include::modules/cli-configuring-completion-zsh.adoc[leveloffset=+2]
19
+
20
+ [id="cli-configuring-kubeconfig_{context}"]
21
+ == Configuring a kubeconfig file by using the oc CLI
22
+
23
+ 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`.
24
+
25
+ include::modules/cli-configuring-kubeconfig-using-cli.adoc[leveloffset=+2]
Original file line number Diff line number Diff line change
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` 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>
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
+ ====
You can’t perform that action at this time.
0 commit comments