小言_互联网的博客

Openshift - Minishift 简介及常用命令总汇

452人阅读  评论(0)

欢迎使用Openshift - Minishift

OpenShift 是由红帽公司推出的 PaaS 云计算平台,供用户创建网络应用(App、网站)。

Openshift 当前共提供四种产品:OpenShift Online、OpenShift Enterprise、Openshift Dedicated 和 OpenShift Origin。 其中,OpenShift Online 是面向普通开发者和小微企业的线上公有云平台;OpenShift Enterprise 是面向企业的私有云平台;Openshift Dedicated 是面向在AWS/Google Cloud上的私有集群;OpenShift Origin 是一个开源项目,是构成前两个的基础。

OpenShift Enterprise是其私有云版本这是一个开源软件,由 OpenShift Origin管理,支持GitHub,开发者可以使用Git来发布自己的web应用程序到平台上。(source: wiki)

Minishift 是一个可以让你将 OpenShift Origin 安装并运行在本地虚拟机上的工具。从原理上讲,它就是在虚拟机中运行可配置的 oc cluster up 的过程。因此,他也是在本地运行一个单节点的 OpenShift 集群,用于做本地开发环境。

安装命令

// An highlighted block
$ minishift.exe start --vm-driver virtualbox;

安装成功的输出:

// An highlighted block
$ minishift.exe start --vm-driver virtualbox
-- Starting profile 'minishift'
-- Checking if https://github.com is reachable (using proxy: "No") ... OK
-- Checking if requested OpenShift version 'v3.9.0' is valid ... OK
-- Checking if requested OpenShift version 'v3.9.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.9.0'
 40.81 MiB / 40.81 MiB [===================================================================================] 100.00% 0s-- Downloading OpenShift v3.9.0 checksums ... OK
-- Checking if provided oc flags are supported ... OK
-- Starting local OpenShift cluster using 'virtualbox' hypervisor ...
-- Minishift VM will be configured with ...
   Memory:    2 GB
   vCPUs :    2
   Disk size: 20 GB

   Downloading ISO 'https://github.com/minishift/minishift-b2d-iso/releases/download/v1.2.0/minishift-b2d.iso'
 40.00 MiB / 40.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 ... 0% used OK
   Importing 'openshift/origin:v3.9.0' . CACHE MISS
   Importing 'openshift/origin-docker-registry:v3.9.0' . CACHE MISS
   Importing 'openshift/origin-haproxy-router:v3.9.0' . CACHE MISS
-- OpenShift cluster will be configured with ...
   Version: v3.9.0
Pulling image openshift/origin:v3.9.0
Pulled 1/4 layers, 26% complete
Pulled 1/4 layers, 55% complete
Pulled 2/4 layers, 82% complete
Pulled 3/4 layers, 98% complete
Pulled 4/4 layers, 100% complete
Extracting
Image pull complete
Using Docker shared volumes for OpenShift volumes
Using 192.168.99.107 as the server IP
Starting OpenShift using openshift/origin:v3.9.0 ...
OpenShift server started.

The server is accessible via web console at:
    https://192.168.99.107:8443

You are logged in as:
    User:     developer
    Password: <any value>

To login as administrator:
    oc login -u system:admin

Skipping addon 'admissions-webhook' in 'C:\Users\YUCHEN\.minishift\addons\admissions-webhook' due to parse error: Unable to process command: 'PATCH := cat patch.json'
-- Exporting of OpenShift images is occuring in background process with pid 17460.

关闭命令

// An highlighted block

$ minishift stop [flags]

启动命令

// An highlighted block

$ minishift start --vm-driver virtualbox
$ minishift config set vm-driver virtualbox

删除命令

// An highlighted block
$ minishift delete
$ minishift delete --clear-cache

OC命令

把 oc 命令添加到PATH中

// An highlighted block
$ minishift oc-env  // 输出要添加到PATH中的export命令:
SET PATH=C:\Users\username\.minishift\cache\oc\v3.9.0\windows;%PATH%
REM Run this command to configure your shell:
REM     @FOR /f "tokens=*" %i IN ('minishift oc-env') DO @call %i)
$ SET PATH=C:\Users\username\.minishift\cache\oc\v3.9.0\windows;%PATH%
$ oc login -u system:admin

项目和用户:See a list of Projects & Users

项目列表

// An highlighted block
$ oc get projects

用户列表

// An highlighted block
$ oc get users

新建用户,及新建admin用户

在Web console中直接输入任何username,即可新建用户,例如username为administrator:

然后将该用户加到集群角色中,角色为cluster-admin

// An highlighted block
$ oc adm policy add-cluster-role-to-user cluster-admin administrator

收集日志 Collect Logs

// An highlighted block

$ minishift start --show-libmachine-logs -v5

查看插件命令

// An highlighted block
## 使用以下命令查看当前插件的启用状态
$ minishift addon list

## 使用以下命令启用一个插件,例如我想要启用 anyuid 插件
$ minishift addon enable anyuid

OKD 3.11 Documentation

https://docs.okd.io/3.11/welcome/index.html
链接: link.

Openshift 管理

Openshift管理有以下三种途径:

通过Web Console

通过CLI

OC Tool - Openshift Client
OC 登录:

// An highlighted block

$ oc login
$ oc login -u <username> -p <password>

OC 退出:

// An highlighted block

$ oc logout

通过Rest API Call

// An highlighted block

$ curl -k https://localhost:8443/oapi/v1/projects \
-H "Authorization: Bearer <Token>"

注意:Token有效期为24小时
Token可通过以下命令查询

// An highlighted block

$ oc login -u developer -p developer //先用developer用户名登录
$ oc whoami -t

输出为项目列表的Jason格式,例如

// An highlighted block

$ curl -k https://192.168.99.107:8443/oapi/v1/projects \-H "Authorization: Bearer u-SVoMxAJ2nA1dmUyUsXeW0TIqv62MsDlOibnf6_WsM"

## 输出为以下格式
{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "projects is forbidden: User \"system:anonymous\" cannot list projects at the cluster scope: User \"system:anonymous\" cannot list all projects in the cluster",
  "reason": "Forbidden",
  "details": {
    "kind": "projects"
  },
  "code": 403
}curl: (6) Could not resolve host: \-H
curl: (3) Port number ended with ' '

好啦,这期就这里。接着我们会讨论如何在Openshift的项目中添加Application。


转载:https://blog.csdn.net/chenyudora/article/details/105809838
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场