Chapter 4. Using the oc tool
The optional OpenShift CLI (oc) tool provides a subset of oc commands for MicroShift deployments. Using oc is convenient if you are familiar with OpenShift Container Platform and Kubernetes.
4.1. About the OpenShift CLI Copy linkLink copied to clipboard!
With the OpenShift command-line interface (CLI), the oc command, you can deploy and manage MicroShift projects from a terminal. The CLI oc tool is ideal in the following situations:
- Working directly with project source code
- Scripting Red Hat build of MicroShift operations
- Managing projects while restricted by bandwidth resources
A kubeconfig file must exist for the node to be accessible. The values are applied from built-in default values or a config.yaml, if you created one.
4.2. Using oc with a MicroShift node Copy linkLink copied to clipboard!
Review the following sections to learn how to complete common tasks in MicroShift using the oc CLI.
4.2.1. Viewing pods Copy linkLink copied to clipboard!
Use the oc get pods command to view the pods for the current project.
When you run oc inside a pod and do not specify a namespace, the namespace of the pod is used by default.
oc get pods -o wide
$ oc get pods -o wide
Example output
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE cakephp-ex-1-build 0/1 Completed 0 5m45s 10.131.0.10 ip-10-0-141-74.ec2.internal <none> cakephp-ex-1-deploy 0/1 Completed 0 3m44s 10.129.2.9 ip-10-0-147-65.ec2.internal <none> cakephp-ex-1-ktz97 1/1 Running 0 3m33s 10.128.2.11 ip-10-0-168-105.ec2.internal <none>
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
cakephp-ex-1-build 0/1 Completed 0 5m45s 10.131.0.10 ip-10-0-141-74.ec2.internal <none>
cakephp-ex-1-deploy 0/1 Completed 0 3m44s 10.129.2.9 ip-10-0-147-65.ec2.internal <none>
cakephp-ex-1-ktz97 1/1 Running 0 3m33s 10.128.2.11 ip-10-0-168-105.ec2.internal <none>
4.2.2. Viewing pod logs Copy linkLink copied to clipboard!
Use the oc logs command to view logs for a particular pod.
oc logs cakephp-ex-1-deploy
$ oc logs cakephp-ex-1-deploy
Example output
--> Scaling cakephp-ex-1 to 1 --> Success
--> Scaling cakephp-ex-1 to 1
--> Success
4.2.3. Listing supported API resources Copy linkLink copied to clipboard!
Use the oc api-resources command to view the list of supported API resources on the server.
oc api-resources
$ oc api-resources
Example output
NAME SHORTNAMES APIGROUP NAMESPACED KIND bindings true Binding componentstatuses cs false ComponentStatus configmaps cm true ConfigMap ...
NAME SHORTNAMES APIGROUP NAMESPACED KIND
bindings true Binding
componentstatuses cs false ComponentStatus
configmaps cm true ConfigMap
...
4.3. Getting help Copy linkLink copied to clipboard!
You can get help with CLI commands and MicroShift resources in the following ways.
Use
oc help --flagto get information about a specific CLI command:Example: Get help for the
oc createcommandoc create --help
$ oc create --helpCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
oc explaincommand to view the description and fields for a particular resource:Example: View documentation for the
Podresourceoc explain pods
$ oc explain podsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.4. oc command errors in MicroShift Copy linkLink copied to clipboard!
Not all OpenShift CLI (oc) commands are relevant for MicroShift deployments. When you use oc to make a request call against an unsupported API, the oc binary usually generates an error message about a resource that cannot be found.
For example, when you run the following
new-projectcommand:oc new-project test
$ oc new-project testCopy to Clipboard Copied! Toggle word wrap Toggle overflow The following error message can be generated:
Error from server (NotFound): the server could not find the requested resource (get projectrequests.project.openshift.io)
Error from server (NotFound): the server could not find the requested resource (get projectrequests.project.openshift.io)Copy to Clipboard Copied! Toggle word wrap Toggle overflow When you run the
get projectscommand, another error can be generated as follows:oc get projects
$ oc get projectsCopy to Clipboard Copied! Toggle word wrap Toggle overflow The following error message can be generated:
error: the server doesn't have a resource type "projects"
error: the server doesn't have a resource type "projects"Copy to Clipboard Copied! Toggle word wrap Toggle overflow