OpenShift开源mini版试用

Minishift 简介

Minishift是一个工具,可以通过在VM中运行单节点OpenShift集群来帮助您在本地运行OpenShift。(OpenShift是RedHat基于K8S进一步开发的PAAS平台, 增强了: CI/CD, 监控, 安全, UI等功能.)

Minishift 安装

以下步骤是在win10 专业版上进行.

先决条件

虚拟机

Minishift需要管理程序来启动配置OpenShift集群的虚拟机。在设置Minishift之前,请验证系统上是否已安装并启用了您选择的虚拟机程序。虚拟机管理程序启动并运行后,Minishift需要进行其他设置才能使用该管理程序。

Windows

Hyper-V

:exclamation:

要将Minishift与Hyper-V配合使用,请确保在安装Hyper-V后,还可以使用Hyper-V管理器添加虚拟交换机,并在minishift配置选项hyperv-virtual-switch 部分设置为之前添加的虚拟交换机(virtual switch)。有关特定配置步骤,请参阅“ 设置Hyper-V驱动程序”部分。

所有平台

VirtualBox

:exclamation:

如果windows是家庭版, 没有Hyper-V的, 也可以安装VirtualBox.

建议在Windows上使用VirtualBox 5.1.12或更高版本

设置虚拟化环境

如果使用了VirtualBox, 有关详细信息,请参阅设置Minishift以使用VirtualBox

Windows

设置Hyper-V驱动程序

要在Hyper-V中使用Minishift:

  1. 安装Hyper-V

  2. 将用户添加到本地Hyper-V管理员组。

    :exclamation:

    这是允许用户使用Hyper-V Management API创建和删除虚拟机所必需的。有关更多信息,请参阅Hyper-V命令必须以管理员身份运行

  3. 添加外部虚拟交换机

  4. 确认您将虚拟交换机与连接到网络的网卡(有线或无线)配对。

安装 Minishift

windows上只能手动安装

  1. Minishift版本页面下载适用于您的操作系统的存档,并提取其内容。

    本次使用的minishift版本-minishift-1.30.0-windows-amd64.zip

  2. 解压压缩包内容到指定位置。

    本次解压至: C:\Program Files\minishift

    目前minishift必须放在C盘

  3. minishift二进制文件添加到PATH环境变量中。

    set_env.png
  4. 使用配置选项hyperv-virtual-switch或启动标志--hyperv-virtual-switch设置要用于Minishift的外部虚拟交换机的名称。

    例如, 在PowerShell上使用("External (Wireless)"就是你之前创建的虚拟交换机的名称)

    PS> minishift config set hyperv-virtual-switch "External (Wireless)"
    

    或者

    PS> minishift start --hyperv-virtual-switch "External (Wireless)"
    

    ❗️

    这一步前提是minishift已经安装, 且路径已经加入到环境变量PATH中.

    虚拟交换机的名称区分大小写。

更新 Minishift

卸载 Minishift

Minishift 快速入门

概述

本节包含Minishift和配置的OpenShift集群的简要演示。有关Minishift使用的详细信息,请参阅“ 基本用法”部分。

与OpenShift的交互是使用命令行工具oc(需要额外下载)。有关Minishift如何帮助您与本地OpenShift实例进行交互和配置的更多信息,请参阅OpenShift客户端二进制文件部分。

有关OpenShift集群结构的更多信息,请参阅OpenShift文档中的体系结构概述

以下步骤描述了如何在具有Hyper-V管理程序驱动程序的Windows操作系统上开始使用Minishift。

