Este conteúdo não está disponível no idioma selecionado.

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

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
Note

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

You can complete common tasks in MicroShift by using the oc CLI.

Note

When you run oc inside a pod and do not specify a namespace, the namespace of the pod is used by default.

  • To view the pods for the current project, run the oc get pods command:

    $ oc get pods -o wide
    Copy to Clipboard Toggle word wrap

    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>
    Copy to Clipboard Toggle word wrap

  • To view logs for a particular pod, run the oc logs command:

    $ oc logs cakephp-ex-1-deploy
    Copy to Clipboard Toggle word wrap

    Example output

    --> Scaling cakephp-ex-1 to 1
    --> Success
    Copy to Clipboard Toggle word wrap

  • To view the list of supported API resources on the server, run the oc api-resources command:

    $ oc api-resources
    Copy to Clipboard Toggle word wrap

    Example output

    NAME                                  SHORTNAMES       APIGROUP                              NAMESPACED   KIND
    bindings                                                                                     true         Binding
    componentstatuses                     cs                                                     false        ComponentStatus
    configmaps                            cm                                                     true         ConfigMap
    ...
    Copy to Clipboard Toggle word wrap

4.3. Getting help

You can get help with CLI commands and MicroShift resources in the following ways.

  • Use oc help --flag to get information about a specific CLI command:

    Example: Get help for the oc create command

    $ oc create --help
    Copy to Clipboard Toggle word wrap

    Example output

    Create a resource by filename or stdin
    
    JSON and YAML formats are accepted.
    
    Usage:
      oc create -f FILENAME [flags]
    
    ...
    Copy to Clipboard Toggle word wrap

  • Use the oc explain command to view the description and fields for a particular resource:

    Example: View documentation for the Pod resource

    $ oc explain pods
    Copy to Clipboard Toggle word wrap

    Example output

    KIND:     Pod
    VERSION:  v1
    
    DESCRIPTION:
         Pod is a collection of containers that can run on a host. This resource is
         created by clients and scheduled onto hosts.
    
    FIELDS:
       apiVersion	<string>
         APIVersion defines the versioned schema of this representation of an
         object. Servers should convert recognized schemas to the latest internal
         value, and may reject unrecognized values. More info:
         https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
    
    ...
    Copy to Clipboard Toggle word wrap

4.4. oc command errors in MicroShift

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-project command:

    $ oc new-project test
    Copy to Clipboard Toggle word wrap

    The following error message can be generated:

    Error from server (NotFound): the server could not find the requested resource (get projectrequests.project.openshift.io)
    Copy to Clipboard Toggle word wrap
  • When you run the get projects command, another error can be generated as follows:

    $ oc get projects
    Copy to Clipboard Toggle word wrap

    The following error message can be generated:

    error: the server doesn't have a resource type "projects"
    Copy to Clipboard Toggle word wrap
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2026 Red Hat
Voltar ao topo