OpenShift CLI developer command reference

This reference provides descriptions and example commands for OpenShift CLI (oc) developer commands. For administrator commands, see the OpenShift CLI administrator command reference.

Run oc help to list all commands or run oc <command> --help to get additional details for a specific command.

OpenShift CLI (oc) developer commands

oc annotate

Update the annotations on a resource

Example usage

  1. # Update pod 'foo' with the annotation 'description' and the value 'my frontend'
  2. # If the same annotation is set multiple times, only the last value will be applied
  3. oc annotate pods foo description='my frontend'
  4. # Update a pod identified by type and name in "pod.json"
  5. oc annotate -f pod.json description='my frontend'
  6. # Update pod 'foo' with the annotation 'description' and the value 'my frontend running nginx', overwriting any existing value
  7. oc annotate --overwrite pods foo description='my frontend running nginx'
  8. # Update all pods in the namespace
  9. oc annotate pods --all description='my frontend running nginx'
  10. # Update pod 'foo' only if the resource is unchanged from version 1
  11. oc annotate pods foo description='my frontend running nginx' --resource-version=1
  12. # Update pod 'foo' by removing an annotation named 'description' if it exists
  13. # Does not require the --overwrite flag
  14. oc annotate pods foo description-

oc api-resources

Print the supported API resources on the server

Example usage

  1. # Print the supported API resources
  2. oc api-resources
  3. # Print the supported API resources with more information
  4. oc api-resources -o wide
  5. # Print the supported API resources sorted by a column
  6. oc api-resources --sort-by=name
  7. # Print the supported namespaced resources
  8. oc api-resources --namespaced=true
  9. # Print the supported non-namespaced resources
  10. oc api-resources --namespaced=false
  11. # Print the supported API resources with a specific APIGroup
  12. oc api-resources --api-group=extensions

oc api-versions

Print the supported API versions on the server, in the form of “group/version”

Example usage

  1. # Print the supported API versions
  2. oc api-versions

oc apply

Apply a configuration to a resource by file name or stdin

Example usage

  1. # Apply the configuration in pod.json to a pod
  2. oc apply -f ./pod.json
  3. # Apply resources from a directory containing kustomization.yaml - e.g. dir/kustomization.yaml
  4. oc apply -k dir/
  5. # Apply the JSON passed into stdin to a pod
  6. cat pod.json | oc apply -f -
  7. # Note: --prune is still in Alpha
  8. # Apply the configuration in manifest.yaml that matches label app=nginx and delete all other resources that are not in the file and match label app=nginx
  9. oc apply --prune -f manifest.yaml -l app=nginx
  10. # Apply the configuration in manifest.yaml and delete all the other config maps that are not in the file
  11. oc apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/ConfigMap

oc apply edit-last-applied

Edit latest last-applied-configuration annotations of a resource/object

Example usage

  1. # Edit the last-applied-configuration annotations by type/name in YAML
  2. oc apply edit-last-applied deployment/nginx
  3. # Edit the last-applied-configuration annotations by file in JSON
  4. oc apply edit-last-applied -f deploy.yaml -o json

oc apply set-last-applied

Set the last-applied-configuration annotation on a live object to match the contents of a file

Example usage

  1. # Set the last-applied-configuration of a resource to match the contents of a file
  2. oc apply set-last-applied -f deploy.yaml
  3. # Execute set-last-applied against each configuration file in a directory
  4. oc apply set-last-applied -f path/
  5. # Set the last-applied-configuration of a resource to match the contents of a file; will create the annotation if it does not already exist
  6. oc apply set-last-applied -f deploy.yaml --create-annotation=true

oc apply view-last-applied

View the latest last-applied-configuration annotations of a resource/object

Example usage

  1. # View the last-applied-configuration annotations by type/name in YAML
  2. oc apply view-last-applied deployment/nginx
  3. # View the last-applied-configuration annotations by file in JSON
  4. oc apply view-last-applied -f deploy.yaml -o json

oc attach

Attach to a running container

Example usage

  1. # Get output from running pod mypod; use the 'oc.kubernetes.io/default-container' annotation
  2. # for selecting the container to be attached or the first container in the pod will be chosen
  3. oc attach mypod
  4. # Get output from ruby-container from pod mypod
  5. oc attach mypod -c ruby-container
  6. # Switch to raw terminal mode; sends stdin to 'bash' in ruby-container from pod mypod
  7. # and sends stdout/stderr from 'bash' back to the client
  8. oc attach mypod -c ruby-container -i -t
  9. # Get output from the first pod of a replica set named nginx
  10. oc attach rs/nginx

oc auth can-i

Check whether an action is allowed

Example usage

  1. # Check to see if I can create pods in any namespace
  2. oc auth can-i create pods --all-namespaces
  3. # Check to see if I can list deployments in my current namespace
  4. oc auth can-i list deployments.apps
  5. # Check to see if I can do everything in my current namespace ("*" means all)
  6. oc auth can-i '*' '*'
  7. # Check to see if I can get the job named "bar" in namespace "foo"
  8. oc auth can-i list jobs.batch/bar -n foo
  9. # Check to see if I can read pod logs
  10. oc auth can-i get pods --subresource=log
  11. # Check to see if I can access the URL /logs/
  12. oc auth can-i get /logs/
  13. # List all allowed actions in namespace "foo"
  14. oc auth can-i --list --namespace=foo

oc auth reconcile

Reconciles rules for RBAC role, role binding, cluster role, and cluster role binding objects

Example usage

  1. # Reconcile RBAC resources from a file
  2. oc auth reconcile -f my-rbac-rules.yaml

oc autoscale

Autoscale a deployment config, deployment, replica set, stateful set, or replication controller

Example usage

  1. # Auto scale a deployment "foo", with the number of pods between 2 and 10, no target CPU utilization specified so a default autoscaling policy will be used
  2. oc autoscale deployment foo --min=2 --max=10
  3. # Auto scale a replication controller "foo", with the number of pods between 1 and 5, target CPU utilization at 80%
  4. oc autoscale rc foo --max=5 --cpu-percent=80

oc cancel-build

Cancel running, pending, or new builds

Example usage

  1. # Cancel the build with the given name
  2. oc cancel-build ruby-build-2
  3. # Cancel the named build and print the build logs
  4. oc cancel-build ruby-build-2 --dump-logs
  5. # Cancel the named build and create a new one with the same parameters
  6. oc cancel-build ruby-build-2 --restart
  7. # Cancel multiple builds
  8. oc cancel-build ruby-build-1 ruby-build-2 ruby-build-3
  9. # Cancel all builds created from the 'ruby-build' build config that are in the 'new' state
  10. oc cancel-build bc/ruby-build --state=new

oc cluster-info

Display cluster information

Example usage

  1. # Print the address of the control plane and cluster services
  2. oc cluster-info

oc cluster-info dump

Dump relevant information for debugging and diagnosis

Example usage

  1. # Dump current cluster state to stdout
  2. oc cluster-info dump
  3. # Dump current cluster state to /path/to/cluster-state
  4. oc cluster-info dump --output-directory=/path/to/cluster-state
  5. # Dump all namespaces to stdout
  6. oc cluster-info dump --all-namespaces
  7. # Dump a set of namespaces to /path/to/cluster-state
  8. oc cluster-info dump --namespaces default,kube-system --output-directory=/path/to/cluster-state

oc completion

Output shell completion code for the specified shell (bash, zsh or fish)

Example usage

  1. # Installing bash completion on macOS using homebrew
  2. ## If running Bash 3.2 included with macOS
  3. brew install bash-completion
  4. ## or, if running Bash 4.1+
  5. brew install bash-completion@2
  6. ## If oc is installed via homebrew, this should start working immediately
  7. ## If you've installed via other means, you may need add the completion to your completion directory
  8. oc completion bash > $(brew --prefix)/etc/bash_completion.d/oc
  9. # Installing bash completion on Linux
  10. ## If bash-completion is not installed on Linux, install the 'bash-completion' package
  11. ## via your distribution's package manager.
  12. ## Load the oc completion code for bash into the current shell
  13. source <(oc completion bash)
  14. ## Write bash completion code to a file and source it from .bash_profile
  15. oc completion bash > ~/.kube/completion.bash.inc
  16. printf "
  17. # Kubectl shell completion
  18. source '$HOME/.kube/completion.bash.inc'
  19. " >> $HOME/.bash_profile
  20. source $HOME/.bash_profile
  21. # Load the oc completion code for zsh[1] into the current shell
  22. source <(oc completion zsh)
  23. # Set the oc completion code for zsh[1] to autoload on startup
  24. oc completion zsh > "${fpath[1]}/_oc"
  25. # Load the oc completion code for fish[2] into the current shell
  26. oc completion fish | source
  27. # To load completions for each session, execute once:
  28. oc completion fish > ~/.config/fish/completions/oc.fish
  29. # Load the oc completion code for powershell into the current shell
  30. oc completion powershell | Out-String | Invoke-Expression
  31. # Set oc completion code for powershell to run on startup
  32. ## Save completion code to a script and execute in the profile
  33. oc completion powershell > $HOME\.kube\completion.ps1
  34. Add-Content $PROFILE "$HOME\.kube\completion.ps1"
  35. ## Execute completion code in the profile
  36. Add-Content $PROFILE "if (Get-Command oc -ErrorAction SilentlyContinue) {
  37. oc completion powershell | Out-String | Invoke-Expression
  38. }"
  39. ## Add completion code directly to the $PROFILE script
  40. oc completion powershell >> $PROFILE

oc config current-context

Display the current-context

Example usage

  1. # Display the current-context
  2. oc config current-context

oc config delete-cluster

Delete the specified cluster from the kubeconfig

Example usage

  1. # Delete the minikube cluster
  2. oc config delete-cluster minikube