Minishift Start

  1. 为了避免命令行下载oc 包过慢, 建议先下载oc 并解压到指定位置. 并在minishift中配置PATH.

    ❗️

    本次下载的oc - openshift-origin-client-tools-v3.11.0-0cbc58b-windows.zip

    解压后路径: C:\Users\cuika\.minishift\cache\oc\v3.11.0\windows\oc.exe

  2. oc路径添加到环境变量的PATH中. (见: 安装Minishift的图)

  3. 运行minishift start命令:

    Windows PowerShell
    版权所有 (C) Microsoft Corporation。保留所有权利。
    
    加载个人及系统配置文件用了 901 毫秒。
    ⚡ cuika@DESKTOP-OQVRBLM  ~                                                                                               [21:48]
    ❯ minishift start
    -- Starting profile 'minishift'
    -- Check if deprecated options are used ... OK
    -- 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 'hyperv' is supported on this platform ... OK
    -- Checking if Hyper-V driver is installed ... OK
    -- Checking if Hyper-V driver is configured to use a Virtual Switch ...
       'External VM Switch' ... OK
    -- Checking if user is a member of the Hyper-V Administrators group ... OK
    -- Checking the ISO URL ... OK
    -- Checking if provided oc flags are supported ... OK
    -- Starting the OpenShift cluster using 'hyperv' hypervisor ...
    -- 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 ... FAIL
       VM is unable to ping external host
    -- 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 ... 19% used OK
    -- Writing current configuration for static assignment of IP address ... OK
    -- OpenShift cluster will be configured with ...
       Version: v3.11.0
    -- 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 ...
    Checking type of volume mount ...
    Determining server IP ...
    Using public hostname IP 192.168.2.6 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 ...
    I0124 13:58:39.187003    6792 flags.go:30] Running "create-kubelet-flags"
    I0124 13:58:39.699733    6792 run_kubelet.go:49] Running "start-kubelet"
    I0124 13:58:39.989981    6792 run_self_hosted.go:181] Waiting for the kube-apiserver to be ready ...
    I0124 13:59:08.091060    6792 interface.go:26] Installing "kube-proxy" ...
    I0124 13:59:08.091966    6792 interface.go:26] Installing "kube-dns" ...
    I0124 13:59:08.091976    6792 interface.go:26] Installing "openshift-service-cert-signer-operator" ...
    I0124 13:59:08.091983    6792 interface.go:26] Installing "openshift-apiserver" ...
    I0124 13:59:08.092028    6792 apply_template.go:81] Installing "openshift-apiserver"
    I0124 13:59:08.093241    6792 apply_template.go:81] Installing "kube-proxy"
    I0124 13:59:08.094733    6792 apply_template.go:81] Installing "kube-dns"
    I0124 13:59:08.094928    6792 apply_template.go:81] Installing "openshift-service-cert-signer-operator"
    I0124 13:59:45.867897    6792 interface.go:41] Finished installing "kube-proxy" "kube-dns" "openshift-service-cert-signer-operator" "openshift-apiserver"
    I0124 14:00:07.031707    6792 run_self_hosted.go:242] openshift-apiserver available
    I0124 14:00:07.033740    6792 interface.go:26] Installing "openshift-controller-manager" ...
    I0124 14:00:07.033856    6792 apply_template.go:81] Installing "openshift-controller-manager"
    I0124 14:00:10.017851    6792 interface.go:41] Finished installing "openshift-controller-manager"
    Adding default OAuthClient redirect URIs ...
    Adding router ...
    Adding sample-templates ...
    Adding web-console ...
    Adding centos-imagestreams ...
    Adding registry ...
    Adding persistent-volumes ...
    I0124 14:00:10.037836    6792 interface.go:26] Installing "openshift-router" ...
    I0124 14:00:10.037848    6792 interface.go:26] Installing "sample-templates" ...
    I0124 14:00:10.037855    6792 interface.go:26] Installing "openshift-web-console-operator" ...
    I0124 14:00:10.037863    6792 interface.go:26] Installing "centos-imagestreams" ...
    I0124 14:00:10.037874    6792 interface.go:26] Installing "openshift-image-registry" ...
    I0124 14:00:10.037881    6792 interface.go:26] Installing "persistent-volumes" ...
    I0124 14:00:10.038621    6792 interface.go:26] Installing "sample-templates/django quickstart" ...
    I0124 14:00:10.038631    6792 interface.go:26] Installing "sample-templates/nodejs quickstart" ...
    I0124 14:00:10.038640    6792 interface.go:26] Installing "sample-templates/rails quickstart" ...
    I0124 14:00:10.038647    6792 interface.go:26] Installing "sample-templates/mongodb" ...
    I0124 14:00:10.038654    6792 interface.go:26] Installing "sample-templates/mysql" ...
    I0124 14:00:10.038662    6792 interface.go:26] Installing "sample-templates/postgresql" ...
    I0124 14:00:10.038717    6792 interface.go:26] Installing "sample-templates/cakephp quickstart" ...
    I0124 14:00:10.038726    6792 interface.go:26] Installing "sample-templates/dancer quickstart" ...
    I0124 14:00:10.038734    6792 interface.go:26] Installing "sample-templates/jenkins pipeline ephemeral" ...
    I0124 14:00:10.038741    6792 interface.go:26] Installing "sample-templates/sample pipeline" ...
    I0124 14:00:10.038748    6792 interface.go:26] Installing "sample-templates/mariadb" ...
    I0124 14:00:10.038815    6792 apply_list.go:67] Installing "sample-templates/mariadb"
    I0124 14:00:10.039141    6792 apply_template.go:81] Installing "openshift-web-console-operator"
    I0124 14:00:10.039340    6792 apply_list.go:67] Installing "centos-imagestreams"
    I0124 14:00:10.039855    6792 apply_list.go:67] Installing "sample-templates/django quickstart"
    I0124 14:00:10.040025    6792 apply_list.go:67] Installing "sample-templates/nodejs quickstart"
    I0124 14:00:10.040139    6792 apply_list.go:67] Installing "sample-templates/rails quickstart"
    I0124 14:00:10.040247    6792 apply_list.go:67] Installing "sample-templates/mongodb"
    I0124 14:00:10.040375    6792 apply_list.go:67] Installing "sample-templates/mysql"
    I0124 14:00:10.040480    6792 apply_list.go:67] Installing "sample-templates/postgresql"
    I0124 14:00:10.040586    6792 apply_list.go:67] Installing "sample-templates/cakephp quickstart"
    I0124 14:00:10.040736    6792 apply_list.go:67] Installing "sample-templates/dancer quickstart"
    I0124 14:00:10.040860    6792 apply_list.go:67] Installing "sample-templates/jenkins pipeline ephemeral"
    I0124 14:00:10.040972    6792 apply_list.go:67] Installing "sample-templates/sample pipeline"
    I0124 14:00:22.891473    6792 interface.go:41] Finished installing "sample-templates/django quickstart" "sample-templates/nodejs quickstart" "sample-templates/rails quickstart" "sample-templates/mongodb" "sample-templates/mysql" "sample-templates/postgresql" "sample-templates/cakephp quickstart" "sample-templates/dancer quickstart" "sample-templates/jenkins pipeline ephemeral" "sample-templates/sample pipeline" "sample-templates/mariadb"
    I0124 14:00:22.891498    6792 interface.go:41] Finished installing "openshift-router" "sample-templates" "openshift-web-console-operator" "centos-imagestreams" "openshift-image-registry" "persistent-volumes"
    Server Information ...
    OpenShift server started.
    
    The server is accessible via web console at:
        https://192.168.2.6:8443/console
    
    

    :exclamation:

    • 启动非常非常慢!!!. 至少10min. 如果之前没有下载好oc , 会更慢!!!

    • 虚拟机至少需要8G内存.

    OpenShift集群IP是动态生成的。要检查IP,请运行minishift ip命令。默认情况下,Minishift使用与主机操作系统最相关的驱动程序。要使用其他驱动程序,请在minishift start后使用--vm-driver标志。例如,要在Linux操作系统上使用VirtualBox而不是KVM,请运行minishift start --vm-driver=virtualbox。当Minishift启动时,它会运行几次检查以确保Minishift VM和OpenShift集群能够正确启动。如果任何启动检查失败,请参阅“ 故障排除入门”主题以获取有关可能原因和解决方案. 有关minishift start选项的更多信息,请参阅minishift start命令。

