Openshift 简明教程
OpenShift - CLI
OpenShift CLI 用于从命令行管理 OpenShift 应用程序。OpenShift CLI 能够管理端到端应用程序生命周期。通常,我们会使用 OC,它是 OpenShift 客户端,用来与 OpenShift 通信。
OpenShift CLI is used for managing OpenShift applications from the command line. OpenShift CLI has the capability to manage end-to-end application life cycle. In general, we would be using OC which is an OpenShift client to communicate with OpenShift.
OpenShift CLI Setup
为了在其他操作系统上设置 OC 客户端,我们需要完成一系列步骤。
In order to set up the OC client on a different operating system, we need to go through different sequence of steps.
OC Client for Windows
Step 1 − 从以下链接下载 oc cli https://github.com/openshift/origin/releases/tag/v3.6.0-alpha.2
Step 1 − Download the oc cli from the following link https://github.com/openshift/origin/releases/tag/v3.6.0-alpha.2
Step 2 − 在计算机上的目标路径解压该软件包。
Step 2 − Unzip the package on a target path on the machine.
Step 3 − 编辑系统的路径环境变量。
Step 3 − Edit the path environment variable of the system.
C:\Users\xxxxxxxx\xxxxxxxx>echo %PATH%
C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Program Files
(x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files
(x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\
v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files
(x86)\ATI Technologies\ATI.ACE\C
ore-Static;C:\Program Files\Intel\Intel(R) Management Engine
Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine
Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
Step 4 − 在 Windows 上验证 OC 设置。
Step 4 − Validate the OC setup on Windows.
C:\openshift-origin-client-tools-v3.6.0-alpha.2-3c221d5-windows>oc version
oc v3.6.0-alpha.2+3c221d5
kubernetes v1.6.1+5115d708d7
features: Basic-Auth
OC Client for Mac OS X
我们可以从与 Windows 相同的位置为 Mac OS 下载设置二进制文件,然后在其他位置解压,并将可执行文件路径设置在 PATH 环境变量下。
We can download the Mac OS setup binaries for the same location as for Windows and later unzip it at a location and set a path of executable under the environment PATH variable.
Alternatively
Alternatively
我们可以使用 Home brew 并用以下命令设置它。
We can use Home brew and set it up using the following command.
$ brew install openshift-cli
OC Client for Linux
在同一页面下,我们有 Linux 安装的 tar 文件,可用于安装。稍后,可以设置一个指向特定可执行文件位置的路径变量。
Under the same page, we have the tar file for Linux installation that can be used for installation. Later, a path variable can be set pointing to that particular executable location.
使用以下命令解压缩 tar 文件。
Unpack the tar file using the following command.
$ tar –xf < path to the OC setup tar file >
运行以下命令检查身份验证。
Run the following command to check the authentication.
C:\openshift-origin-client-tools-v3.6.0-alpha.2-3c221d5-windows>oc login
Server [https://localhost:8443]:
CLI Configuration Files
OC CLI 配置文件用于管理多个 OpenShift 服务器连接和身份验证机制。此配置文件还用于存储和管理多个配置文件,以及在它们之间进行切换。正常的配置文件如下所示。
OC CLI configuration file is used for managing multiple OpenShift server connection and authentication mechanism. This configuration file is also used for storing and managing multiple profiles and for switching between them. A normal configuration file looks like the following.
$ oc config view
apiVersion: v1
clusters:
- cluster:
server: https://vklnld908.int.example.com
name: openshift
contexts:
- context:
cluster: openshift
namespace: testproject
user: alice
name: alice
current-context: alice
kind: Config
preferences: {}
users:
- name: vipin
user:
token: ZCJKML2365jhdfafsdj797GkjgjGKJKJGjkg232
Setting Up CLI Client
For setting user credential
$ oc config set-credentials <user_nickname>
[--client-certificate = <path/to/certfile>] [--client-key=<path/to/keyfile>]
[--token = <bearer_token>] [--username = <basic_user>] [--password = <basic_password>]
CLI Profiles
在单个 CLI 配置文件中,我们可以拥有多个配置文件,其中每个配置文件具有不同的 OpenShift 服务器配置,稍后可用于在不同的 CLI 配置文件之间进行切换。
In a single CLI configuration file, we can have multiple profiles wherein each profile has a different OpenShift server configuration, which later can be used for switching between different CLI profiles.
apiVersion: v1
clusters: --→ 1
- cluster:
insecure-skip-tls-verify: true
server: https://vklnld908.int.example.com:8443
name: vklnld908.int.example.com:8443
- cluster:
insecure-skip-tls-verify: true
server: https://vklnld1446.int.example.com:8443
name: vklnld1446.int.example.com:8443
contexts: ---→ 2
- context:
cluster: vklnld908.int.example.com:8443
namespace: openshift-project
user: vipin/vklnld908.int.example.com:8443
name: openshift-project/vklnld908.int.example.com:8443/vipin
- context:
cluster: vklnld908.int.example.com:8443
namespace: testing-project
user: alim/vklnld908.int.example.com:8443
name: testproject-project/openshift1/alim
current-context: testing-project/vklnld908.int.example.com:8443/vipin - 3
kind: Config
preferences: {}
users:
- name: vipin/vklnld908.int.example.com:8443
user: ---→ 4
token: ZCJKML2365jhdfafsdj797GkjgjGKJKJGjkg232
在上面的配置中,我们可以看到它被分为四个主要部分,从定义了 OpenShift 主机计算机的两个实例的 cluster 开始。第二个 context 部分定义了名为 vipin 和 alim 两个上下文。当前上下文定义了当前正在使用的上下文。如果我们在此处更改定义,则可以将其更改为其他上下文或配置文件。最后,定义了用户定义及其身份验证令牌,在我们的示例中是 vipin。
In the above configuration, we can see it is divided into four main sections starting from cluster which defines two instances of OpenShift master machines. Second context section defines two contexts named vipin and alim. The current context defines which context is currently in use. It can be changed to other context or profile, if we change the definition here. Finally, the user definition and its authentication token is defined which in our case is vipin.
如果我们想检查正在使用的当前配置文件,可以使用以下方法完成:
If we want to check the current profile in use, it can be done using −
$ oc status
oc status
In project testing Project (testing-project)
$ oc project
Using project "testing-project" from context named "testing-
project/vklnld908.int.example.com:8443/vipin" on server "https://vklnld908.int.example.com:8443".
如果我们想要切换到其他的 CLI,则可以使用以下命令从命令行执行。
If we want to switch to other CLI, it can be done from the command line using the following command.
$ oc project openshift-project
Now using project "Openshift-project" on server "
https://vklnld908.int.example.com:8443".
使用上述命令,我们可以切换概要文件。在任何时候,如果我们希望查看配置,我们可以使用 $ oc config view 命令。
Using the above command, we can switch between profiles. At any point of time, if we wish to view the configuration, we can use $ oc config view command.