oc config delete-context

Delete the specified context from the kubeconfig

Example usage

  1. # Delete the context for the minikube cluster
  2. oc config delete-context minikube

oc config delete-user

Delete the specified user from the kubeconfig

Example usage

  1. # Delete the minikube user
  2. oc config delete-user minikube

oc config get-clusters

Display clusters defined in the kubeconfig

Example usage

  1. # List the clusters that oc knows about
  2. oc config get-clusters

oc config get-contexts

Describe one or many contexts

Example usage

  1. # List all the contexts in your kubeconfig file
  2. oc config get-contexts
  3. # Describe one context in your kubeconfig file
  4. oc config get-contexts my-context

oc config get-users

Display users defined in the kubeconfig

Example usage

  1. # List the users that oc knows about
  2. oc config get-users

oc config rename-context

Rename a context from the kubeconfig file

Example usage

  1. # Rename the context 'old-name' to 'new-name' in your kubeconfig file
  2. oc config rename-context old-name new-name

oc config set

Set an individual value in a kubeconfig file

Example usage

  1. # Set the server field on the my-cluster cluster to https://1.2.3.4
  2. oc config set clusters.my-cluster.server https://1.2.3.4
  3. # Set the certificate-authority-data field on the my-cluster cluster
  4. oc config set clusters.my-cluster.certificate-authority-data $(echo "cert_data_here" | base64 -i -)
  5. # Set the cluster field in the my-context context to my-cluster
  6. oc config set contexts.my-context.cluster my-cluster
  7. # Set the client-key-data field in the cluster-admin user using --set-raw-bytes option
  8. oc config set users.cluster-admin.client-key-data cert_data_here --set-raw-bytes=true

oc config set-cluster

Set a cluster entry in kubeconfig

Example usage

  1. # Set only the server field on the e2e cluster entry without touching other values
  2. oc config set-cluster e2e --server=https://1.2.3.4
  3. # Embed certificate authority data for the e2e cluster entry
  4. oc config set-cluster e2e --embed-certs --certificate-authority=~/.kube/e2e/kubernetes.ca.crt
  5. # Disable cert checking for the dev cluster entry
  6. oc config set-cluster e2e --insecure-skip-tls-verify=true
  7. # Set custom TLS server name to use for validation for the e2e cluster entry
  8. oc config set-cluster e2e --tls-server-name=my-cluster-name

oc config set-context

Set a context entry in kubeconfig

Example usage

  1. # Set the user field on the gce context entry without touching other values
  2. oc config set-context gce --user=cluster-admin

oc config set-credentials

Set a user entry in kubeconfig

Example usage

  1. # Set only the "client-key" field on the "cluster-admin"
  2. # entry, without touching other values
  3. oc config set-credentials cluster-admin --client-key=~/.kube/admin.key
  4. # Set basic auth for the "cluster-admin" entry
  5. oc config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif
  6. # Embed client certificate data in the "cluster-admin" entry
  7. oc config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true
  8. # Enable the Google Compute Platform auth provider for the "cluster-admin" entry
  9. oc config set-credentials cluster-admin --auth-provider=gcp
  10. # Enable the OpenID Connect auth provider for the "cluster-admin" entry with additional args
  11. oc config set-credentials cluster-admin --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar
  12. # Remove the "client-secret" config value for the OpenID Connect auth provider for the "cluster-admin" entry
  13. oc config set-credentials cluster-admin --auth-provider=oidc --auth-provider-arg=client-secret-
  14. # Enable new exec auth plugin for the "cluster-admin" entry
  15. oc config set-credentials cluster-admin --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1
  16. # Define new exec auth plugin args for the "cluster-admin" entry
  17. oc config set-credentials cluster-admin --exec-arg=arg1 --exec-arg=arg2
  18. # Create or update exec auth plugin environment variables for the "cluster-admin" entry
  19. oc config set-credentials cluster-admin --exec-env=key1=val1 --exec-env=key2=val2
  20. # Remove exec auth plugin environment variables for the "cluster-admin" entry
  21. oc config set-credentials cluster-admin --exec-env=var-to-remove-

oc config unset

Unset an individual value in a kubeconfig file

Example usage

  1. # Unset the current-context
  2. oc config unset current-context
  3. # Unset namespace in foo context
  4. oc config unset contexts.foo.namespace

oc config use-context

Set the current-context in a kubeconfig file

Example usage

  1. # Use the context for the minikube cluster
  2. oc config use-context minikube

oc config view

Display merged kubeconfig settings or a specified kubeconfig file

Example usage

  1. # Show merged kubeconfig settings
  2. oc config view
  3. # Show merged kubeconfig settings and raw certificate data
  4. oc config view --raw
  5. # Get the password for the e2e user
  6. oc config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'

oc cp

Copy files and directories to and from containers

Example usage

  1. # !!!Important Note!!!
  2. # Requires that the 'tar' binary is present in your container
  3. # image. If 'tar' is not present, 'oc cp' will fail.
  4. #
  5. # For advanced use cases, such as symlinks, wildcard expansion or
  6. # file mode preservation, consider using 'oc exec'.
  7. # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
  8. tar cf - /tmp/foo | oc exec -i -n <some-namespace> <some-pod> -- tar xf - -C /tmp/bar
  9. # Copy /tmp/foo from a remote pod to /tmp/bar locally
  10. oc exec -n <some-namespace> <some-pod> -- tar cf - /tmp/foo | tar xf - -C /tmp/bar
  11. # Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
  12. oc cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
  13. # Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
  14. oc cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>
  15. # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
  16. oc cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
  17. # Copy /tmp/foo from a remote pod to /tmp/bar locally
  18. oc cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar

oc create

Create a resource from a file or from stdin

Example usage

  1. # Create a pod using the data in pod.json
  2. oc create -f ./pod.json
  3. # Create a pod based on the JSON passed into stdin
  4. cat pod.json | oc create -f -
  5. # Edit the data in docker-registry.yaml in JSON then create the resource using the edited data
  6. oc create -f docker-registry.yaml --edit -o json

oc create build

Create a new build

Example usage

  1. # Create a new build
  2. oc create build myapp

oc create clusterresourcequota

Create a cluster resource quota

Example usage

  1. # Create a cluster resource quota limited to 10 pods
  2. oc create clusterresourcequota limit-bob --project-annotation-selector=openshift.io/requester=user-bob --hard=pods=10

oc create clusterrole

Create a cluster role

Example usage

  1. # Create a cluster role named "pod-reader" that allows user to perform "get", "watch" and "list" on pods
  2. oc create clusterrole pod-reader --verb=get,list,watch --resource=pods
  3. # Create a cluster role named "pod-reader" with ResourceName specified
  4. oc create clusterrole pod-reader --verb=get --resource=pods --resource-name=readablepod --resource-name=anotherpod
  5. # Create a cluster role named "foo" with API Group specified
  6. oc create clusterrole foo --verb=get,list,watch --resource=rs.extensions
  7. # Create a cluster role named "foo" with SubResource specified
  8. oc create clusterrole foo --verb=get,list,watch --resource=pods,pods/status
  9. # Create a cluster role name "foo" with NonResourceURL specified
  10. oc create clusterrole "foo" --verb=get --non-resource-url=/logs/*
  11. # Create a cluster role name "monitoring" with AggregationRule specified
  12. oc create clusterrole monitoring --aggregation-rule="rbac.example.com/aggregate-to-monitoring=true"

oc create clusterrolebinding

Create a cluster role binding for a particular cluster role

Example usage

  1. # Create a cluster role binding for user1, user2, and group1 using the cluster-admin cluster role
  2. oc create clusterrolebinding cluster-admin --clusterrole=cluster-admin --user=user1 --user=user2 --group=group1

oc create configmap

Create a config map from a local file, directory or literal value

Example usage

  1. # Create a new config map named my-config based on folder bar
  2. oc create configmap my-config --from-file=path/to/bar
  3. # Create a new config map named my-config with specified keys instead of file basenames on disk
  4. oc create configmap my-config --from-file=key1=/path/to/bar/file1.txt --from-file=key2=/path/to/bar/file2.txt
  5. # Create a new config map named my-config with key1=config1 and key2=config2
  6. oc create configmap my-config --from-literal=key1=config1 --from-literal=key2=config2
  7. # Create a new config map named my-config from the key=value pairs in the file
  8. oc create configmap my-config --from-file=path/to/bar
  9. # Create a new config map named my-config from an env file
  10. oc create configmap my-config --from-env-file=path/to/foo.env --from-env-file=path/to/bar.env

oc create cronjob

Create a cron job with the specified name

Example usage

  1. # Create a cron job
  2. oc create cronjob my-job --image=busybox --schedule="*/1 * * * *"
  3. # Create a cron job with a command
  4. oc create cronjob my-job --image=busybox --schedule="*/1 * * * *" -- date

oc create deployment

Create a deployment with the specified name

Example usage

  1. # Create a deployment named my-dep that runs the busybox image
  2. oc create deployment my-dep --image=busybox
  3. # Create a deployment with a command
  4. oc create deployment my-dep --image=busybox -- date
  5. # Create a deployment named my-dep that runs the nginx image with 3 replicas
  6. oc create deployment my-dep --image=nginx --replicas=3
  7. # Create a deployment named my-dep that runs the busybox image and expose port 5701
  8. oc create deployment my-dep --image=busybox --port=5701

oc create deploymentconfig

Create a deployment config with default options that uses a given image

Example usage

  1. # Create an nginx deployment config named my-nginx
  2. oc create deploymentconfig my-nginx --image=nginx

oc create identity

Manually create an identity (only needed if automatic creation is disabled)

Example usage

  1. # Create an identity with identity provider "acme_ldap" and the identity provider username "adamjones"
  2. oc create identity acme_ldap:adamjones

