Skip to content

OpenShift 3 Client

Endi S. Dewata edited this page Sep 15, 2023 · 1 revision

Table of Contents

Installation

To install OpenShift client:

$ dnf install origin-clients

Authentication

To get the client login command:

  1. Login to OpenShift console (e.g. https://manage.openshift.com).
  2. Click Open Web Console.
  3. On the upper right of the page, click your name.
  4. Click Copy Login Command.
To authenticate with a token, paste the logging command to a terminal, then execute it:
$ oc login <URL> --token=<hidden>

Alternatively, to authenticate with username and password, remove the token from the login command, then execute it:

$ oc login <URL>

To verify the status, execute the following command:

$ oc status

Projects

To list projects:

$ oc projects

To create a new project:

$ oc new-project <name>

To delete a project:

$ oc delete project <name>

Secrets

To create secret:

$ mkdir <dir>
$ echo -n "<value>" > <dir>/<key>
$ oc secrets new <name> <dir>

Make sure the values do not contain EOL characters.

Storage

To list storage:

$ oc get pvc

To list mounted storage:

$ oc volume dc --all

To mount a storage:

$ oc volume dc/<deployment> --add --name=<name> --type=persistentVolumeClaim --claim-name=<name> --mount-path=<path>

To unmount a storage:

$ oc volume dc/<deployment> --remove --name=<name>

See also:

Image Streams

To list application's image streams:

$ oc get is

To show image stream details:

$ oc describe is/<name>

To list OpenShift's image streams:

$ oc get is -n openshift

To pull PHP 5.6 container image to the local system for use with OpenShift:

$ oc import-image my-rhscl/php-56-rhel7 --from=registry.access.redhat.com/rhscl/php-56-rhel7 --confirm

See also:

Builds

To list build configurations:

$ oc get bc

To create a new build:

$ oc start-build <name> --follow

To list builds:

$ oc get builds

Templates

To list OpenShift's application templates:

$ oc get templates -n openshift

To show template details:

$ oc describe templates/<name> -n openshift

To export a template:

$ oc get templates/<name> -n openshift -o yaml > template.yaml

Application

To list available image streams/templates that can be used to create an application:

$ oc new-app --list

To create a new application with image stream:

$ oc new-app <image stream>:<tag>~<git URL>#<branch>

To list the environment variables:

$ oc env dc/<name> --list

Deployments

To list deployment configurations:

$ oc get dc

To show deployment configuration details:

$ oc describe dc/<name>

To deploy the latest build:

$ oc rollout latest <name>

To configure the replica:

$ oc scale dc <name> --replicas=<number of pods>

Pods

To list all pods:

$ oc get pods

To list pods for a particular deployment config:

$ oc get pods -l deploymentconfig=<name>

To show pod details:

$ oc describe pods/<name>

To delete a pod (a new one will be created automatically):

$ oc delete pods/<name>

See also:

Services

To list services:

$ oc get svc

To create a service:

$ oc expose dc/<deployment> --name=<name> --port=<port>

To show service details:

$ oc describe svc/<name>

To delete a service:

$ oc delete svc/<name>

See also:

Routes

To list routes:

$ oc get routes

To create a route:

$ oc expose svc/<service> --name=<name> --hostname <hostname>

To show route details:

$ oc describe routes/<name>

To delete route:

$ oc delete routes/<name>

See also:

SSL Certificate

See OpenShift 3 SSL.

Remote Access

To start a remote shell:

$ oc rsh <pod>

File Transfer

To upload a file into a pod:

$ oc cp <source path> <pod>:<destination path>

To upload a folder into a pod:

$ oc rsync <source dir> <pod>:<destination dir> --no-perms

To download a file/folder from a pod:

$ oc rsync <pod>:<source file/folder> <destination dir> --no-perms

See also:

Port Forwarding

To forward MySQL port:

$ oc port-forward <mysql pod> 3306
Forwarding from 127.0.0.1:3306 -> 3306
Forwarding from [::1]:3306 -> 3306

Connect with MySQL client as follows:

$ mysql -h 127.0.0.1 -u root -p

Removing Application

To remove an application:

$ oc delete routes/<name>
$ oc delete svc/<name>
$ oc delete is/<name>
$ oc delete dc/<name>
$ oc delete bc/<name>

See Also