openshift_webui.png

有关使用命令行界面和Web控制台与OpenShift交互的更多信息,请参阅OpenShift客户端二进制文件部分。

部署示例应用程序

OpenShift提供各种示例应用程序,例如模板(templates),构建器应用程序(builder applications)和快速入门(quickstarts)。以下步骤描述了如何从命令行部署示例Node.js应用程序。

  1. 创建一个Node.js示例应用程序:

    $ oc new-app https://github.com/sclorg/nodejs-ex -l name=myapp
    
  2. 跟踪构建日志,直到应用程序构建和部署完毕:

    $ oc logs -f bc/nodejs-ex
    Cloning "https://github.com/sclorg/nodejs-ex" ...
            Commit: e59fe7571f883db2ae2e53d555aef6d145c6f032 (Merge pull request #206 from liangxia/okd)
            Author: Honza Horak <hhorak@redhat.com>
            Date:   Tue Oct 16 15:45:10 2018 +0200
    Using 172.30.1.1:5000/openshift/nodejs@sha256:3cc041334eef8d5853078a0190e46a2998a70ad98320db512968f1de0561705e as the s2i builder image
    
    ---> Installing application source
    ---> Building your Node application from source
    Current git config
    url.https://github.com.insteadof=git@github.com:
    url.https://.insteadof=ssh://
    url.https://github.com.insteadof=ssh://git@github.com
    core.repositoryformatversion=0
    core.filemode=true
    core.bare=false
    core.logallrefupdates=true
    remote.origin.url=https://github.com/sclorg/nodejs-ex
    remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
    branch.master.remote=origin
    branch.master.merge=refs/heads/master
    ---> Installing dependencies
    ---> Using 'npm install -s --only=production'
    added 117 packages from 342 contributors and audited 200 packages in 409.907s
    found 5 vulnerabilities (2 low, 1 moderate, 1 high, 1 critical)
    run `npm audit fix` to fix them, or `npm audit` for details
    ---> Pruning the development dependencies
    npm info it worked if it ends with ok
    npm info using npm@6.4.1
    npm info using node@v10.12.0
    npm timing stage:loadCurrentTree Completed in 412ms
    npm timing stage:loadIdealTree:cloneCurrentTree Completed in 3ms
    npm timing stage:loadIdealTree:loadShrinkwrap Completed in 168ms
    npm timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 86ms
    npm timing stage:loadIdealTree Completed in 320ms
    npm timing stage:generateActionsToTake Completed in 23ms
    npm timing audit compress Completed in 9ms
    npm info audit Submitting payload of 6300bytes
    npm timing stage:executeActions Completed in 239ms
    npm timing stage:rollbackFailedOptional Completed in 1ms
    npm timing stage:runTopLevelLifecycles Completed in 1065ms
    npm timing audit submit Completed in 8161ms
    npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/audits/quick 7997ms
    npm timing audit body Completed in 3ms
    audited 200 packages in 9.006s
    found 5 vulnerabilities (2 low, 1 moderate, 1 high, 1 critical)
    run `npm audit fix` to fix them, or `npm audit` for details
    npm timing npm Completed in 9548ms
    npm info ok
    ---> Cleaning up npm cache
    ---> Fix permissions on app-root
    Pushing image 172.30.1.1:5000/myproject/nodejs-ex:latest ...
    Pushed 6/7 layers, 90% complete
    Pushed 7/7 layers, 100% complete
    Push successful
    
  3. 暴露route到对应service:

    $ oc expose svc/nodejs-ex
    
  4. 访问应用程序:

    $ minishift openshift service nodejs-ex --in-browser
    
  5. 本次自动分配的应用程序URL为: http://nodejs-ex-myproject.192.168.2.6.nip.io

    sampleapp_ui.png
  6. 要停止Minishift,请使用以下命令:

    $ minishift stop
    Stopping local OpenShift cluster...
    Stopping "minishift"...
    

有关在OpenShift中创建应用程序的更多信息,请参阅OpenShift文档中的创建新应用程序

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,015评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,262评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,727评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,986评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,363评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,610评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,871评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,582评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,297评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,551评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,053评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,385评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,035评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,079评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,841评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,648评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,550评论 2 270

推荐阅读更多精彩内容