This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.1.4. Developer CLI commands
1.4.1. Basic CLI commands 复制链接链接已复制到粘贴板!
1.4.1.1. explain 复制链接链接已复制到粘贴板!
Display documentation for a certain resource.
Example: Display documentation for pods
oc explain pods
$ oc explain pods
1.4.1.2. login 复制链接链接已复制到粘贴板!
Log in to the OpenShift Container Platform server and save login information for subsequent use.
Example: Interactive login
oc login
$ oc login
Example: Log in specifying a user name
oc login -u user1
$ oc login -u user1
1.4.1.3. new-app 复制链接链接已复制到粘贴板!
Create a new application by specifying source code, a template, or an image.
Example: Create a new application from a local Git repository
oc new-app .
$ oc new-app .
Example: Create a new application from a remote Git repository
oc new-app https://github.com/sclorg/cakephp-ex
$ oc new-app https://github.com/sclorg/cakephp-ex
Example: Create a new application from a private remote repository
oc new-app https://github.com/youruser/yourprivaterepo --source-secret=yoursecret
$ oc new-app https://github.com/youruser/yourprivaterepo --source-secret=yoursecret
1.4.1.4. new-project 复制链接链接已复制到粘贴板!
Create a new project and switch to it as the default project in your configuration.
Example: Create a new project
oc new-project myproject
$ oc new-project myproject
1.4.1.5. project 复制链接链接已复制到粘贴板!
Switch to another project and make it the default in your configuration.
Example: Switch to a different project
oc project test-project
$ oc project test-project
1.4.1.6. projects 复制链接链接已复制到粘贴板!
Display information about the current active project and existing projects on the server.
Example: List all projects
oc projects
$ oc projects
1.4.1.7. status 复制链接链接已复制到粘贴板!
Show a high-level overview of the current project.
Example: Show the status of the current project
oc status
$ oc status
1.4.2. Build and Deploy CLI commands 复制链接链接已复制到粘贴板!
1.4.2.1. cancel-build 复制链接链接已复制到粘贴板!
Cancel a running, pending, or new build.
Example: Cancel a build
oc cancel-build python-1
$ oc cancel-build python-1
Example: Cancel all pending builds from the python
build config
oc cancel-build buildconfig/python --state=pending
$ oc cancel-build buildconfig/python --state=pending
1.4.2.2. import-image 复制链接链接已复制到粘贴板!
Import the latest tag and image information from an image repository.
Example: Import the latest image information
oc import-image my-ruby
$ oc import-image my-ruby
1.4.2.3. new-build 复制链接链接已复制到粘贴板!
Create a new build config from source code.
Example: Create a build config from a local Git repository
oc new-build .
$ oc new-build .
Example: Create a build config from a remote Git repository
oc new-build https://github.com/sclorg/cakephp-ex
$ oc new-build https://github.com/sclorg/cakephp-ex
1.4.2.4. rollback 复制链接链接已复制到粘贴板!
Revert an application back to a previous deployment.
Example: Roll back to the last successful deployment
oc rollback php
$ oc rollback php
Example: Roll back to a specific version
oc rollback php --to-version=3
$ oc rollback php --to-version=3
1.4.2.5. rollout 复制链接链接已复制到粘贴板!
Start a new rollout, view its status or history, or roll back to a previous revision of your application.
Example: Roll back to the last successful deployment
oc rollout undo deploymentconfig/php
$ oc rollout undo deploymentconfig/php
Example: Start a new rollout for a deployment with its latest state
oc rollout latest deploymentconfig/php
$ oc rollout latest deploymentconfig/php
1.4.2.6. start-build 复制链接链接已复制到粘贴板!
Start a build from a build config or copy an existing build.
Example: Start a build from the specified build config
oc start-build python
$ oc start-build python
Example: Start a build from a previous build
oc start-build --from-build=python-1
$ oc start-build --from-build=python-1
Example: Set an environment variable to use for the current build
oc start-build python --env=mykey=myvalue
$ oc start-build python --env=mykey=myvalue
1.4.2.7. tag 复制链接链接已复制到粘贴板!
Tag existing images into image streams.
Example: Configure the ruby
image’s latest
tag to refer to the image for the 2.0
tag
oc tag ruby:latest ruby:2.0
$ oc tag ruby:latest ruby:2.0
1.4.3. Application management CLI commands 复制链接链接已复制到粘贴板!
1.4.3.1. annotate 复制链接链接已复制到粘贴板!
Update the annotations on one or more resources.
Example: Add an annotation to a route
oc annotate route/test-route haproxy.router.openshift.io/ip_whitelist="192.168.1.10"
$ oc annotate route/test-route haproxy.router.openshift.io/ip_whitelist="192.168.1.10"
Example: Remove the annotation from the route
oc annotate route/test-route haproxy.router.openshift.io/ip_whitelist-
$ oc annotate route/test-route haproxy.router.openshift.io/ip_whitelist-
1.4.3.2. apply 复制链接链接已复制到粘贴板!
Apply a configuration to a resource by file name or standard in (stdin) in JSON or YAML format.
Example: Apply the configuration in pod.json
to a pod
oc apply -f pod.json
$ oc apply -f pod.json
1.4.3.3. autoscale 复制链接链接已复制到粘贴板!
Autoscale a deployment or replication controller.
Example: Autoscale to a minimum of two and maximum of five pods
oc autoscale deploymentconfig/parksmap-katacoda --min=2 --max=5
$ oc autoscale deploymentconfig/parksmap-katacoda --min=2 --max=5
1.4.3.4. create 复制链接链接已复制到粘贴板!
Create a resource by file name or standard in (stdin) in JSON or YAML format.
Example: Create a pod using the content in pod.json
oc create -f pod.json
$ oc create -f pod.json
1.4.3.5. delete 复制链接链接已复制到粘贴板!
Delete a resource.
Example: Delete a pod named parksmap-katacoda-1-qfqz4
oc delete pod/parksmap-katacoda-1-qfqz4
$ oc delete pod/parksmap-katacoda-1-qfqz4
Example: Delete all pods with the app=parksmap-katacoda
label
oc delete pods -l app=parksmap-katacoda
$ oc delete pods -l app=parksmap-katacoda
1.4.3.6. describe 复制链接链接已复制到粘贴板!
Return detailed information about a specific object.
Example: Describe a deployment named example
oc describe deployment/example
$ oc describe deployment/example
Example: Describe all pods
oc describe pods
$ oc describe pods
1.4.3.7. edit 复制链接链接已复制到粘贴板!
Edit a resource.
Example: Edit a deployment using the default editor
oc edit deploymentconfig/parksmap-katacoda
$ oc edit deploymentconfig/parksmap-katacoda
Example: Edit a deployment using a different editor
OC_EDITOR="nano" oc edit deploymentconfig/parksmap-katacoda
$ OC_EDITOR="nano" oc edit deploymentconfig/parksmap-katacoda
Example: Edit a deployment in JSON format
oc edit deploymentconfig/parksmap-katacoda -o json
$ oc edit deploymentconfig/parksmap-katacoda -o json
1.4.3.8. expose 复制链接链接已复制到粘贴板!
Expose a service externally as a route.
Example: Expose a service
oc expose service/parksmap-katacoda
$ oc expose service/parksmap-katacoda
Example: Expose a service and specify the host name
oc expose service/parksmap-katacoda --hostname=www.my-host.com
$ oc expose service/parksmap-katacoda --hostname=www.my-host.com
1.4.3.9. get 复制链接链接已复制到粘贴板!
Display one or more resources.
Example: List pods in the default
namespace
oc get pods -n default
$ oc get pods -n default
Example: Get details about the python
deployment in JSON format
oc get deploymentconfig/python -o json
$ oc get deploymentconfig/python -o json
1.4.3.10. label 复制链接链接已复制到粘贴板!
Update the labels on one or more resources.
Example: Update the python-1-mz2rf
pod with the label status
set to unhealthy
oc label pod/python-1-mz2rf status=unhealthy
$ oc label pod/python-1-mz2rf status=unhealthy
1.4.3.11. scale 复制链接链接已复制到粘贴板!
Set the desired number of replicas for a replication controller or a deployment.
Example: Scale the ruby-app
deployment to three pods
oc scale deploymentconfig/ruby-app --replicas=3
$ oc scale deploymentconfig/ruby-app --replicas=3
1.4.3.12. secrets 复制链接链接已复制到粘贴板!
Manage secrets in your project.
Example: Allow my-pull-secret
to be used as an image pull secret by the default
service account
oc secrets link default my-pull-secret --for=pull
$ oc secrets link default my-pull-secret --for=pull
1.4.3.13. serviceaccounts 复制链接链接已复制到粘贴板!
Get a token assigned to a service account or create a new token or kubeconfig
file for a service account.
Example: Get the token assigned to the default
service account
oc serviceaccounts get-token default
$ oc serviceaccounts get-token default
1.4.3.14. set 复制链接链接已复制到粘贴板!
Configure existing application resources.
Example: Set the name of a secret on a build config
oc set build-secret --source buildconfig/mybc mysecret
$ oc set build-secret --source buildconfig/mybc mysecret
1.4.4. Troubleshooting and debugging CLI commands 复制链接链接已复制到粘贴板!
1.4.4.1. attach 复制链接链接已复制到粘贴板!
Attach the shell to a running container.
Example: Get output from the python
container from pod python-1-mz2rf
oc attach python-1-mz2rf -c python
$ oc attach python-1-mz2rf -c python
1.4.4.2. cp 复制链接链接已复制到粘贴板!
Copy files and directories to and from containers.
Example: Copy a file from the python-1-mz2rf
pod to the local file system
oc cp default/python-1-mz2rf:/opt/app-root/src/README.md ~/mydirectory/.
$ oc cp default/python-1-mz2rf:/opt/app-root/src/README.md ~/mydirectory/.
1.4.4.3. debug 复制链接链接已复制到粘贴板!
Launch a command shell to debug a running application.
Example: Debug the python
deployment
oc debug deploymentconfig/python
$ oc debug deploymentconfig/python
1.4.4.4. exec 复制链接链接已复制到粘贴板!
Execute a command in a container.
Example: Execute the ls
command in the python
container from pod python-1-mz2rf
oc exec python-1-mz2rf -c python ls
$ oc exec python-1-mz2rf -c python ls
1.4.4.5. logs 复制链接链接已复制到粘贴板!
Retrieve the log output for a specific build, build config, deployment, or pod.
Example: Stream the latest logs from the python
deployment
oc logs -f deploymentconfig/python
$ oc logs -f deploymentconfig/python
1.4.4.6. port-forward 复制链接链接已复制到粘贴板!
Forward one or more local ports to a pod.
Example: Listen on port 8888
locally and forward to port 5000
in the pod
oc port-forward python-1-mz2rf 8888:5000
$ oc port-forward python-1-mz2rf 8888:5000
1.4.4.7. proxy 复制链接链接已复制到粘贴板!
Run a proxy to the Kubernetes API server.
Example: Run a proxy to the API server on port 8011
serving static content from ./local/www/
oc proxy --port=8011 --www=./local/www/
$ oc proxy --port=8011 --www=./local/www/
1.4.4.8. rsh 复制链接链接已复制到粘贴板!
Open a remote shell session to a container.
Example: Open a shell session on the first container in the python-1-mz2rf
pod
oc rsh python-1-mz2rf
$ oc rsh python-1-mz2rf
1.4.4.9. rsync 复制链接链接已复制到粘贴板!
Copy contents of a directory to or from a running pod container. Only changed files are copied using the rsync
command from your operating system.
Example: Synchronize files from a local directory with a pod directory
oc rsync ~/mydirectory/ python-1-mz2rf:/opt/app-root/src/
$ oc rsync ~/mydirectory/ python-1-mz2rf:/opt/app-root/src/
1.4.4.10. run 复制链接链接已复制到粘贴板!
Create a pod running a particular image.
Example: Start a pod running the perl
image
oc run my-test --image=perl
$ oc run my-test --image=perl
1.4.4.11. wait 复制链接链接已复制到粘贴板!
Wait for a specific condition on one or more resources.
This command is experimental and might change without notice.
Example: Wait for the python-1-mz2rf
pod to be deleted
oc wait --for=delete pod/python-1-mz2rf
$ oc wait --for=delete pod/python-1-mz2rf
1.4.5. Advanced developer CLI commands 复制链接链接已复制到粘贴板!
1.4.5.1. api-resources 复制链接链接已复制到粘贴板!
Display the full list of API resources that the server supports.
Example: List the supported API resources
oc api-resources
$ oc api-resources
1.4.5.2. api-versions 复制链接链接已复制到粘贴板!
Display the full list of API versions that the server supports.
Example: List the supported API versions
oc api-versions
$ oc api-versions
1.4.5.3. auth 复制链接链接已复制到粘贴板!
Inspect permissions and reconcile RBAC roles.
Example: Check whether the current user can read pod logs
oc auth can-i get pods --subresource=log
$ oc auth can-i get pods --subresource=log
Example: Reconcile RBAC roles and permissions from a file
oc auth reconcile -f policy.json
$ oc auth reconcile -f policy.json
1.4.5.4. cluster-info 复制链接链接已复制到粘贴板!
Display the address of the master and cluster services.
Example: Display cluster information
oc cluster-info
$ oc cluster-info
1.4.5.5. convert 复制链接链接已复制到粘贴板!
Convert a YAML or JSON configuration file to a different API version and print to standard output (stdout).
Example: Convert pod.yaml
to the latest version
oc convert -f pod.yaml
$ oc convert -f pod.yaml
1.4.5.6. extract 复制链接链接已复制到粘贴板!
Extract the contents of a config map or secret. Each key in the config map or secret is created as a separate file with the name of the key.
Example: Download the contents of the ruby-1-ca
config map to the current directory
oc extract configmap/ruby-1-ca
$ oc extract configmap/ruby-1-ca
Example: Print the contents of the ruby-1-ca
config map to stdout
oc extract configmap/ruby-1-ca --to=-
$ oc extract configmap/ruby-1-ca --to=-
1.4.5.7. idle 复制链接链接已复制到粘贴板!
Idle scalable resources. An idled service will automatically become unidled when it receives traffic or it can be manually unidled using the oc scale
command.
Example: Idle the ruby-app
service
oc idle ruby-app
$ oc idle ruby-app
1.4.5.8. image 复制链接链接已复制到粘贴板!
Manage images in your OpenShift Container Platform cluster.
Example: Copy an image to another tag
oc image mirror myregistry.com/myimage:latest myregistry.com/myimage:stable
$ oc image mirror myregistry.com/myimage:latest myregistry.com/myimage:stable
1.4.5.9. observe 复制链接链接已复制到粘贴板!
Observe changes to resources and take action on them.
Example: Observe changes to services
oc observe services
$ oc observe services
1.4.5.10. patch 复制链接链接已复制到粘贴板!
Updates one or more fields of an object using strategic merge patch in JSON or YAML format.
Example: Update the spec.unschedulable
field for node node1
to true
oc patch node/node1 -p '{"spec":{"unschedulable":true}}'
$ oc patch node/node1 -p '{"spec":{"unschedulable":true}}'
If you must patch a custom resource definition, you must include the --type merge
option in the command.
1.4.5.11. policy 复制链接链接已复制到粘贴板!
Manage authorization policies.
Example: Add the edit
role to user1
for the current project
oc policy add-role-to-user edit user1
$ oc policy add-role-to-user edit user1
1.4.5.12. process 复制链接链接已复制到粘贴板!
Process a template into a list of resources.
Example: Convert template.json
to a resource list and pass to oc create
oc process -f template.json | oc create -f -
$ oc process -f template.json | oc create -f -
1.4.5.13. registry 复制链接链接已复制到粘贴板!
Manage the integrated registry on OpenShift Container Platform.
Example: Display information about the integrated registry
oc registry info
$ oc registry info
1.4.5.14. replace 复制链接链接已复制到粘贴板!
Modify an existing object based on the contents of the specified configuration file.
Example: Update a pod using the content in pod.json
oc replace -f pod.json
$ oc replace -f pod.json
1.4.6. Settings CLI commands 复制链接链接已复制到粘贴板!
1.4.6.1. completion 复制链接链接已复制到粘贴板!
Output shell completion code for the specified shell.
Example: Display completion code for Bash
oc completion bash
$ oc completion bash
1.4.6.2. config 复制链接链接已复制到粘贴板!
Manage the client configuration files.
Example: Display the current configuration
oc config view
$ oc config view
Example: Switch to a different context
oc config use-context test-context
$ oc config use-context test-context
1.4.6.3. logout 复制链接链接已复制到粘贴板!
Log out of the current session.
Example: End the current session
oc logout
$ oc logout
1.4.6.4. whoami 复制链接链接已复制到粘贴板!
Display information about the current session.
Example: Display the currently authenticated user
oc whoami
$ oc whoami
1.4.7. Other developer CLI commands 复制链接链接已复制到粘贴板!
1.4.7.1. help 复制链接链接已复制到粘贴板!
Display general help information for the CLI and a list of available commands.
Example: Display available commands
oc help
$ oc help
Example: Display the help for the new-project
command
oc help new-project
$ oc help new-project
1.4.7.2. plugin 复制链接链接已复制到粘贴板!
List the available plug-ins on the user’s PATH
.
Example: List available plug-ins
oc plugin list
$ oc plugin list
1.4.7.3. version 复制链接链接已复制到粘贴板!
Display the oc
client and server versions.
Example: Display version information
oc version
$ oc version
For cluster administrators, the OpenShift Container Platform server version is also displayed.