Using Cloud Shell
Getting Started with Cloud Shell
You can access Cloud Shell in two ways:
- Via the OCI Console
- Via the 'Try It' button that appears on many command line and code samples throughout the documentation
To access Cloud Shell via the Console:
- Login to the Console.
- Click the Cloud Shell icon in the Console header. Note that the OCI CLI running in the Cloud Shell will execute commands against the region selected in the Console's Region selection menu when the Cloud Shell was started.
This displays the Cloud Shell in a "drawer" at the bottom of the console:
You can use the icons in the upper right corner of the Cloud Shell window to minimize, maximize, restart, and close your Cloud Shell session.
For clipboard operations, Windows users can use Ctrl-C or Ctrl-Insert to copy, and Shift-Insert or Ctrl-V to paste. For Mac OS users, use Cmd-C to copy and Cmd-V to paste.
To access Cloud Shell via the Try It button:
Many code and command samples in the OCI documentation include a Try It button. This button will copy the sample to the clipboard and open a Cloud Shell session so you can try out the sample.
Your Cloud Shell comes with the OCI CLI pre-authenticated, so there’s no setup required before you can start using it.
Try it with the following commands:
oci os ns get
oci iam compartment list
Interact with an OKE cluster from Cloud Shell
Follow the instructions in Setting Up Cloud Shell Access to Clusters to:
- Set up an OKE kubeconfig file for use with Cloud Shell:
- Select a cluster.
- Click the Access Cluster button.
- Click Cloud Shell Access.
- Click Launch Cloud Shell to display the Cloud Shell window.
In the Cloud Shell window, run the Oracle Cloud Infrastructure CLI command to set up the kubeconfig file and save it in a location accessible to kubectl. For example:
$ oci ce cluster create-kubeconfig --cluster-id ocid1.cluster.oc1.phx.aaaaaaaaae... --file $HOME/.kube/config --region us-phoenix-1 --token-version 2.0.0
-
Verify that kubectl is available and can connect to the cluster from the Cloud Shell window by entering the following command in the Cloud Shell window:
$ kubectl get nodes
Things To Try
Using the OCI CLI
Customizing the Cloud Shell OCI CLI Configuration
Cloud Shell comes with a pre-authenticated OCI CLI, which is refreshed and provisioned for your user when you open a new Cloud Shell. The OCI config location and token are outside of the user's home directory, in /etc/oci
. For example:
example_user@cloudshell:~ (us-ashburn-1)$ ll /etc/oci
total 20K
drwxrwx---. 1 root oci 44 Oct 12 00:07 ./
drwxr-xr-x. 1 root root 4.0K Oct 12 00:07 ../
-rw-------. 1 jonathan_s oci 1.9K Jan 1 1970 config
-rw-------. 1 jonathan_s oci 1.3K Jan 1 1970 delegation_token
example_user@cloudshell:~ (us-ashburn-1)$
The location of the configuration file, OCI CLI authentication type, and profile choice are specified with environment variables:
OCI_CLI_AUTH=instance_obo_user
OCI_CLI_CONFIG_FILE=/etc/oci/config
OCI_CLI_PROFILE=us-ashburn-1
To customize the OCI CLI, you can create an OCI CLI RC file and put that in your local .oci directory:
$ oci setup oci-cli-rc --file path/to/target/file
For more information on configuring the OCI CLI, see Configuring the CLI.
Managing Cloud Shell Regions
Cloud Shell uses the CLI config file and ENV variables to determine which region that the OCI CLI is interacting with. The OCI CLI configuration file (specified by the environment variable OCI_CLI_CONFIG_FILE
) contains the CLI profiles for Cloud Shell. Each region is its own CLI profile, and the current profile is specified via the OCI_CLI_PROFILE
environment variable.
For example, if you open Cloud Shell from the Console with "US East (Ashburn)" selected in the Console region dropdown, Cloud Shell will open with the OCI_CLI_PROFILE
set to us-ashburn-1
.
There is no
[DEFAULT]
profile value in Cloud Shell because the selected region changes depending on the Console configuration when Cloud Shell is opened.If you would like to customize the OCI CLI settings in Cloud Shell you can use an OCI CLI configuration file. For example, to set a default compartment in your configuration file under the appropriate region profile in your RC file. For our "us-ashburn-1" example, you could add a default compartment setting like this:
[COMPARTMENT DEFAULTS]
[us-ashburn-1]
compartment-id = ocid1.compartment.oc1..xxxxxxxx
Resetting Your Cloud Shell Environment
You can use the csreset
tool to reset your Cloud Shell environment to its default state. You can reset just your bash profile and emacs settings, or you can delete all of the data in your home directory and reset the bash and emacs settings.
To reset your bash files
You can use the --bashfiles
(or -b
) option to reset the $HOME/.bashrc
, $HOME/.bash_profile
, $HOME/.bash_logout
and $HOME/.emacs
files back to their default values:
csreset --bashfiles
or
csreset -b
To reset everything
You can use the --all
(or
-a
) option to erase all the data in your $HOME
directory and reset the $HOME/.bashrc
,
$HOME/.bash_profile
,
$HOME/.bash_logout
and
$HOME/.emacs
files back to their default
values:
csreset --all
or
csreset -a
Displaying help
To display usage options, use the --help
or -h
option:
csreset -h
or
csreset --help