이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 4. Using the oc tool


The optional OpenShift CLI (oc) tool provides a subset of oc commands for Red Hat build of 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 Red Hat build of 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 cluster to be accessible. The values are applied from built-in default values or a config.yaml, if one was created.

4.2. Using the OpenShift CLI in Red Hat build of MicroShift

Review the following sections to learn how to complete common tasks in Red Hat build of MicroShift using the oc CLI.

4.2.1. Viewing pods

Use the oc get pods command to view the pods for the current project.

Note

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

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>

4.2.2. Viewing pod logs

Use the oc logs command to view logs for a particular pod.

$ oc logs cakephp-ex-1-deploy

Example output

--> Scaling cakephp-ex-1 to 1
--> Success

4.2.3. Listing supported API resources

Use the oc api-resources command to view the list of supported API resources on the server.

$ oc api-resources

Example output

NAME                                  SHORTNAMES       APIGROUP                              NAMESPACED   KIND
bindings                                                                                     true         Binding
componentstatuses                     cs                                                     false        ComponentStatus
configmaps                            cm                                                     true         ConfigMap
...

4.3. Getting help

You can get help with CLI commands and Red Hat build of 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

    Example output

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

  • 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

    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
    
    ...

4.4. oc command errors in Red Hat build of MicroShift

Not all OpenShift CLI (oc) tool commands are relevant for Red Hat build of 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.

Example output

For example, when the following new-project command is run:

$ oc new-project test

The following error message can be generated:

Error from server (NotFound): the server could not find the requested resource (get projectrequests.project.openshift.io)

And when the get projects command is run, another error can be generated as follows:

$ oc get projects
error: the server doesn't have a resource type "projects"
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.