Configuring the OpenShift CLI
Enabling tab completion
You can enable tab completion for the Bash or Zsh shells.
Enabling tab completion for Bash
After you install the OpenShift CLI (oc), you can enable tab completion to automatically complete oc commands or suggest options when you press Tab. The following procedure enables tab completion for the Bash shell.
-
You must have the OpenShift CLI (
oc) installed. -
You must have the package
bash-completioninstalled.
-
Save the Bash completion code to a file:
$ oc completion bash > oc_bash_completion -
Copy the file to
/etc/bash_completion.d/:$ sudo cp oc_bash_completion /etc/bash_completion.d/You can also save the file to a local directory and source it from your
.bashrcfile instead. Tab completion is enabled when you open a new terminal.
Enabling tab completion for Zsh
After you install the OpenShift CLI (oc), you can enable tab completion to automatically complete oc commands or suggest options when you press Tab. The following procedure enables tab completion for the Zsh shell.
-
You must have the OpenShift CLI (
oc) installed.
-
To add tab completion for
octo your.zshrcfile, run the following command:$ cat >>~/.zshrc<<EOF autoload -Uz compinit compinit if [ $commands[oc] ]; then source <(oc completion zsh) compdef _oc oc fi EOFTab completion is enabled when you open a new terminal.
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.
-
You have access to the OpenShift Container Platform web console or API server endpoint.
-
Log in to your OpenShift cluster by running the following command:
$ oc login <api-server-url> -u <username> -p <password>- Specify the full API server URL. For example:
https://api.my-cluster.example.com:6443. - Specify a valid username. For example:
kubeadmin. - Provide the password for the specified user. For example, the
kubeadminpassword generated during cluster installation.
- Specify the full API server URL. For example:
-
Save the cluster configuration to a local file by running the following command:
$ oc config view --raw > kubeconfig -
Set the
KUBECONFIGenvironment variable to point to the exported file by running the following command:$ export KUBECONFIG=./kubeconfig -
Use
octo interact with your OpenShift cluster by running the following command:$ 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.