Explore OpenShift

The Web Console

OpenShift 附带一个基于 Web 的控制台,允许用户通过浏览器执行各种任务

Sandbox

Developer Sandbox for Red Hat OpenShift 适用于 Red Hat OpenShift 的开发人员沙箱是一个免费的 Kubernetes 云环境,位于共享的多租户 OpenShift 集群中,该集群预配置了一组开发人员工具。开发者沙盒有效期为 30 天,到期后可更新。

要创建您的帐户,请访问 https://developers.redhat.com/developer-sandbox ,点击红色按钮,上面写着Get Started in the Sandbox,如下图所示。

Developer Sandbox Sign-up Page

使用您现有的Red Hat帐户或创建一个新帐户,然后按照屏幕上的说明操作。然后,您应该再次重定向到开发者沙盒页面,但这一次,您应该看到一个标记为Start using your sandbox的按钮。

Developer Sandbox Start Page

单击它将打开OpenShift登录屏幕,您可以在其中使用DevSandbox按钮登录,如下所示。

Log in the Developer Sandbox

单击此按钮将打开新的OpenShift群集控制台。

Topology View
配额和限制

开发者沙箱上的私有OpenShift环境包含:

  • 7 GB RAM

  • 15GB storage

这足以运行本次实验

有两个固定项目 (namespaces):

  • <your_username>-dev

  • <your_username>-stage

在此共享环境中, 1、您不能创建新项目,请跳过创建您的第一个项目章节;2此环境不支持Pipelines Operator,所以您需要跳过 the OpenShift Pipelines 之后章节.

请在`<your_username>-dev` project下操作.

developer sandbox还有其他限制,如最多创建10个service,每隔12小时,pod会被停止。

要继续使用实验手册实验,请执行以下操作:

1 - 如上图所示,复制您的集群子域,第1部分,例如apps.sandbox-m2.ll9k.p1.openshiftapps.com. 这用于在实验手册中自动生成所有 URL。

Topology Detail

转到本实验室指南的顶部菜单,并将复制的主机名粘贴到第一个文本字段中,其中有Enter Cluster Subdomain字样。

Add Cluster Subdomain

按Enter键提交.

2 - 复制您的开发人员沙箱的项目名称,如上图所示,第2部分,例如nvinto-dev. 这部分也是用于在实验手册中生成 URL 和说明。

Add Project Name

转到本实验室指南的顶部菜单,并将复制的项目名称粘贴到第二个文本字段中,其中有Enter Project Name字样

按Enter键提交.

您的实验手册现已使用您的 Developer Sandbox 环境主机名和设置进行自定义:

Lab Guide OK

通常,第一次访问 Web 控制台时,您很可能处于管理员视角。如果您也是集群管理员,您将看到整个集群状态的概览:

Web Console Overview

本次实验环境Developer Sandbox for Red Hat OpenShift 4.9 已经自带cli工具。在沙盒界面最顶端右侧,点击cli工具按钮,将会加载cli工具。

Command Line Interface 命令行工具

配置CLI工具请参考官方文档

OpenShift 附带一个功能丰富的 Web 控制台和命令行工具,为用户提供一个很好的界面来处理部署到平台的应用程序。OpenShift 工具是用 Go 编程语言编写的单个可执行文件,可用于以下操作系统:

  • Microsoft Windows

  • Mac OS X

  • Linux

您的环境中可能已经有了 OpenShift CLI。您可以通过运行以下oc命令来验证它:

oc version

您应该会看到以下内容(或类似内容):

Client Version: 4.8.2
Server Version: 4.8.0 (1)
Kubernetes Version: v1.21.0+bd9e442
1 NOTE: you will only see the Server Version and Kubernetes Version if you are currently connected to a Kubenetes or OpenShift cluster

如果您看到类似上面的输出,您可以跳到。 从 CLI 连接到 OpenShift 集群.

但是,如果该oc命令不存在或者您有旧版本的 OpenShift CLI(例如 < 4.4.x),请选择适合您的操作系统的选项卡并按照说明安装或更新 OpenShift CL

  • Mac OSX

  • Windows

  • Linux

If you have HomeBrew installed you can instead install the OpenShift CLI using the brew command. If you don’t have homebrew, then follow the manual download and install instructions that follow the inset.
Download and Install OpenShift CLI on Mac OS X using HomeBrew
brew install openshift-cli

You may also want to enable CLI autocompletion (bash or zsh):

source <(oc completion bash)
source <(oc completion zsh)

To make CLI autocompletion persistent (bash or zsh) by adding a relevant line to your .bashrc or .zshrc:

oc completion bash > oc_bash_completion.sh

source oc_bash_completion.sh
oc completion zsh > oc_zsh_completion.sh

source oc_zsh_completion.sh

从右上角的菜单栏中,单击白色的小问号图标,然后单击命令行工具:

Download CLI