oc create imagestream

Create a new empty image stream

Example usage

  1. # Create a new image stream
  2. oc create imagestream mysql

oc create imagestreamtag

Create a new image stream tag

Example usage

  1. # Create a new image stream tag based on an image in a remote registry
  2. oc create imagestreamtag mysql:latest --from-image=myregistry.local/mysql/mysql:5.0

oc create ingress

Create an ingress with the specified name

Example usage

  1. # Create a single ingress called 'simple' that directs requests to foo.com/bar to svc
  2. # svc1:8080 with a tls secret "my-cert"
  3. oc create ingress simple --rule="foo.com/bar=svc1:8080,tls=my-cert"
  4. # Create a catch all ingress of "/path" pointing to service svc:port and Ingress Class as "otheringress"
  5. oc create ingress catch-all --class=otheringress --rule="/path=svc:port"
  6. # Create an ingress with two annotations: ingress.annotation1 and ingress.annotations2
  7. oc create ingress annotated --class=default --rule="foo.com/bar=svc:port" \
  8. --annotation ingress.annotation1=foo \
  9. --annotation ingress.annotation2=bla
  10. # Create an ingress with the same host and multiple paths
  11. oc create ingress multipath --class=default \
  12. --rule="foo.com/=svc:port" \
  13. --rule="foo.com/admin/=svcadmin:portadmin"
  14. # Create an ingress with multiple hosts and the pathType as Prefix
  15. oc create ingress ingress1 --class=default \
  16. --rule="foo.com/path*=svc:8080" \
  17. --rule="bar.com/admin*=svc2:http"
  18. # Create an ingress with TLS enabled using the default ingress certificate and different path types
  19. oc create ingress ingtls --class=default \
  20. --rule="foo.com/=svc:https,tls" \
  21. --rule="foo.com/path/subpath*=othersvc:8080"
  22. # Create an ingress with TLS enabled using a specific secret and pathType as Prefix
  23. oc create ingress ingsecret --class=default \
  24. --rule="foo.com/*=svc:8080,tls=secret1"
  25. # Create an ingress with a default backend
  26. oc create ingress ingdefault --class=default \
  27. --default-backend=defaultsvc:http \
  28. --rule="foo.com/*=svc:8080,tls=secret1"

oc create job

Create a job with the specified name

Example usage

  1. # Create a job
  2. oc create job my-job --image=busybox
  3. # Create a job with a command
  4. oc create job my-job --image=busybox -- date
  5. # Create a job from a cron job named "a-cronjob"
  6. oc create job test-job --from=cronjob/a-cronjob

oc create namespace

Create a namespace with the specified name

Example usage

  1. # Create a new namespace named my-namespace
  2. oc create namespace my-namespace

oc create poddisruptionbudget

Create a pod disruption budget with the specified name

Example usage

  1. # Create a pod disruption budget named my-pdb that will select all pods with the app=rails label
  2. # and require at least one of them being available at any point in time
  3. oc create poddisruptionbudget my-pdb --selector=app=rails --min-available=1
  4. # Create a pod disruption budget named my-pdb that will select all pods with the app=nginx label
  5. # and require at least half of the pods selected to be available at any point in time
  6. oc create pdb my-pdb --selector=app=nginx --min-available=50%

oc create priorityclass

Create a priority class with the specified name

Example usage

  1. # Create a priority class named high-priority
  2. oc create priorityclass high-priority --value=1000 --description="high priority"
  3. # Create a priority class named default-priority that is considered as the global default priority
  4. oc create priorityclass default-priority --value=1000 --global-default=true --description="default priority"
  5. # Create a priority class named high-priority that cannot preempt pods with lower priority
  6. oc create priorityclass high-priority --value=1000 --description="high priority" --preemption-policy="Never"

oc create quota

Create a quota with the specified name

Example usage

  1. # Create a new resource quota named my-quota
  2. oc create quota my-quota --hard=cpu=1,memory=1G,pods=2,services=3,replicationcontrollers=2,resourcequotas=1,secrets=5,persistentvolumeclaims=10
  3. # Create a new resource quota named best-effort
  4. oc create quota best-effort --hard=pods=100 --scopes=BestEffort

oc create role

Create a role with single rule

Example usage

  1. # Create a role named "pod-reader" that allows user to perform "get", "watch" and "list" on pods
  2. oc create role pod-reader --verb=get --verb=list --verb=watch --resource=pods
  3. # Create a role named "pod-reader" with ResourceName specified
  4. oc create role pod-reader --verb=get --resource=pods --resource-name=readablepod --resource-name=anotherpod
  5. # Create a role named "foo" with API Group specified
  6. oc create role foo --verb=get,list,watch --resource=rs.extensions
  7. # Create a role named "foo" with SubResource specified
  8. oc create role foo --verb=get,list,watch --resource=pods,pods/status

oc create rolebinding

Create a role binding for a particular role or cluster role

Example usage

  1. # Create a role binding for user1, user2, and group1 using the admin cluster role
  2. oc create rolebinding admin --clusterrole=admin --user=user1 --user=user2 --group=group1

oc create route edge

Create a route that uses edge TLS termination

Example usage

  1. # Create an edge route named "my-route" that exposes the frontend service
  2. oc create route edge my-route --service=frontend
  3. # Create an edge route that exposes the frontend service and specify a path
  4. # If the route name is omitted, the service name will be used
  5. oc create route edge --service=frontend --path /assets

oc create route passthrough

Create a route that uses passthrough TLS termination

Example usage

  1. # Create a passthrough route named "my-route" that exposes the frontend service
  2. oc create route passthrough my-route --service=frontend
  3. # Create a passthrough route that exposes the frontend service and specify
  4. # a host name. If the route name is omitted, the service name will be used
  5. oc create route passthrough --service=frontend --hostname=www.example.com

oc create route reencrypt

Create a route that uses reencrypt TLS termination

Example usage

  1. # Create a route named "my-route" that exposes the frontend service
  2. oc create route reencrypt my-route --service=frontend --dest-ca-cert cert.cert
  3. # Create a reencrypt route that exposes the frontend service, letting the
  4. # route name default to the service name and the destination CA certificate
  5. # default to the service CA
  6. oc create route reencrypt --service=frontend

oc create secret docker-registry

Create a secret for use with a Docker registry

Example usage

  1. # If you don't already have a .dockercfg file, you can create a dockercfg secret directly by using:
  2. oc create secret docker-registry my-secret --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL
  3. # Create a new secret named my-secret from ~/.docker/config.json
  4. oc create secret docker-registry my-secret --from-file=.dockerconfigjson=path/to/.docker/config.json

oc create secret generic

Create a secret from a local file, directory, or literal value

Example usage

  1. # Create a new secret named my-secret with keys for each file in folder bar
  2. oc create secret generic my-secret --from-file=path/to/bar
  3. # Create a new secret named my-secret with specified keys instead of names on disk
  4. oc create secret generic my-secret --from-file=ssh-privatekey=path/to/id_rsa --from-file=ssh-publickey=path/to/id_rsa.pub
  5. # Create a new secret named my-secret with key1=supersecret and key2=topsecret
  6. oc create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret
  7. # Create a new secret named my-secret using a combination of a file and a literal
  8. oc create secret generic my-secret --from-file=ssh-privatekey=path/to/id_rsa --from-literal=passphrase=topsecret
  9. # Create a new secret named my-secret from env files
  10. oc create secret generic my-secret --from-env-file=path/to/foo.env --from-env-file=path/to/bar.env

oc create secret tls

Create a TLS secret

Example usage

  1. # Create a new TLS secret named tls-secret with the given key pair
  2. oc create secret tls tls-secret --cert=path/to/tls.cert --key=path/to/tls.key

oc create service clusterip

Create a ClusterIP service

Example usage

  1. # Create a new ClusterIP service named my-cs
  2. oc create service clusterip my-cs --tcp=5678:8080
  3. # Create a new ClusterIP service named my-cs (in headless mode)
  4. oc create service clusterip my-cs --clusterip="None"

oc create service externalname

Create an ExternalName service

Example usage

  1. # Create a new ExternalName service named my-ns
  2. oc create service externalname my-ns --external-name bar.com

oc create service loadbalancer

Create a LoadBalancer service

Example usage

  1. # Create a new LoadBalancer service named my-lbs
  2. oc create service loadbalancer my-lbs --tcp=5678:8080

oc create service nodeport

Create a NodePort service

Example usage

  1. # Create a new NodePort service named my-ns
  2. oc create service nodeport my-ns --tcp=5678:8080

oc create serviceaccount

Create a service account with the specified name

Example usage

  1. # Create a new service account named my-service-account
  2. oc create serviceaccount my-service-account

oc create user

Manually create a user (only needed if automatic creation is disabled)

Example usage

  1. # Create a user with the username "ajones" and the display name "Adam Jones"
  2. oc create user ajones --full-name="Adam Jones"

oc create useridentitymapping

Manually map an identity to a user

Example usage

  1. # Map the identity "acme_ldap:adamjones" to the user "ajones"
  2. oc create useridentitymapping acme_ldap:adamjones ajones

oc debug

Launch a new instance of a pod for debugging

Example usage

  1. # Start a shell session into a pod using the OpenShift tools image
  2. oc debug
  3. # Debug a currently running deployment by creating a new pod
  4. oc debug deploy/test
  5. # Debug a node as an administrator
  6. oc debug node/master-1
  7. # Launch a shell in a pod using the provided image stream tag
  8. oc debug istag/mysql:latest -n openshift
  9. # Test running a job as a non-root user
  10. oc debug job/test --as-user=1000000
  11. # Debug a specific failing container by running the env command in the 'second' container
  12. oc debug daemonset/test -c second -- /bin/env
  13. # See the pod that would be created to debug
  14. oc debug mypod-9xbc -o yaml
  15. # Debug a resource but launch the debug pod in another namespace
  16. # Note: Not all resources can be debugged using --to-namespace without modification. For example,
  17. # volumes and service accounts are namespace-dependent. Add '-o yaml' to output the debug pod definition
  18. # to disk. If necessary, edit the definition then run 'oc debug -f -' or run without --to-namespace
  19. oc debug mypod-9xbc --to-namespace testns

