Integration

10 basic Openshift commands to get you started

I know the feeling: you start working with a new technology and there is so much information in blogs, articles and books that you get lost. Take Openshift as an example. It has so many new concepts and building blocks that it can be really overwhelming. Pods, namespaces, services, registry, routes, deployments … where to begin? But don’t worry, I have compiled a list of basic commands in Openshift so that you can take those first steps.

1) Login

What does it do?

You will need to login before entering any other command in Openshift. It will start a “session” and save the token in the .kube/config file. After that, every other command you enter will use that token to authenticate. Beware if you work with multiple environments because you may be executing your commands in the wrong one.

Sample

References
  • https://docs.openshift.com/container-platform/3.11/cli_reference/get_started_cli.html#basic-setup-and-login
  • https://www.mankier.com/1/oc-login

 

2) Change Project

    What does it do?

    Project is the name Openshift uses to refer to Kubernetes namespaces and this command will help you change between them. You have to select the right project before creating or editing your artifacts.

    Sample

    References
    • https://docs.openshift.com/container-platform/3.11/cli_reference/basic_cli_operations.html
    • https://www.mankier.com/1/oc-project

    3) Describe

    What does it do?

    This command describes the object type you pass as a parameter. So if you type oc describe pod, the command will return the detailed information of every POD running in the current namespace. Since it can be a lot of information, you can filter the output by providing the name of the object you want to be described. So oc describe pod myrunning-pod-2-fdthn will only return the detailed information of myrunning-pod-2-fdthn

    You can also describe other objects, such as projects, configmaps, routes and secrets.

    Sample

    References
    • https://docs.openshift.com/container-platform/3.11/cli_reference/basic_cli_operations.html
    • https://www.mankier.com/1/oc-describe

    4) Get

    What does it do?

    This command returns an object list of the provided object type. For example, if you enter oc get secrets you will get a list the current namespace’s secret. As with describe, you can also filter by name.

    Sample

    References
    • https://docs.openshift.com/container-platform/3.11/cli_reference/basic_cli_operations.html
    • https://www.mankier.com/1/oc-get

    5) Create

    What does it do?

    Like the name says it, this command lets you create new resources in your namespace. You can define them in a JSON or YAML file and send it to Openshift to process it.

    Sample

    References
    • https://docs.openshift.com/container-platform/3.11/cli_reference/basic_cli_operations.html#create
    • https://www.mankier.com/1/oc-create

    6) Apply

    What does it do?

    This command is very similar to “create”. The difference is that apply lets you change/merge already existing resources. With the –f you can force your changes

    Sample

    References
    • https://www.mankier.com/1/oc-apply
    • https://docs.openshift.com/container-platform/3.11/dev_guide/application_lifecycle/promoting_applications.html

    7) Delete

    What does it do?

    The whole CRUD won’t be complete without a delete operation. Here you only have to provide the name of the resource you want to delete. You can provide a grace period to let the resource terminate and you can also delete several resources at once using a label.

    Sample

    References
    • https://docs.openshift.com/container-platform/3.11/cli_reference/basic_cli_operations.html#delete
    • https://www.mankier.com/1/oc-delete

    8) Rsync

    What does it do?

    rsynch is a very popular Linux file copying tool. The OC command tool provides its own version to allow you to copy files to or from a POD. Simply provide the name of the POD and the path of the file that you want to copy.

    Sample

    References
    • https://www.mankier.com/1/oc-rsync
    • https://docs.openshift.com/container-platform/3.11/dev_guide/copy_files_to_container.html

    9) Logs

    What does it do?

    Openshift gives you the possibility to see the standard ouput of the pod in the web console. You can also download (or stream them) by using the command “oc logs”. You can also use parameters like “since” to delimit the output send.

    Sample

    References

    • https://www.mankier.com/1/oc-logs
    • https://docs.openshift.com/container-platform/3.11/cli_reference/basic_cli_operations.html#logs

    10) Rollout pause and resume

    What does it do?

    Sometimes you don’t want Openshift to automatically create a new POD when you make changes to a deployment. This scenario is also interesting when using the fabric8 maven plugin. With oc rollout pause you can tell Openshift to not create a new POD even of the trigger was activated. You can end the pause using oc rollout resume, letting Openshift recreate the POD if needed.

    Sample

    The rollout command is a very powerful one. It also allows you to rollback back to a previous deployment or view the history of all rollouts.

    References
    • https://www.mankier.com/1/oc-rollout
    • https://docs.openshift.com/container-platform/3.11/dev_guide/deployments/basic_deployment_operations.html