Outcomes
Use the OpenShift web console to locate the installation file for the
ocOpenShift command-line interface.Get and use a token from the web console to access the cluster from the command line.
Identify key differences between the
kubectlandoccommand-line tools.Identify the main components of OpenShift and Kubernetes.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that all resources are available for this exercise.
[student@workstation ~]$ lab start cli-interfaces
Instructions
Log in to the OpenShift web console as the
developeruser. Locate the installation file for theocOpenShift command-line interface (CLI).Open a web browser and then navigate to
https://console-openshift-console.apps.ocp4.example.com.Click and log in as the
developeruser with thedeveloperpassword.Locate the installation file for the
ocCLI. From the OpenShift web console, select → . The menu is represented by a?icon.The
ocbinary is available for multiple operating systems and architectures. For each operating system and architecture, theocbinary also includes thekubectlbinary.Note
You do not need to download or install the
ocandkubectlbinaries, which are already installed on theworkstationmachine.
Download an authorization token from the web console. Then, use the token and the
occommand to log in to the OpenShift cluster.From the page, click the link.
The link opens a login page. Click and log in as the
developeruser with thedeveloperpassword.A web page is displayed. Click the link to show your API token and the login command.
Copy the
oc logincommand to your clipboard. Open a terminal window and then use the copied command to log in to the cluster with your token.[student@workstation ~]$
oc login --token=Logged into "https://api.ocp4.example.com:6443" as "developer" using the token provided. ...output omitted...sha256-fypX...Ot6A\ --server=https://api.ocp4.example.com:6443
Compare the available commands for the
kubectlandoccommands.Use the
helpcommand to list and review the available commands for thekubectlcommand.[student@workstation ~]$
kubectl helpkubectl controls the Kubernetes cluster manager. Find more information at: https://kubernetes.io/docs/reference/kubectl/ Basic Commands (Beginner): create Create a resource from a file or from stdin expose Take a replication controller, service, deployment or pod and expose it as a new Kubernetes service run Run a particular image on the cluster set Set specific features on objects Basic Commands (Intermediate): explain Get documentation for a resource get Display one or many resources edit Edit a resource on the server delete Delete resources by file names, stdin, resources and names, or by resources and label selector ...output omitted....Notice that the
kubectlcommand does not provide alogincommand.Examine the available subcommands and options for the
kubectl createcommand by using the--helpoption.[student@workstation ~]$
kubectl create --helpCreate a resource from a file or from stdin. JSON and YAML formats are accepted. Examples: # Create a pod using the data in pod.json kubectl create -f ./pod.json ...output omitted.... Available Commands: clusterrole Create a cluster role clusterrolebinding Create a cluster role binding for a particular cluster role configmap Create a config map from a local file, directory or literal value cronjob Create a cron job with the specified name deployment Create a deployment with the specified name ...output omitted... Options: --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. --dry-run='none': Must be "none", "server", or "client". If client strategy, only print the object that would be sent, without sending it. If server strategy, submit server-side request without persisting the resource. ...output omitted.... Usage: kubectl create -f FILENAME [options] Use "kubectl create <command> --help" for more information about a given command. Use "kubectl options" for a list of global command-line options (applies to all commands).You can use the
--helpoption with anykubectlcommand. The--helpoption provides information about a command, including the available subcommands and options, and the command syntax.List and review the available commands for the
ocbinary by using thehelpcommand.[student@workstation ~]$
oc helpOpenShift Client This client helps you develop, build, deploy, and run your applications on any OpenShift or Kubernetes cluster. It also includes the administrative commands for managing a cluster under the 'adm' subcommand. Basic Commands: 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 Get documentation for a resource ...output omitted....The
occommand supports the same capabilities as thekubectlcommand. Theoccommand provides additional commands to natively support an OpenShift cluster. For example, thenew-projectcommand creates a project, which is a Kubernetes namespace, in the OpenShift cluster. Thenew-appcommand is unique to theoccommand. It creates applications by using existing source code or prebuilt images.Use the
--helpoption with theoc createcommand to view the available subcommands and options.[student@workstation ~]$
oc create --helpCreate a resource from a file or from stdin. JSON and YAML formats are accepted. Examples: # Create a pod using the data in pod.json oc create -f ./pod.json ...output omitted... Available Commands: build Create a new build clusterresourcequota Create a cluster resource quota clusterrole Create a cluster role clusterrolebinding Create a cluster role binding for a particular cluster role configmap Create a config map from a local file, directory or literal value cronjob Create a cron job with the specified name deployment Create a deployment with the specified name deploymentconfig Create a deployment config with default options that uses a given image ...output omitted.... Options: --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. --dry-run='none': Must be "none", "server", or "client". If client strategy, only print the object that would be sent, without sending it. If server strategy, submit server-side request without persisting the resource. ...output omitted... Usage: oc create -f FILENAME [options] ....output omitted....The
oc createcommand includes the same subcommands and options as thekubectl createcommand, and provides additional subcommands for OpenShift resources. For example, you can use theoc createcommand to create OpenShift resources such as a deployment configuration, a route, and an image stream.
Identify the components and Kubernetes resources of an OpenShift cluster by using the terminal. Unless otherwise noted, all commands are available for the
ocandkubectlcommands.In a terminal, use the
oc logincommand to log in to the cluster as theadminuser with theredhatocppassword. Regular cluster users, such as thedeveloperuser, cannot list resources at a cluster scope.[student@workstation ~]$
oc login -u admin -p redhatocpLogin successful ...output omitted...Identify the cluster version with the
versioncommand.[student@workstation ~]$
oc versionClient Version: 4.14.0 Kustomize Version: v5.0.1Server Version: 4.14.0Kubernetes Version: v1.27.6+f67aeb3Use the
cluster-infocommand to identify the URL for the Kubernetes control plane.[student@workstation ~]$
oc cluster-infoKubernetes control plane is running at https://api.ocp4.example.com:6443 To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.Identify the supported API versions by using the
api-versionscommand.[student@workstation ~]$
oc api-versionsadmissionregistration.k8s.io/v1 apiextensions.k8s.io/v1 apiregistration.k8s.io/v1 apiserver.openshift.io/v1 apps.openshift.io/v1 apps/v1 ...output omitted....List cluster operators with the
get clusteroperatorcommand.[student@workstation ~]$
oc get clusteroperatorNAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE ... authentication 4.14.0 True False False 18d baremetal 4.14.0 True False False 18d cloud-controller-manager 4.14.0 True False False 18d cloud-credential 4.14.0 True False False 18d cluster-autoscaler 4.14.0 True False False 18d config-operator 4.14.0 True False False 18d console 4.14.0 True False False 18d control-plane-machine-set 4.14.0 True False False 18d csi-snapshot-controller 4.14.0 True False False 18d dns 4.14.0 True False False 5h24m etcd 4.14.0 True False False 18d image-registry 4.14.0 True False False 18d ingress 4.14.0 True False False 18d ...output omitted...Use the
getcommand to list pods in theopenshift-apiproject. Specify the project with the-noption.[student@workstation ~]$
oc get pods -n openshift-apiserverNAME READY STATUS RESTARTS AGE apiserver-68c9485699-ndqlc 2/2 Running 6 18dUse the
oc statuscommand to retrieve the status of resources in theopenshift-authenticationproject.[student@workstation ~]$
oc status -n openshift-authenticationWarning: apps.openshift.io/v1 DeploymentConfig is deprecated in v4.14+, unavailable in v4.10000+ In project openshift-authentication on server https://api.ocp4.example.com:6443 https://oauth-openshift.apps.ocp4.example.com (passthrough) to pod port 6443 (svc/oauth-openshift) deployment/oauth-openshift deploys quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:64e6...de42 deployment #7 running for 2 weeks - 1 pod deployment #6 deployed 2 weeks ago deployment #4 deployed 2 weeks ago deployment #5 deployed 2 weeks ago deployment #3 deployed 2 weeks ago deployment #2 deployed 2 weeks ago deployment #1 deployed 2 weeks ago ...output omitted...Use the
explaincommand to list the description and available fields forservicesresources.[student@workstation ~]$
oc explain servicesKIND: Service VERSION: v1 DESCRIPTION: Service is a named abstraction of software service (for example, mysql) consisting of local port (for example 3306) that the proxy listens on, and the selector that determines which pods will answer requests sent through the proxy. 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. ...output omitted...Use the
getcommand to list cluster nodes.[student@workstation ~]$
oc get nodesNAME STATUS ROLES AGE VERSION master01 Ready control-plane,master,worker 18d v1.27.6+f67aeb3A single node exists in the cluster.