Java

How to develop, build, deploy, and run your applications on any OpenShift or Kubernetes compatible platform using OpenShift Client aka oc command?

This OpenShift Client helps you develop, build, deploy, and run your applications on any OpenShift or Kubernetes compatible platform.

Here are the step by step guide on how to for absolute beginners:

Note: Make sure to add oc (OpenShift Client) to your environment variable so you can run that command from anywhere.

Step 1: login to your server:

Command :  oc login https://yourcluster.yourcompany.com

If required only you must first obtain an API token by going into https://yourcluster.yourcompany.com/oauth/token/request

Find this screenshot below. If this is something you haven’t setup yet go to my other article on how to setup OpenShift locally. http://www.javapan.com/how-to-setup-openshift-in-my-local-machine/

Get your token this way from the console below:

Click on this question icon and you should see this below:

Click on Command Line Tools above:

Now all you have to do is copy that token from the clipboard on the right above and paste it in your oc command line tool below.

These token do have some expiration period so you might have to do this process again. This should conclude step 1.

Step 2:  Create new-app using command line. You can also create from console itself. Demo is done using command line:

Command: oc new-app your-app-name/your-docker-image-name~your-repository-url

A Docker image is a read-only template that contains a set of instructions for creating a container that can run on the Docker platform.

For Docker image information you could use oc new-app –list to view all:

For this demo I will go with this image: “jboss-webserver54-openjdk11-tomcat9-openshift-rhel7”

Before I go create a new app I will first create a gitsecret as I am using GitHub repo so that it will save me a lot of hassle down the line.

Use this command below:  FYI: before from and type it is two dashes (Somehow on mobile device it is showing a single dash, it is two dashes )

oc create secret generic gitsecret –from-literal=username=yourusername–from-password=yourpassword –type=kubernetes.io/basic-auth

Now naming and creating an Application.

Use this command:

oc new-app openshift/jboss-webserver54-openjdk11-tomcat9-openshift-rhel7:latest~https://github.com/jboss-openshift/openshift-quickstarts#my-demo –source-secret=gitsecret

Now if you go to OpenShift console you should see something like this:

Once your application is deployed, use the status, describe, and get commands to see more about the created components:

oc status

oc get pods

OpenShift Console Example:

Command Line Example: oc describe deploymentconfig openshift-quickstarts

Step 3: Make Your Application visible outside the cluster.

To make this application visible outside of the cluster, use the expose command on the service we just created to create a ‘route’ (which will connect your application over the HTTP port to a public domain name).

Command:  oc expose svc/openshift-quickstarts

Console View:

You can run oc status command to see more details. You should now see the URL the application can be reached at. This is a very initial step towards learning OpenShift please do refer to Red Hat Official Documentation for OpenShift for more information.

See helpful command with their usage below :

  types           An introduction to concepts and types

  login           Log in to a server

  new-project     Request a new project

  new-app         Create a new application

  status          Show an overview of the current project

  project         Switch to another project

  projects        Display existing projects

  explain         Documentation of resources

  cluster         Start and stop OpenShift cluster

  rollout         Manage a Kubernetes deployment or OpenShift deployment config

  rollback        Revert part of an application back to a previous deployment

  new-build       Create a new build configuration

  start-build     Start a new build

  cancel-build    Cancel running, pending, or new builds

  import-image    Imports images from a Docker registry

  tag             Tag existing images into image streams

  get             Display one or many resources

  describe        Show details of a specific resource or group of resources

  edit            Edit a resource on the server

  set             Commands that help set specific features on objects

  label           Update the labels on a resource

  annotate        Update the annotations on a resource

  expose          Expose a replicated application as a service or route

  delete          Delete one or more resources

  scale           Change the number of pods in a deployment

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

  secrets         Manage secrets

  serviceaccounts Manage service accounts in your project

  logs            Print the logs for a resource

  rsh             Start a shell session in a pod

  rsync           Copy files between local filesystem and a pod

  port-forward    Forward one or more local ports to a pod

  debug           Launch a new instance of a pod for debugging

  exec            Execute a command in a container

  proxy           Run a proxy to the Kubernetes API server

  attach          Attach to a running container

  run             Run a particular image on the cluster

  cp              Copy files and directories to and from containers.

  wait            Experimental: Wait for one condition on one or many resources

  adm             Tools for managing a cluster

  create          Create a resource from a file or from stdin.

  replace         Replace a resource by filename or stdin

  apply           Apply a configuration to a resource by filename or stdin

  patch           Update field(s) of a resource using strategic merge patch

  process         Process a template into list of resources

  export          Export resources so they can be used elsewhere

  extract         Extract secrets or config maps to disk

  idle            Idle scalable resources

  observe         Observe changes to resources and react to them (experimental)

  policy          Manage authorization policy

  auth            Inspect authorization

  convert         Convert config files between different API versions

  import          Commands that import applications

  image           Useful commands for managing images

  registry        Commands for working with the registry

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

  api-resources   Print the supported API resources on the server

  logout          End the current server session

  config          Change configuration files for the client

  whoami          Return information about the current session

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

  ex              Experimental commands under active development

  help            Help about any command

  plugin          Runs a command-line plugin

  version         Display client and server versions

Leave a Reply