oc delete

Delete resources by file names, stdin, resources and names, or by resources and label selector

Example usage

  1. # Delete a pod using the type and name specified in pod.json
  2. oc delete -f ./pod.json
  3. # Delete resources from a directory containing kustomization.yaml - e.g. dir/kustomization.yaml
  4. oc delete -k dir
  5. # Delete a pod based on the type and name in the JSON passed into stdin
  6. cat pod.json | oc delete -f -
  7. # Delete pods and services with same names "baz" and "foo"
  8. oc delete pod,service baz foo
  9. # Delete pods and services with label name=myLabel
  10. oc delete pods,services -l name=myLabel
  11. # Delete a pod with minimal delay
  12. oc delete pod foo --now
  13. # Force delete a pod on a dead node
  14. oc delete pod foo --force
  15. # Delete all pods
  16. oc delete pods --all

oc describe

Show details of a specific resource or group of resources

Example usage

  1. # Describe a node
  2. oc describe nodes kubernetes-node-emt8.c.myproject.internal
  3. # Describe a pod
  4. oc describe pods/nginx
  5. # Describe a pod identified by type and name in "pod.json"
  6. oc describe -f pod.json
  7. # Describe all pods
  8. oc describe pods
  9. # Describe pods by label name=myLabel
  10. oc describe po -l name=myLabel
  11. # Describe all pods managed by the 'frontend' replication controller
  12. # (rc-created pods get the name of the rc as a prefix in the pod name)
  13. oc describe pods frontend

oc diff

Diff the live version against a would-be applied version

Example usage

  1. # Diff resources included in pod.json
  2. oc diff -f pod.json
  3. # Diff file read from stdin
  4. cat service.yaml | oc diff -f -

oc edit

Edit a resource on the server

Example usage

  1. # Edit the service named 'docker-registry'
  2. oc edit svc/docker-registry
  3. # Use an alternative editor
  4. KUBE_EDITOR="nano" oc edit svc/docker-registry
  5. # Edit the job 'myjob' in JSON using the v1 API format
  6. oc edit job.v1.batch/myjob -o json
  7. # Edit the deployment 'mydeployment' in YAML and save the modified config in its annotation
  8. oc edit deployment/mydeployment -o yaml --save-config

oc exec

Execute a command in a container

Example usage

  1. # Get output from running the 'date' command from pod mypod, using the first container by default
  2. oc exec mypod -- date
  3. # Get output from running the 'date' command in ruby-container from pod mypod
  4. oc exec mypod -c ruby-container -- date
  5. # Switch to raw terminal mode; sends stdin to 'bash' in ruby-container from pod mypod
  6. # and sends stdout/stderr from 'bash' back to the client
  7. oc exec mypod -c ruby-container -i -t -- bash -il
  8. # List contents of /usr from the first container of pod mypod and sort by modification time
  9. # If the command you want to execute in the pod has any flags in common (e.g. -i),
  10. # you must use two dashes (--) to separate your command's flags/arguments
  11. # Also note, do not surround your command and its flags/arguments with quotes
  12. # unless that is how you would execute it normally (i.e., do ls -t /usr, not "ls -t /usr")
  13. oc exec mypod -i -t -- ls -t /usr
  14. # Get output from running 'date' command from the first pod of the deployment mydeployment, using the first container by default
  15. oc exec deploy/mydeployment -- date
  16. # Get output from running 'date' command from the first pod of the service myservice, using the first container by default
  17. oc exec svc/myservice -- date

oc explain

Get documentation for a resource

Example usage

  1. # Get the documentation of the resource and its fields
  2. oc explain pods
  3. # Get the documentation of a specific field of a resource
  4. oc explain pods.spec.containers

oc expose

Expose a replicated application as a service or route

Example usage

  1. # Create a route based on service nginx. The new route will reuse nginx's labels
  2. oc expose service nginx
  3. # Create a route and specify your own label and route name
  4. oc expose service nginx -l name=myroute --name=fromdowntown
  5. # Create a route and specify a host name
  6. oc expose service nginx --hostname=www.example.com
  7. # Create a route with a wildcard
  8. oc expose service nginx --hostname=x.example.com --wildcard-policy=Subdomain
  9. # This would be equivalent to *.example.com. NOTE: only hosts are matched by the wildcard; subdomains would not be included
  10. # Expose a deployment configuration as a service and use the specified port
  11. oc expose dc ruby-hello-world --port=8080
  12. # Expose a service as a route in the specified path
  13. oc expose service nginx --path=/nginx
  14. # Expose a service using different generators
  15. oc expose service nginx --name=exposed-svc --port=12201 --protocol="TCP" --generator="service/v2"
  16. oc expose service nginx --name=my-route --port=12201 --generator="route/v1"
  17. # Exposing a service using the "route/v1" generator (default) will create a new exposed route with the "--name" provided
  18. # (or the name of the service otherwise). You may not specify a "--protocol" or "--target-port" option when using this generator

oc extract

Extract secrets or config maps to disk

Example usage

  1. # Extract the secret "test" to the current directory
  2. oc extract secret/test
  3. # Extract the config map "nginx" to the /tmp directory
  4. oc extract configmap/nginx --to=/tmp
  5. # Extract the config map "nginx" to STDOUT
  6. oc extract configmap/nginx --to=-
  7. # Extract only the key "nginx.conf" from config map "nginx" to the /tmp directory
  8. oc extract configmap/nginx --to=/tmp --keys=nginx.conf

oc get

Display one or many resources

Example usage

  1. # List all pods in ps output format
  2. oc get pods
  3. # List all pods in ps output format with more information (such as node name)
  4. oc get pods -o wide
  5. # List a single replication controller with specified NAME in ps output format
  6. oc get replicationcontroller web
  7. # List deployments in JSON output format, in the "v1" version of the "apps" API group
  8. oc get deployments.v1.apps -o json
  9. # List a single pod in JSON output format
  10. oc get -o json pod web-pod-13je7
  11. # List a pod identified by type and name specified in "pod.yaml" in JSON output format
  12. oc get -f pod.yaml -o json
  13. # List resources from a directory with kustomization.yaml - e.g. dir/kustomization.yaml
  14. oc get -k dir/
  15. # Return only the phase value of the specified pod
  16. oc get -o template pod/web-pod-13je7 --template={{.status.phase}}
  17. # List resource information in custom columns
  18. oc get pod test-pod -o custom-columns=CONTAINER:.spec.containers[0].name,IMAGE:.spec.containers[0].image
  19. # List all replication controllers and services together in ps output format
  20. oc get rc,services
  21. # List one or more resources by their type and names
  22. oc get rc/web service/frontend pods/web-pod-13je7

oc idle

Idle scalable resources

Example usage

  1. # Idle the scalable controllers associated with the services listed in to-idle.txt
  2. $ oc idle --resource-names-file to-idle.txt

oc image append

Add layers to images and push them to a registry

Example usage

  1. # Remove the entrypoint on the mysql:latest image
  2. oc image append --from mysql:latest --to myregistry.com/myimage:latest --image '{"Entrypoint":null}'
  3. # Add a new layer to the image
  4. oc image append --from mysql:latest --to myregistry.com/myimage:latest layer.tar.gz
  5. # Add a new layer to the image and store the result on disk
  6. # This results in $(pwd)/v2/mysql/blobs,manifests
  7. oc image append --from mysql:latest --to file://mysql:local layer.tar.gz
  8. # Add a new layer to the image and store the result on disk in a designated directory
  9. # This will result in $(pwd)/mysql-local/v2/mysql/blobs,manifests
  10. oc image append --from mysql:latest --to file://mysql:local --dir mysql-local layer.tar.gz
  11. # Add a new layer to an image that is stored on disk (~/mysql-local/v2/image exists)
  12. oc image append --from-dir ~/mysql-local --to myregistry.com/myimage:latest layer.tar.gz
  13. # Add a new layer to an image that was mirrored to the current directory on disk ($(pwd)/v2/image exists)
  14. oc image append --from-dir v2 --to myregistry.com/myimage:latest layer.tar.gz
  15. # Add a new layer to a multi-architecture image for an os/arch that is different from the system's os/arch
  16. # Note: Wildcard filter is not supported with append. Pass a single os/arch to append
  17. oc image append --from docker.io/library/busybox:latest --filter-by-os=linux/s390x --to myregistry.com/myimage:latest layer.tar.gz

oc image extract

Copy files from an image to the file system

