Objective of this article to know how to call REST API from CLI to get the projects list. Continue further to know various problems and solutions to overcome and finally list the projects.
How to call REST API from CLI? To call REST API from CLI, we can use curl -k command followed by the REST URL. For more information look at the below command,
How to solve Forbidden (403) issue while calling REST API? Since we are not authorized who is calling the API, we end up with the problem of 403 Forbidden. To solve this problem, login as developer by using the following command.
oc login -u developer -p developer
user login from CLI
Then issue the below command to get the security token which we need to pass in REST API call.
oc whoami -t
Identifying the security key by issuing the command of whoami
Now pass the security key in the REST call Authorization by using -H “Authorization: Bearer PaqE4Ui1mirlpAUqi6w-20VQS0qeD3EXA8w1IhwewqE”. The complete URL looks like,
Objective of this article to make you understand how to solve the problem of OpenShift oc command is not recognized as an internal or external command in CLI.
oc is not recognized as command
To overcome this problem we have to setup the path of the OpenShift CLI which we can get is by executing the below command.
minishift oc-env
oc environment details
Copy the full line of set path and execute the same. SET PATH=C:\Users\subbaiah.nallamachu.minishift\cache\oc\v3.11.0\windows;%PATH%
openshift path setup
Now the system will not throw the problem of not recognized as a command.
How to list all OpenShift supported commands?
This is very simple task to identify the list of OpenShift supported commands. Issue the oc –help to get list of commands.
This client helps you develop, build, deploy, and run your applications on any OpenShift or Kubernetes compatible platform. It also includes the administrative commands for managing a cluster under the ‘adm’ subcommand.
Usage: oc [flags]
Basic Commands: 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
Build and Deploy Commands: 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
Application Management Commands: 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
Troubleshooting and Debugging Commands: 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
Advanced Commands: 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
Settings Commands: 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)
Other Commands: ex Experimental commands under active development help Help about any command plugin Runs a command-line plugin version Display client and server versions
Use “oc <command> –help” for more information about a given command. Use “oc options” for a list of global command-line options (applies to all commands).
Objective of this article is to help to know how to setup MiniShift and Run in development environment by using Oracle VM VirtualBox. Prior to continue with this article, there are few prerequisites which you should already done in your system.
Download & Install Oracle VM by clicking this link
Then keep the extracted MiniShift directory into your C drive or even any specific directory which is comfortable to you and navigate to the path of the MiniShift directory in Command Line or PowerShell. Then issue the below command to start MiniShift.
minishift start –vm-driver virtualbox
Look at the below log information while setting up the MiniShift.
C:\minishift-1.34.2-windows-amd64>minishift start –vm-driver virtualbox — Starting profile ‘minishift’ — Check if deprecated options are used … Use of HYPERV_VIRTUAL_SWITCH has been deprecated Please use: minishift config set hyperv-virtual-switch External FAIL
— Checking if https://github.com is reachable … OK — Checking if requested OpenShift version ‘v3.11.0’ is valid … OK — Checking if requested OpenShift version ‘v3.11.0’ is supported … OK — Checking if requested hypervisor ‘virtualbox’ is supported on this platform … OK — Checking if VirtualBox is installed … OK — Checking the ISO URL … OK — Downloading OpenShift binary ‘oc’ version ‘v3.11.0’ 53.59 MiB / 53.59 MiB [========================================================================================================================================================================================================] 100.00% 0s– Downloading OpenShift v3.11.0 checksums … OK — Checking if provided oc flags are supported … OK — Starting the OpenShift cluster using ‘virtualbox’ hypervisor … — Minishift VM will be configured with … Memory: 4 GB vCPUs : 2 Disk size: 20 GB
Downloading ISO ‘https://github.com/minishift/minishift-centos-iso/releases/download/v1.16.0/minishift-centos7.iso’ 370.00 MiB / 370.00 MiB [======================================================================================================================================================================================================] 100.00% 0s — Starting Minishift VM …………………………. OK — Checking for IP address … OK — Checking for nameservers … OK — Checking if external host is reachable from the Minishift VM … Pinging 8.8.8.8 … OK — Checking HTTP connectivity from the VM … Retrieving http://minishift.io/index.html … OK — Checking if persistent storage volume is mounted … OK — Checking available disk space … 1% used OK — Writing current configuration for static assignment of IP address … OK Importing ‘openshift/origin-control-plane:v3.11.0’ . CACHE MISS Importing ‘openshift/origin-docker-registry:v3.11.0’ . CACHE MISS Importing ‘openshift/origin-haproxy-router:v3.11.0’ . CACHE MISS — OpenShift cluster will be configured with … Version: v3.11.0 — Pulling the OpenShift Container Image ………………… OK — Copying oc binary from the OpenShift container image to VM … OK — Starting OpenShift cluster ………………………………………………………. Getting a Docker client … Checking if image openshift/origin-control-plane:v3.11.0 is available … E0215 13:06:53.869343 2668 helper.go:173] Reading docker config from /home/docker/.docker/config.json failed: open /home/docker/.docker/config.json: no such file or directory, will attempt to pull image docker.io/openshift/origin-cli:v3.11.0 anonymously Pulling image openshift/origin-cli:v3.11.0 Image pull complete E0215 13:06:57.802592 2668 helper.go:173] Reading docker config from /home/docker/.docker/config.json failed: open /home/docker/.docker/config.json: no such file or directory, will attempt to pull image docker.io/openshift/origin-node:v3.11.0 anonymously Pulling image openshift/origin-node:v3.11.0 Pulled 5/6 layers, 86% complete Pulled 6/6 layers, 100% complete Extracting Image pull complete Checking type of volume mount … Determining server IP … Using public hostname IP 192.168.99.100 as the host IP Checking if OpenShift is already running … Checking for supported Docker version (=>1.22) … Checking if insecured registry is configured properly in Docker … Checking if required ports are available … Checking if OpenShift client is configured properly … Checking if image openshift/origin-control-plane:v3.11.0 is available … Starting OpenShift using openshift/origin-control-plane:v3.11.0 … I0215 13:07:18.692080 2668 config.go:40] Running “create-master-config” I0215 13:07:20.801879 2668 config.go:46] Running “create-node-config” I0215 13:07:21.874073 2668 flags.go:30] Running “create-kubelet-flags” I0215 13:07:22.261666 2668 run_kubelet.go:49] Running “start-kubelet” I0215 13:07:22.490333 2668 run_self_hosted.go:181] Waiting for the kube-apiserver to be ready … I0215 13:08:15.514360 2668 interface.go:26] Installing “kube-proxy” … I0215 13:08:15.514860 2668 interface.go:26] Installing “kube-dns” … I0215 13:08:15.514866 2668 interface.go:26] Installing “openshift-service-cert-signer-operator” … I0215 13:08:15.514871 2668 interface.go:26] Installing “openshift-apiserver” … I0215 13:08:15.514908 2668 apply_template.go:81] Installing “openshift-apiserver” I0215 13:08:15.515090 2668 apply_template.go:81] Installing “kube-proxy” I0215 13:08:15.516216 2668 apply_template.go:81] Installing “kube-dns” I0215 13:08:15.516356 2668 apply_template.go:81] Installing “openshift-service-cert-signer-operator” I0215 13:08:19.721560 2668 interface.go:41] Finished installing “kube-proxy” “kube-dns” “openshift-service-cert-signer-operator” “openshift-apiserver” I0215 13:10:57.742660 2668 run_self_hosted.go:242] openshift-apiserver available I0215 13:10:57.743220 2668 interface.go:26] Installing “openshift-controller-manager” … I0215 13:10:57.743240 2668 apply_template.go:81] Installing “openshift-controller-manager” I0215 13:11:01.077314 2668 interface.go:41] Finished installing “openshift-controller-manager” Adding default OAuthClient redirect URIs … Adding sample-templates … Adding web-console … Adding centos-imagestreams … Adding registry … Adding router … Adding persistent-volumes … I0215 13:11:01.109594 2668 interface.go:26] Installing “sample-templates” … I0215 13:11:01.109610 2668 interface.go:26] Installing “openshift-web-console-operator” … I0215 13:11:01.109622 2668 interface.go:26] Installing “centos-imagestreams” … I0215 13:11:01.109650 2668 interface.go:26] Installing “openshift-image-registry” … I0215 13:11:01.109661 2668 interface.go:26] Installing “openshift-router” … I0215 13:11:01.109671 2668 interface.go:26] Installing “persistent-volumes” … I0215 13:11:01.110738 2668 interface.go:26] Installing “sample-templates/cakephp quickstart” … I0215 13:11:01.110752 2668 interface.go:26] Installing “sample-templates/django quickstart” … I0215 13:11:01.110763 2668 interface.go:26] Installing “sample-templates/nodejs quickstart” … I0215 13:11:01.110773 2668 interface.go:26] Installing “sample-templates/sample pipeline” … I0215 13:11:01.110784 2668 interface.go:26] Installing “sample-templates/mongodb” … I0215 13:11:01.110793 2668 interface.go:26] Installing “sample-templates/mariadb” … I0215 13:11:01.110803 2668 interface.go:26] Installing “sample-templates/mysql” … I0215 13:11:01.110812 2668 interface.go:26] Installing “sample-templates/jenkins pipeline ephemeral” … I0215 13:11:01.110823 2668 interface.go:26] Installing “sample-templates/postgresql” … I0215 13:11:01.110833 2668 interface.go:26] Installing “sample-templates/dancer quickstart” … I0215 13:11:01.110843 2668 interface.go:26] Installing “sample-templates/rails quickstart” … I0215 13:11:01.110890 2668 apply_list.go:67] Installing “sample-templates/rails quickstart” I0215 13:11:01.111815 2668 apply_template.go:81] Installing “openshift-web-console-operator” I0215 13:11:01.112046 2668 apply_list.go:67] Installing “centos-imagestreams” I0215 13:11:01.113980 2668 apply_list.go:67] Installing “sample-templates/cakephp quickstart” I0215 13:11:01.114199 2668 apply_list.go:67] Installing “sample-templates/django quickstart” I0215 13:11:01.114369 2668 apply_list.go:67] Installing “sample-templates/nodejs quickstart” I0215 13:11:01.114535 2668 apply_list.go:67] Installing “sample-templates/sample pipeline” I0215 13:11:01.114707 2668 apply_list.go:67] Installing “sample-templates/mongodb” I0215 13:11:01.114857 2668 apply_list.go:67] Installing “sample-templates/mariadb” I0215 13:11:01.115058 2668 apply_list.go:67] Installing “sample-templates/mysql” I0215 13:11:01.115217 2668 apply_list.go:67] Installing “sample-templates/jenkins pipeline ephemeral” I0215 13:11:01.115370 2668 apply_list.go:67] Installing “sample-templates/postgresql” I0215 13:11:01.115543 2668 apply_list.go:67] Installing “sample-templates/dancer quickstart” I0215 13:11:17.346124 2668 interface.go:41] Finished installing “sample-templates/cakephp quickstart” “sample-templates/django quickstart” “sample-templates/nodejs quickstart” “sample-templates/sample pipeline” “sample-templates/mongodb” “sample-templates/mariadb” “sample-templates/mysql” “sample-templates/jenkins pipeline ephemeral” “sample-templates/postgresql” “sample-templates/dancer quickstart” “sample-templates/rails quickstart” I0215 13:11:49.774639 2668 interface.go:41] Finished installing “sample-templates” “openshift-web-console-operator” “centos-imagestreams” “openshift-image-registry” “openshift-router” “persistent-volumes” Login to server … Creating initial project “myproject” … Server Information … OpenShift server started.
You are logged in as: User: developer Password: <any value>
To login as administrator: oc login -u system:admin
— Exporting of OpenShift images is occuring in background process with pid 71760.
Minishift Starting Logs
Note: MiniShift will automatically import image into VirtualBox and Run, we no need to import image in VirtualBox manually.
As per the above log information OpenShift setup has been done and it is running with Process Id of 71760. We can access the OpenShift console with the URL of https://192.168.99.100:8443/console and there are 2 different types of login provided like developer and administrator. Currently it is logged in as developer. Let’s access the console,
OpenShift Login Page
We should pass the username as developer and password as any value to login. Then the home page looks like,
OpenShift home page with list of tools available inbuilt
Now try to login as administrator by using the credentials generated at the time of OpenShift starting. We may end up with the problem of error: not a valid port: strconv.ParseUint: parsing “admin”: invalid syntax
To solve this problem, we must set OC path which we can find it in oc-env. Execute the below command to know the properties present in oc-env.
minishift oc-env
SET PATH=C:\Users\subbaiah.nallamachu\.minishift\cache\oc\v3.11.0\windows;%PATH%
Now copy the complete line of set path and execute in the same command line and then try to login as administrator by using the same command shown in the log.
Openshift inbuilt available projects. Ignore the stared project which I created for practice and it’s a custom project.