向下滚动oc - OpenShift Command Line Interface (CLI)并单击适合您操作系统的链接

CLI Binaries

下载文件后,您需要解压缩内容,因为它是压缩存档。建议将此文件保存到以下目录:

~/OpenShift

打开终端窗口并切换到下载文件的目录。进入目录后,输入以下命令:

oc 文件的名称可能会有所不同。请做相应调整。
tar zxvf oc-macosx.tar.gz

示例中的tar.gz 文件名需要替换为在上一步中下载的文件名。

现在您可以将 OpenShift CLI 工具添加到您的 PATH。

export PATH=$PATH:~/OpenShift

At this point, we should have the oc tool available for use. Let’s test this out by printing the version of the oc command:

oc version

You should see the following (or something similar):

Client Version: 4.7.0

If you get an error message, you may not have not updated your path correctly. If after checking your PATH you still cannot get the oc command to work, contact your lab instructor for assistence.

从右上角的菜单栏中,单击白色的小问号图标,然后单击命令行工具:

Download CLI

向下滚动oc - OpenShift Command Line Interface (CLI)并单击适合您操作系统的链接

CLI Binaries

适用于 Windows 的 CLI 以 zip 存档形式提供。使用 ZIP 程序下载并解压缩存档并将 oc 二进制文件移动到 PATH 上的目录。要检查您的 PATH,请打开命令提示符并运行:

path

如果您想使用Powershell进行设置,请查看 此博客文章

At this point, we should have the oc tool available for use. Let’s test this out by printing the version of the oc command:

oc version

You should see the following (or something similar):

Client Version: 4.7.0

If you get an error message, you may not have not updated your path correctly. If after checking your PATH you still cannot get the oc command to work, contact your lab instructor for assistence.

从右上角的菜单栏中,单击白色的小问号图标,然后单击命令行工具:

Download CLI

向下滚动oc - OpenShift Command Line Interface (CLI)并单击适合您操作系统的链接

CLI Binaries

下载文件后,您需要解压缩内容,因为它是压缩存档。建议将此文件保存到以下目录:

~/OpenShift

打开终端窗口并切换到下载文件的目录。进入目录后,输入以下命令:

oc 文件的名称可能会有所不同。请做相应调整。
tar zxvf oc-linux.tar.gz

示例中的tar.gz 文件名需要替换为在上一步中下载的文件名。

现在您可以将 OpenShift CLI 工具添加到您的 PATH。

export PATH=$PATH:~/OpenShift

At this point, we should have the oc tool available for use. Let’s test this out by printing the version of the oc command:

oc version

You should see the following (or something similar):

Client Version: 4.7.0

If you get an error message, you may not have not updated your path correctly. If after checking your PATH you still cannot get the oc command to work, contact your lab instructor for assistence.

从 CLI 连接到 OpenShift 集群

如果您安装了OC 客户端,您可以通过OC客户端连接到openshift sandbox实验环境

从 Web 控制台概览中,转到右上角的菜单栏并单击包含您的用户名的下拉菜单,然后单击 复制登录命令

Copy Login Command

单击Display Token并复制Login with this token下的命令:

示例:

oc login --token=sha256~zg0M-1denNkYZjU65IfuCq2gbS8kJ8n1fGhSXdalMx0 --server=https://api.sandbox.x8i5.p1.openshiftapps.com:6443
Logged into "https://api.sandbox.x8i5.p1.openshiftapps.com:6443" as "cowboy-china" using the token provided.

You have access to the following projects and can switch between them with ' project <projectname>':

  * cowboy-china-dev

    cowboy-china-stage

Using project "cowboy-china-dev".

您现在已经可以通过cli 连接到实验环境了。

Working with proxies

It might happen that you’re behind a corporate proxy to access the internet. In this case, you’ll need to set some additional environment variables for the oc command line to work. Select the tab appropriate to your OS below.

  • Mac OS X

  • Windows

  • Linux

Replace the proxy server with the one for your environment/machine.
export https_proxy=http://proxy-server.mycorp.com:3128/
export HTTPS_PROXY=http://proxy-server.mycorp.com:3128/

Follow previous section’s instructions on how to set an Environment Variable on Windows. The variables you’ll need to set are:

Replace the proxy server with the one for your environment/machine.
https_proxy=http://proxy-server.mycorp.com:3128/
HTTPS_PROXY=http://proxy-server.mycorp.com:3128/
Replace the proxy server with the one for your environment/machine.
export https_proxy=http://proxy-server.mycorp.com:3128/
export HTTPS_PROXY=http://proxy-server.mycorp.com:3128/

If the proxy is secured, make sure to use the following URL pattern, replacing the contents with the appropriate values:

export https_proxy=http://USERNAME:PASSOWRD@proxy-server.mycorp.com:3128/

Special Characters: If your password contains special characters, you must replace them with ASCII codes, for example the at sign @ must be replaced by the %40 code, e.g. p@ssword = p%40ssword.