Example usage

  1. # Extract the busybox image into the current directory
  2. oc image extract docker.io/library/busybox:latest
  3. # Extract the busybox image into a designated directory (must exist)
  4. oc image extract docker.io/library/busybox:latest --path /:/tmp/busybox
  5. # Extract the busybox image into the current directory for linux/s390x platform
  6. # Note: Wildcard filter is not supported with extract. Pass a single os/arch to extract
  7. oc image extract docker.io/library/busybox:latest --filter-by-os=linux/s390x
  8. # Extract a single file from the image into the current directory
  9. oc image extract docker.io/library/centos:7 --path /bin/bash:.
  10. # Extract all .repo files from the image's /etc/yum.repos.d/ folder into the current directory
  11. oc image extract docker.io/library/centos:7 --path /etc/yum.repos.d/*.repo:.
  12. # Extract all .repo files from the image's /etc/yum.repos.d/ folder into a designated directory (must exist)
  13. # This results in /tmp/yum.repos.d/*.repo on local system
  14. oc image extract docker.io/library/centos:7 --path /etc/yum.repos.d/*.repo:/tmp/yum.repos.d
  15. # Extract an image stored on disk into the current directory ($(pwd)/v2/busybox/blobs,manifests exists)
  16. # --confirm is required because the current directory is not empty
  17. oc image extract file://busybox:local --confirm
  18. # Extract an image stored on disk in a directory other than $(pwd)/v2 into the current directory
  19. # --confirm is required because the current directory is not empty ($(pwd)/busybox-mirror-dir/v2/busybox exists)
  20. oc image extract file://busybox:local --dir busybox-mirror-dir --confirm
  21. # Extract an image stored on disk in a directory other than $(pwd)/v2 into a designated directory (must exist)
  22. oc image extract file://busybox:local --dir busybox-mirror-dir --path /:/tmp/busybox
  23. # Extract the last layer in the image
  24. oc image extract docker.io/library/centos:7[-1]
  25. # Extract the first three layers of the image
  26. oc image extract docker.io/library/centos:7[:3]
  27. # Extract the last three layers of the image
  28. oc image extract docker.io/library/centos:7[-3:]

oc image info

Display information about an image

Example usage

  1. # Show information about an image
  2. oc image info quay.io/openshift/cli:latest
  3. # Show information about images matching a wildcard
  4. oc image info quay.io/openshift/cli:4.*
  5. # Show information about a file mirrored to disk under DIR
  6. oc image info --dir=DIR file://library/busybox:latest
  7. # Select which image from a multi-OS image to show
  8. oc image info library/busybox:latest --filter-by-os=linux/arm64

oc image mirror

Mirror images from one repository to another

Example usage

  1. # Copy image to another tag
  2. oc image mirror myregistry.com/myimage:latest myregistry.com/myimage:stable
  3. # Copy image to another registry
  4. oc image mirror myregistry.com/myimage:latest docker.io/myrepository/myimage:stable
  5. # Copy all tags starting with mysql to the destination repository
  6. oc image mirror myregistry.com/myimage:mysql* docker.io/myrepository/myimage
  7. # Copy image to disk, creating a directory structure that can be served as a registry
  8. oc image mirror myregistry.com/myimage:latest file://myrepository/myimage:latest
  9. # Copy image to S3 (pull from <bucket>.s3.amazonaws.com/image:latest)
  10. oc image mirror myregistry.com/myimage:latest s3://s3.amazonaws.com/<region>/<bucket>/image:latest
  11. # Copy image to S3 without setting a tag (pull via @<digest>)
  12. oc image mirror myregistry.com/myimage:latest s3://s3.amazonaws.com/<region>/<bucket>/image
  13. # Copy image to multiple locations
  14. oc image mirror myregistry.com/myimage:latest docker.io/myrepository/myimage:stable \
  15. docker.io/myrepository/myimage:dev
  16. # Copy multiple images
  17. oc image mirror myregistry.com/myimage:latest=myregistry.com/other:test \
  18. myregistry.com/myimage:new=myregistry.com/other:target
  19. # Copy manifest list of a multi-architecture image, even if only a single image is found
  20. oc image mirror myregistry.com/myimage:latest=myregistry.com/other:test \
  21. --keep-manifest-list=true
  22. # Copy specific os/arch manifest of a multi-architecture image
  23. # Run 'oc image info myregistry.com/myimage:latest' to see available os/arch for multi-arch images
  24. # Note that with multi-arch images, this results in a new manifest list digest that includes only
  25. # the filtered manifests
  26. oc image mirror myregistry.com/myimage:latest=myregistry.com/other:test \
  27. --filter-by-os=os/arch
  28. # Copy all os/arch manifests of a multi-architecture image
  29. # Run 'oc image info myregistry.com/myimage:latest' to see list of os/arch manifests that will be mirrored
  30. oc image mirror myregistry.com/myimage:latest=myregistry.com/other:test \
  31. --keep-manifest-list=true
  32. # Note the above command is equivalent to
  33. oc image mirror myregistry.com/myimage:latest=myregistry.com/other:test \
  34. --filter-by-os=.*

oc import-image

Import images from a container image registry

Example usage

  1. # Import tag latest into a new image stream
  2. oc import-image mystream --from=registry.io/repo/image:latest --confirm
  3. # Update imported data for tag latest in an already existing image stream
  4. oc import-image mystream
  5. # Update imported data for tag stable in an already existing image stream
  6. oc import-image mystream:stable
  7. # Update imported data for all tags in an existing image stream
  8. oc import-image mystream --all
  9. # Import all tags into a new image stream
  10. oc import-image mystream --from=registry.io/repo/image --all --confirm
  11. # Import all tags into a new image stream using a custom timeout
  12. oc --request-timeout=5m import-image mystream --from=registry.io/repo/image --all --confirm

oc kustomize

Build a kustomization target from a directory or URL.

Example usage

  1. # Build the current working directory
  2. oc kustomize
  3. # Build some shared configuration directory
  4. oc kustomize /home/config/production
  5. # Build from github
  6. oc kustomize https://github.com/kubernetes-sigs/kustomize.git/examples/helloWorld?ref=v1.0.6

oc label

Update the labels on a resource

Example usage

  1. # Update pod 'foo' with the label 'unhealthy' and the value 'true'
  2. oc label pods foo unhealthy=true
  3. # Update pod 'foo' with the label 'status' and the value 'unhealthy', overwriting any existing value
  4. oc label --overwrite pods foo status=unhealthy
  5. # Update all pods in the namespace
  6. oc label pods --all status=unhealthy
  7. # Update a pod identified by the type and name in "pod.json"
  8. oc label -f pod.json status=unhealthy
  9. # Update pod 'foo' only if the resource is unchanged from version 1
  10. oc label pods foo status=unhealthy --resource-version=1
  11. # Update pod 'foo' by removing a label named 'bar' if it exists
  12. # Does not require the --overwrite flag
  13. oc label pods foo bar-

oc login

Log in to a server

Example usage

  1. # Log in interactively
  2. oc login --username=myuser
  3. # Log in to the given server with the given certificate authority file
  4. oc login localhost:8443 --certificate-authority=/path/to/cert.crt
  5. # Log in to the given server with the given credentials (will not prompt interactively)
  6. oc login localhost:8443 --username=myuser --password=mypass

oc logout

End the current server session

Example usage

  1. # Log out
  2. oc logout

oc logs

Print the logs for a container in a pod

Example usage

  1. # Start streaming the logs of the most recent build of the openldap build config
  2. oc logs -f bc/openldap
  3. # Start streaming the logs of the latest deployment of the mysql deployment config
  4. oc logs -f dc/mysql
  5. # Get the logs of the first deployment for the mysql deployment config. Note that logs
  6. # from older deployments may not exist either because the deployment was successful
  7. # or due to deployment pruning or manual deletion of the deployment
  8. oc logs --version=1 dc/mysql
  9. # Return a snapshot of ruby-container logs from pod backend
  10. oc logs backend -c ruby-container
  11. # Start streaming of ruby-container logs from pod backend
  12. oc logs -f pod/backend -c ruby-container

oc new-app

Create a new application

Example usage

  1. # List all local templates and image streams that can be used to create an app
  2. oc new-app --list
  3. # Create an application based on the source code in the current git repository (with a public remote) and a container image
  4. oc new-app . --image=registry/repo/langimage
  5. # Create an application myapp with Docker based build strategy expecting binary input
  6. oc new-app --strategy=docker --binary --name myapp
  7. # Create a Ruby application based on the provided [image]~[source code] combination
  8. oc new-app centos/ruby-25-centos7~https://github.com/sclorg/ruby-ex.git
  9. # Use the public container registry MySQL image to create an app. Generated artifacts will be labeled with db=mysql
  10. oc new-app mysql MYSQL_USER=user MYSQL_PASSWORD=pass MYSQL_DATABASE=testdb -l db=mysql
  11. # Use a MySQL image in a private registry to create an app and override application artifacts' names
  12. oc new-app --image=myregistry.com/mycompany/mysql --name=private
  13. # Create an application from a remote repository using its beta4 branch
  14. oc new-app https://github.com/openshift/ruby-hello-world#beta4
  15. # Create an application based on a stored template, explicitly setting a parameter value
  16. oc new-app --template=ruby-helloworld-sample --param=MYSQL_USER=admin
  17. # Create an application from a remote repository and specify a context directory
  18. oc new-app https://github.com/youruser/yourgitrepo --context-dir=src/build
  19. # Create an application from a remote private repository and specify which existing secret to use
  20. oc new-app https://github.com/youruser/yourgitrepo --source-secret=yoursecret
  21. # Create an application based on a template file, explicitly setting a parameter value
  22. oc new-app --file=./example/myapp/template.json --param=MYSQL_USER=admin
  23. # Search all templates, image streams, and container images for the ones that match "ruby"
  24. oc new-app --search ruby
  25. # Search for "ruby", but only in stored templates (--template, --image-stream and --image
  26. # can be used to filter search results)
  27. oc new-app --search --template=ruby
  28. # Search for "ruby" in stored templates and print the output as YAML
  29. oc new-app --search --template=ruby --output=yaml

oc new-build

Create a new build configuration

Example usage

  1. # Create a build config based on the source code in the current git repository (with a public
  2. # remote) and a container image
  3. oc new-build . --image=repo/langimage
  4. # Create a NodeJS build config based on the provided [image]~[source code] combination
  5. oc new-build centos/nodejs-8-centos7~https://github.com/sclorg/nodejs-ex.git
  6. # Create a build config from a remote repository using its beta2 branch
  7. oc new-build https://github.com/openshift/ruby-hello-world#beta2
  8. # Create a build config using a Dockerfile specified as an argument
  9. oc new-build -D $'FROM centos:7\nRUN yum install -y httpd'
  10. # Create a build config from a remote repository and add custom environment variables
  11. oc new-build https://github.com/openshift/ruby-hello-world -e RACK_ENV=development
  12. # Create a build config from a remote private repository and specify which existing secret to use
  13. oc new-build https://github.com/youruser/yourgitrepo --source-secret=yoursecret
  14. # Create a build config from a remote repository and inject the npmrc into a build
  15. oc new-build https://github.com/openshift/ruby-hello-world --build-secret npmrc:.npmrc
  16. # Create a build config from a remote repository and inject environment data into a build
  17. oc new-build https://github.com/openshift/ruby-hello-world --build-config-map env:config
  18. # Create a build config that gets its input from a remote repository and another container image
  19. oc new-build https://github.com/openshift/ruby-hello-world --source-image=openshift/jenkins-1-centos7 --source-image-path=/var/lib/jenkins:tmp

oc new-project

Request a new project

Example usage

  1. # Create a new project with minimal information
  2. oc new-project web-team-dev
  3. # Create a new project with a display name and description
  4. oc new-project web-team-dev --display-name="Web Team Development" --description="Development project for the web team."

oc observe

Observe changes to resources and react to them (experimental)

Example usage

  1. # Observe changes to services
  2. oc observe services
  3. # Observe changes to services, including the clusterIP and invoke a script for each
  4. oc observe services --template '{ .spec.clusterIP }' -- register_dns.sh
  5. # Observe changes to services filtered by a label selector
  6. oc observe namespaces -l regist-dns=true --template '{ .spec.clusterIP }' -- register_dns.sh

oc patch

Update fields of a resource

Example usage

  1. # Partially update a node using a strategic merge patch, specifying the patch as JSON
  2. oc patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'
  3. # Partially update a node using a strategic merge patch, specifying the patch as YAML
  4. oc patch node k8s-node-1 -p $'spec:\n unschedulable: true'
  5. # Partially update a node identified by the type and name specified in "node.json" using strategic merge patch
  6. oc patch -f node.json -p '{"spec":{"unschedulable":true}}'
  7. # Update a container's image; spec.containers[*].name is required because it's a merge key
  8. oc patch pod valid-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}'
  9. # Update a container's image using a JSON patch with positional arrays
  10. oc patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]'

oc policy add-role-to-user

Add a role to users or service accounts for the current project

Example usage

  1. # Add the 'view' role to user1 for the current project
  2. oc policy add-role-to-user view user1
  3. # Add the 'edit' role to serviceaccount1 for the current project
  4. oc policy add-role-to-user edit -z serviceaccount1

oc policy scc-review

Check which service account can create a pod

Example usage

  1. # Check whether service accounts sa1 and sa2 can admit a pod with a template pod spec specified in my_resource.yaml
  2. # Service Account specified in myresource.yaml file is ignored
  3. oc policy scc-review -z sa1,sa2 -f my_resource.yaml
  4. # Check whether service accounts system:serviceaccount:bob:default can admit a pod with a template pod spec specified in my_resource.yaml
  5. oc policy scc-review -z system:serviceaccount:bob:default -f my_resource.yaml
  6. # Check whether the service account specified in my_resource_with_sa.yaml can admit the pod
  7. oc policy scc-review -f my_resource_with_sa.yaml
  8. # Check whether the default service account can admit the pod; default is taken since no service account is defined in myresource_with_no_sa.yaml
  9. oc policy scc-review -f myresource_with_no_sa.yaml

oc policy scc-subject-review

Check whether a user or a service account can create a pod

Example usage

  1. # Check whether user bob can create a pod specified in myresource.yaml
  2. oc policy scc-subject-review -u bob -f myresource.yaml
  3. # Check whether user bob who belongs to projectAdmin group can create a pod specified in myresource.yaml
  4. oc policy scc-subject-review -u bob -g projectAdmin -f myresource.yaml
  5. # Check whether a service account specified in the pod template spec in myresourcewithsa.yaml can create the pod
  6. oc policy scc-subject-review -f myresourcewithsa.yaml

oc port-forward

Forward one or more local ports to a pod

Example usage

  1. # Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
  2. oc port-forward pod/mypod 5000 6000
  3. # Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in a pod selected by the deployment
  4. oc port-forward deployment/mydeployment 5000 6000
  5. # Listen on port 8443 locally, forwarding to the targetPort of the service's port named "https" in a pod selected by the service
  6. oc port-forward service/myservice 8443:https
  7. # Listen on port 8888 locally, forwarding to 5000 in the pod
  8. oc port-forward pod/mypod 8888:5000
  9. # Listen on port 8888 on all addresses, forwarding to 5000 in the pod
  10. oc port-forward --address 0.0.0.0 pod/mypod 8888:5000
  11. # Listen on port 8888 on localhost and selected IP, forwarding to 5000 in the pod
  12. oc port-forward --address localhost,10.19.21.23 pod/mypod 8888:5000
  13. # Listen on a random port locally, forwarding to 5000 in the pod
  14. oc port-forward pod/mypod :5000

oc process

Process a template into list of resources

Example usage

  1. # Convert the template.json file into a resource list and pass to create
  2. oc process -f template.json | oc create -f -
  3. # Process a file locally instead of contacting the server
  4. oc process -f template.json --local -o yaml
  5. # Process template while passing a user-defined label
  6. oc process -f template.json -l name=mytemplate
  7. # Convert a stored template into a resource list
  8. oc process foo
  9. # Convert a stored template into a resource list by setting/overriding parameter values
  10. oc process foo PARM1=VALUE1 PARM2=VALUE2
  11. # Convert a template stored in different namespace into a resource list
  12. oc process openshift//foo
  13. # Convert template.json into a resource list
  14. cat template.json | oc process -f -

oc project

Switch to another project

Example usage

  1. # Switch to the 'myapp' project
  2. oc project myapp
  3. # Display the project currently in use
  4. oc project

oc projects

Display existing projects

Example usage

  1. # List all projects
  2. oc projects

oc proxy

Run a proxy to the Kubernetes API server

Example usage

  1. # To proxy all of the Kubernetes API and nothing else
  2. oc proxy --api-prefix=/
  3. # To proxy only part of the Kubernetes API and also some static files
  4. # You can get pods info with 'curl localhost:8001/api/v1/pods'
  5. oc proxy --www=/my/files --www-prefix=/static/ --api-prefix=/api/
  6. # To proxy the entire Kubernetes API at a different root
  7. # You can get pods info with 'curl localhost:8001/custom/api/v1/pods'
  8. oc proxy --api-prefix=/custom/
  9. # Run a proxy to the Kubernetes API server on port 8011, serving static content from ./local/www/
  10. oc proxy --port=8011 --www=./local/www/
  11. # Run a proxy to the Kubernetes API server on an arbitrary local port
  12. # The chosen port for the server will be output to stdout
  13. oc proxy --port=0
  14. # Run a proxy to the Kubernetes API server, changing the API prefix to k8s-api
  15. # This makes e.g. the pods API available at localhost:8001/k8s-api/v1/pods/
  16. oc proxy --api-prefix=/k8s-api

oc registry info

Print information about the integrated registry

Example usage

  1. # Display information about the integrated registry
  2. oc registry info

oc registry login

Log in to the integrated registry

Example usage

  1. # Log in to the integrated registry
  2. oc registry login
  3. # Log in as the default service account in the current namespace
  4. oc registry login -z default
  5. # Log in to different registry using BASIC auth credentials
  6. oc registry login --registry quay.io/myregistry --auth-basic=USER:PASS

oc replace

Replace a resource by file name or stdin

Example usage

  1. # Replace a pod using the data in pod.json
  2. oc replace -f ./pod.json
  3. # Replace a pod based on the JSON passed into stdin
  4. cat pod.json | oc replace -f -
  5. # Update a single-container pod's image version (tag) to v4
  6. oc get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | oc replace -f -
  7. # Force replace, delete and then re-create the resource
  8. oc replace --force -f ./pod.json

oc rollback

Revert part of an application back to a previous deployment

Example usage

  1. # Perform a rollback to the last successfully completed deployment for a deployment config
  2. oc rollback frontend
  3. # See what a rollback to version 3 will look like, but do not perform the rollback
  4. oc rollback frontend --to-version=3 --dry-run
  5. # Perform a rollback to a specific deployment
  6. oc rollback frontend-2
  7. # Perform the rollback manually by piping the JSON of the new config back to oc
  8. oc rollback frontend -o json | oc replace dc/frontend -f -
  9. # Print the updated deployment configuration in JSON format instead of performing the rollback
  10. oc rollback frontend -o json

oc rollout cancel

Cancel the in-progress deployment

Example usage

  1. # Cancel the in-progress deployment based on 'nginx'
  2. oc rollout cancel dc/nginx

oc rollout history

View rollout history

Example usage

  1. # View the rollout history of a deployment
  2. oc rollout history dc/nginx
  3. # View the details of deployment revision 3
  4. oc rollout history dc/nginx --revision=3

oc rollout latest

Start a new rollout for a deployment config with the latest state from its triggers

Example usage

  1. # Start a new rollout based on the latest images defined in the image change triggers
  2. oc rollout latest dc/nginx
  3. # Print the rolled out deployment config
  4. oc rollout latest dc/nginx -o json

oc rollout pause

Mark the provided resource as paused

Example usage

  1. # Mark the nginx deployment as paused. Any current state of
  2. # the deployment will continue its function, new updates to the deployment will not
  3. # have an effect as long as the deployment is paused
  4. oc rollout pause dc/nginx

oc rollout restart

Restart a resource

Example usage

  1. # Restart a deployment
  2. oc rollout restart deployment/nginx
  3. # Restart a daemon set
  4. oc rollout restart daemonset/abc

oc rollout resume

Resume a paused resource

Example usage

  1. # Resume an already paused deployment
  2. oc rollout resume dc/nginx

oc rollout retry

Retry the latest failed rollout

Example usage

  1. # Retry the latest failed deployment based on 'frontend'
  2. # The deployer pod and any hook pods are deleted for the latest failed deployment
  3. oc rollout retry dc/frontend

oc rollout status

Show the status of the rollout

Example usage

  1. # Watch the status of the latest rollout
  2. oc rollout status dc/nginx

oc rollout undo

Undo a previous rollout

Example usage

  1. # Roll back to the previous deployment
  2. oc rollout undo dc/nginx
  3. # Roll back to deployment revision 3. The replication controller for that version must exist
  4. oc rollout undo dc/nginx --to-revision=3

oc rsh

Start a shell session in a container

Example usage

  1. # Open a shell session on the first container in pod 'foo'
  2. oc rsh foo
  3. # Open a shell session on the first container in pod 'foo' and namespace 'bar'
  4. # (Note that oc client specific arguments must come before the resource name and its arguments)
  5. oc rsh -n bar foo
  6. # Run the command 'cat /etc/resolv.conf' inside pod 'foo'
  7. oc rsh foo cat /etc/resolv.conf
  8. # See the configuration of your internal registry
  9. oc rsh dc/docker-registry cat config.yml
  10. # Open a shell session on the container named 'index' inside a pod of your job
  11. oc rsh -c index job/sheduled

oc rsync

Copy files between a local file system and a pod

Example usage

  1. # Synchronize a local directory with a pod directory
  2. oc rsync ./local/dir/ POD:/remote/dir
  3. # Synchronize a pod directory with a local directory
  4. oc rsync POD:/remote/dir/ ./local/dir

oc run

Run a particular image on the cluster

Example usage

  1. # Start a nginx pod
  2. oc run nginx --image=nginx
  3. # Start a hazelcast pod and let the container expose port 5701
  4. oc run hazelcast --image=hazelcast/hazelcast --port=5701
  5. # Start a hazelcast pod and set environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default" in the container
  6. oc run hazelcast --image=hazelcast/hazelcast --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default"
  7. # Start a hazelcast pod and set labels "app=hazelcast" and "env=prod" in the container
  8. oc run hazelcast --image=hazelcast/hazelcast --labels="app=hazelcast,env=prod"
  9. # Dry run; print the corresponding API objects without creating them
  10. oc run nginx --image=nginx --dry-run=client
  11. # Start a nginx pod, but overload the spec with a partial set of values parsed from JSON
  12. oc run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { ... } }'
  13. # Start a busybox pod and keep it in the foreground, don't restart it if it exits
  14. oc run -i -t busybox --image=busybox --restart=Never
  15. # Start the nginx pod using the default command, but use custom arguments (arg1 .. argN) for that command
  16. oc run nginx --image=nginx -- <arg1> <arg2> ... <argN>
  17. # Start the nginx pod using a different command and custom arguments
  18. oc run nginx --image=nginx --command -- <cmd> <arg1> ... <argN>

oc scale

Set a new size for a deployment, replica set, or replication controller

Example usage

  1. # Scale a replica set named 'foo' to 3
  2. oc scale --replicas=3 rs/foo
  3. # Scale a resource identified by type and name specified in "foo.yaml" to 3
  4. oc scale --replicas=3 -f foo.yaml
  5. # If the deployment named mysql's current size is 2, scale mysql to 3
  6. oc scale --current-replicas=2 --replicas=3 deployment/mysql
  7. # Scale multiple replication controllers
  8. oc scale --replicas=5 rc/foo rc/bar rc/baz
  9. # Scale stateful set named 'web' to 3
  10. oc scale --replicas=3 statefulset/web

Link secrets to a service account

Example usage

  1. # Add an image pull secret to a service account to automatically use it for pulling pod images
  2. oc secrets link serviceaccount-name pull-secret --for=pull
  3. # Add an image pull secret to a service account to automatically use it for both pulling and pushing build images
  4. oc secrets link builder builder-image-secret --for=pull,mount

Detach secrets from a service account

Example usage

  1. # Unlink a secret currently associated with a service account
  2. oc secrets unlink serviceaccount-name secret-name another-secret-name ...

oc serviceaccounts create-kubeconfig

Generate a kubeconfig file for a service account

Example usage

  1. # Create a kubeconfig file for service account 'default'
  2. oc serviceaccounts create-kubeconfig 'default' > default.kubeconfig

oc serviceaccounts get-token

Get a token assigned to a service account

Example usage

  1. # Get the service account token from service account 'default'
  2. oc serviceaccounts get-token 'default'

oc serviceaccounts new-token

Generate a new token for a service account

Example usage

  1. # Generate a new token for service account 'default'
  2. oc serviceaccounts new-token 'default'
  3. # Generate a new token for service account 'default' and apply
  4. # labels 'foo' and 'bar' to the new token for identification
  5. oc serviceaccounts new-token 'default' --labels foo=foo-value,bar=bar-value

oc set build-hook

Update a build hook on a build config

Example usage

  1. # Clear post-commit hook on a build config
  2. oc set build-hook bc/mybuild --post-commit --remove
  3. # Set the post-commit hook to execute a test suite using a new entrypoint
  4. oc set build-hook bc/mybuild --post-commit --command -- /bin/bash -c /var/lib/test-image.sh
  5. # Set the post-commit hook to execute a shell script
  6. oc set build-hook bc/mybuild --post-commit --script="/var/lib/test-image.sh param1 param2 && /var/lib/done.sh"

oc set build-secret

Update a build secret on a build config

Example usage

  1. # Clear the push secret on a build config
  2. oc set build-secret --push --remove bc/mybuild
  3. # Set the pull secret on a build config
  4. oc set build-secret --pull bc/mybuild mysecret
  5. # Set the push and pull secret on a build config
  6. oc set build-secret --push --pull bc/mybuild mysecret
  7. # Set the source secret on a set of build configs matching a selector
  8. oc set build-secret --source -l app=myapp gitsecret

oc set data

Update the data within a config map or secret

Example usage

  1. # Set the 'password' key of a secret
  2. oc set data secret/foo password=this_is_secret
  3. # Remove the 'password' key from a secret
  4. oc set data secret/foo password-
  5. # Update the 'haproxy.conf' key of a config map from a file on disk
  6. oc set data configmap/bar --from-file=../haproxy.conf
  7. # Update a secret with the contents of a directory, one key per file
  8. oc set data secret/foo --from-file=secret-dir

oc set deployment-hook

Update a deployment hook on a deployment config

Example usage

  1. # Clear pre and post hooks on a deployment config
  2. oc set deployment-hook dc/myapp --remove --pre --post
  3. # Set the pre deployment hook to execute a db migration command for an application
  4. # using the data volume from the application
  5. oc set deployment-hook dc/myapp --pre --volumes=data -- /var/lib/migrate-db.sh
  6. # Set a mid deployment hook along with additional environment variables
  7. oc set deployment-hook dc/myapp --mid --volumes=data -e VAR1=value1 -e VAR2=value2 -- /var/lib/prepare-deploy.sh

oc set env

Update environment variables on a pod template

Example usage

  1. # Update deployment config 'myapp' with a new environment variable
  2. oc set env dc/myapp STORAGE_DIR=/local
  3. # List the environment variables defined on a build config 'sample-build'
  4. oc set env bc/sample-build --list
  5. # List the environment variables defined on all pods
  6. oc set env pods --all --list
  7. # Output modified build config in YAML
  8. oc set env bc/sample-build STORAGE_DIR=/data -o yaml
  9. # Update all containers in all replication controllers in the project to have ENV=prod
  10. oc set env rc --all ENV=prod
  11. # Import environment from a secret
  12. oc set env --from=secret/mysecret dc/myapp
  13. # Import environment from a config map with a prefix
  14. oc set env --from=configmap/myconfigmap --prefix=MYSQL_ dc/myapp
  15. # Remove the environment variable ENV from container 'c1' in all deployment configs
  16. oc set env dc --all --containers="c1" ENV-
  17. # Remove the environment variable ENV from a deployment config definition on disk and
  18. # update the deployment config on the server
  19. oc set env -f dc.json ENV-
  20. # Set some of the local shell environment into a deployment config on the server
  21. oc set env | grep RAILS_ | oc env -e - dc/myapp

oc set image

Update the image of a pod template

Example usage

  1. # Set a deployment configs's nginx container image to 'nginx:1.9.1', and its busybox container image to 'busybox'.
  2. oc set image dc/nginx busybox=busybox nginx=nginx:1.9.1
  3. # Set a deployment configs's app container image to the image referenced by the imagestream tag 'openshift/ruby:2.3'.
  4. oc set image dc/myapp app=openshift/ruby:2.3 --source=imagestreamtag
  5. # Update all deployments' and rc's nginx container's image to 'nginx:1.9.1'
  6. oc set image deployments,rc nginx=nginx:1.9.1 --all
  7. # Update image of all containers of daemonset abc to 'nginx:1.9.1'
  8. oc set image daemonset abc *=nginx:1.9.1
  9. # Print result (in yaml format) of updating nginx container image from local file, without hitting the server
  10. oc set image -f path/to/file.yaml nginx=nginx:1.9.1 --local -o yaml

oc set image-lookup

Change how images are resolved when deploying applications

Example usage

  1. # Print all of the image streams and whether they resolve local names
  2. oc set image-lookup
  3. # Use local name lookup on image stream mysql
  4. oc set image-lookup mysql
  5. # Force a deployment to use local name lookup
  6. oc set image-lookup deploy/mysql
  7. # Show the current status of the deployment lookup
  8. oc set image-lookup deploy/mysql --list
  9. # Disable local name lookup on image stream mysql
  10. oc set image-lookup mysql --enabled=false
  11. # Set local name lookup on all image streams
  12. oc set image-lookup --all

oc set probe

Update a probe on a pod template

Example usage

  1. # Clear both readiness and liveness probes off all containers
  2. oc set probe dc/myapp --remove --readiness --liveness
  3. # Set an exec action as a liveness probe to run 'echo ok'
  4. oc set probe dc/myapp --liveness -- echo ok
  5. # Set a readiness probe to try to open a TCP socket on 3306
  6. oc set probe rc/mysql --readiness --open-tcp=3306
  7. # Set an HTTP startup probe for port 8080 and path /healthz over HTTP on the pod IP
  8. oc set probe dc/webapp --startup --get-url=http://:8080/healthz
  9. # Set an HTTP readiness probe for port 8080 and path /healthz over HTTP on the pod IP
  10. oc set probe dc/webapp --readiness --get-url=http://:8080/healthz
  11. # Set an HTTP readiness probe over HTTPS on 127.0.0.1 for a hostNetwork pod
  12. oc set probe dc/router --readiness --get-url=https://127.0.0.1:1936/stats
  13. # Set only the initial-delay-seconds field on all deployments
  14. oc set probe dc --all --readiness --initial-delay-seconds=30

oc set resources

Update resource requests/limits on objects with pod templates

Example usage

  1. # Set a deployments nginx container CPU limits to "200m and memory to 512Mi"
  2. oc set resources deployment nginx -c=nginx --limits=cpu=200m,memory=512Mi
  3. # Set the resource request and limits for all containers in nginx
  4. oc set resources deployment nginx --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=256Mi
  5. # Remove the resource requests for resources on containers in nginx
  6. oc set resources deployment nginx --limits=cpu=0,memory=0 --requests=cpu=0,memory=0
  7. # Print the result (in YAML format) of updating nginx container limits locally, without hitting the server
  8. oc set resources -f path/to/file.yaml --limits=cpu=200m,memory=512Mi --local -o yaml

oc set route-backends

Update the backends for a route

Example usage

  1. # Print the backends on the route 'web'
  2. oc set route-backends web
  3. # Set two backend services on route 'web' with 2/3rds of traffic going to 'a'
  4. oc set route-backends web a=2 b=1
  5. # Increase the traffic percentage going to b by 10%% relative to a
  6. oc set route-backends web --adjust b=+10%%
  7. # Set traffic percentage going to b to 10%% of the traffic going to a
  8. oc set route-backends web --adjust b=10%%
  9. # Set weight of b to 10
  10. oc set route-backends web --adjust b=10
  11. # Set the weight to all backends to zero
  12. oc set route-backends web --zero

oc set selector

Set the selector on a resource

Example usage

  1. # Set the labels and selector before creating a deployment/service pair.
  2. oc create service clusterip my-svc --clusterip="None" -o yaml --dry-run | oc set selector --local -f - 'environment=qa' -o yaml | oc create -f -
  3. oc create deployment my-dep -o yaml --dry-run | oc label --local -f - environment=qa -o yaml | oc create -f -

oc set serviceaccount

Update the service account of a resource

Example usage

  1. # Set deployment nginx-deployment's service account to serviceaccount1
  2. oc set serviceaccount deployment nginx-deployment serviceaccount1
  3. # Print the result (in YAML format) of updated nginx deployment with service account from a local file, without hitting the API server
  4. oc set sa -f nginx-deployment.yaml serviceaccount1 --local --dry-run -o yaml

oc set subject

Update the user, group, or service account in a role binding or cluster role binding

Example usage

  1. # Update a cluster role binding for serviceaccount1
  2. oc set subject clusterrolebinding admin --serviceaccount=namespace:serviceaccount1
  3. # Update a role binding for user1, user2, and group1
  4. oc set subject rolebinding admin --user=user1 --user=user2 --group=group1
  5. # Print the result (in YAML format) of updating role binding subjects locally, without hitting the server
  6. oc create rolebinding admin --role=admin --user=admin -o yaml --dry-run | oc set subject --local -f - --user=foo -o yaml

oc set triggers

Update the triggers on one or more objects

Example usage

  1. # Print the triggers on the deployment config 'myapp'
  2. oc set triggers dc/myapp
  3. # Set all triggers to manual
  4. oc set triggers dc/myapp --manual
  5. # Enable all automatic triggers
  6. oc set triggers dc/myapp --auto
  7. # Reset the GitHub webhook on a build to a new, generated secret
  8. oc set triggers bc/webapp --from-github
  9. oc set triggers bc/webapp --from-webhook
  10. # Remove all triggers
  11. oc set triggers bc/webapp --remove-all
  12. # Stop triggering on config change
  13. oc set triggers dc/myapp --from-config --remove
  14. # Add an image trigger to a build config
  15. oc set triggers bc/webapp --from-image=namespace1/image:latest
  16. # Add an image trigger to a stateful set on the main container
  17. oc set triggers statefulset/db --from-image=namespace1/image:latest -c main

oc set volumes

Update volumes on a pod template

Example usage

  1. # List volumes defined on all deployment configs in the current project
  2. oc set volume dc --all
  3. # Add a new empty dir volume to deployment config (dc) 'myapp' mounted under
  4. # /var/lib/myapp
  5. oc set volume dc/myapp --add --mount-path=/var/lib/myapp
  6. # Use an existing persistent volume claim (pvc) to overwrite an existing volume 'v1'
  7. oc set volume dc/myapp --add --name=v1 -t pvc --claim-name=pvc1 --overwrite
  8. # Remove volume 'v1' from deployment config 'myapp'
  9. oc set volume dc/myapp --remove --name=v1
  10. # Create a new persistent volume claim that overwrites an existing volume 'v1'
  11. oc set volume dc/myapp --add --name=v1 -t pvc --claim-size=1G --overwrite
  12. # Change the mount point for volume 'v1' to /data
  13. oc set volume dc/myapp --add --name=v1 -m /data --overwrite
  14. # Modify the deployment config by removing volume mount "v1" from container "c1"
  15. # (and by removing the volume "v1" if no other containers have volume mounts that reference it)
  16. oc set volume dc/myapp --remove --name=v1 --containers=c1
  17. # Add new volume based on a more complex volume source (AWS EBS, GCE PD,
  18. # Ceph, Gluster, NFS, ISCSI, ...)
  19. oc set volume dc/myapp --add -m /data --source=<json-string>

oc start-build

Start a new build

Example usage

  1. # Starts build from build config "hello-world"
  2. oc start-build hello-world
  3. # Starts build from a previous build "hello-world-1"
  4. oc start-build --from-build=hello-world-1
  5. # Use the contents of a directory as build input
  6. oc start-build hello-world --from-dir=src/
  7. # Send the contents of a Git repository to the server from tag 'v2'
  8. oc start-build hello-world --from-repo=../hello-world --commit=v2
  9. # Start a new build for build config "hello-world" and watch the logs until the build
  10. # completes or fails
  11. oc start-build hello-world --follow
  12. # Start a new build for build config "hello-world" and wait until the build completes. It
  13. # exits with a non-zero return code if the build fails
  14. oc start-build hello-world --wait

oc status

Show an overview of the current project

Example usage

  1. # See an overview of the current project
  2. oc status
  3. # Export the overview of the current project in an svg file
  4. oc status -o dot | dot -T svg -o project.svg
  5. # See an overview of the current project including details for any identified issues
  6. oc status --suggest

oc tag

Tag existing images into image streams

Example usage

  1. # Tag the current image for the image stream 'openshift/ruby' and tag '2.0' into the image stream 'yourproject/ruby with tag 'tip'
  2. oc tag openshift/ruby:2.0 yourproject/ruby:tip
  3. # Tag a specific image
  4. oc tag openshift/ruby@sha256:6b646fa6bf5e5e4c7fa41056c27910e679c03ebe7f93e361e6515a9da7e258cc yourproject/ruby:tip
  5. # Tag an external container image
  6. oc tag --source=docker openshift/origin-control-plane:latest yourproject/ruby:tip
  7. # Tag an external container image and request pullthrough for it
  8. oc tag --source=docker openshift/origin-control-plane:latest yourproject/ruby:tip --reference-policy=local
  9. # Remove the specified spec tag from an image stream
  10. oc tag openshift/origin-control-plane:latest -d

oc version

Print the client and server version information

Example usage

  1. # Print the OpenShift client, kube-apiserver, and openshift-apiserver version information for the current context
  2. oc version
  3. # Print the OpenShift client, kube-apiserver, and openshift-apiserver version numbers for the current context
  4. oc version --short
  5. # Print the OpenShift client version information for the current context
  6. oc version --client

oc wait

Experimental: Wait for a specific condition on one or many resources

Example usage

  1. # Wait for the pod "busybox1" to contain the status condition of type "Ready"
  2. oc wait --for=condition=Ready pod/busybox1
  3. # The default value of status condition is true; you can set it to false
  4. oc wait --for=condition=Ready=false pod/busybox1
  5. # Wait for the pod "busybox1" to contain the status phase to be "Running".
  6. oc wait --for=jsonpath='{.status.phase}'=Running pod/busybox1
  7. # Wait for the pod "busybox1" to be deleted, with a timeout of 60s, after having issued the "delete" command
  8. oc delete pod/busybox1
  9. oc wait --for=delete pod/busybox1 --timeout=60s

oc whoami

Return information about the current session

Example usage

  1. # Display the currently authenticated user
  2. oc whoami

Additional resources