Minishift 简介
Minishift是一个工具,可以通过在VM中运行单节点OpenShift集群来帮助您在本地运行OpenShift。(OpenShift是RedHat基于K8S进一步开发的PAAS平台, 增强了: CI/CD, 监控, 安全, UI等功能.)
Minishift 安装
以下步骤是在win10 专业版上进行.
先决条件
虚拟机
Minishift需要管理程序来启动配置OpenShift集群的虚拟机。在设置Minishift之前,请验证系统上是否已安装并启用了您选择的虚拟机程序。虚拟机管理程序启动并运行后,Minishift需要进行其他设置才能使用该管理程序。
Windows
:exclamation:
要将Minishift与Hyper-V配合使用,请确保在安装Hyper-V后,还可以使用Hyper-V管理器添加虚拟交换机,并在minishift配置选项
hyperv-virtual-switch
部分设置为之前添加的虚拟交换机(virtual switch)。有关特定配置步骤,请参阅“ 设置Hyper-V驱动程序”部分。
所有平台
:exclamation:
如果windows是家庭版, 没有Hyper-V的, 也可以安装VirtualBox.
建议在Windows上使用VirtualBox 5.1.12或更高版本
设置虚拟化环境
如果使用了VirtualBox, 有关详细信息,请参阅设置Minishift以使用VirtualBox。
Windows
设置Hyper-V驱动程序
要在Hyper-V中使用Minishift:
安装Hyper-V。
-
将用户添加到本地Hyper-V管理员组。
:exclamation:
这是允许用户使用Hyper-V Management API创建和删除虚拟机所必需的。有关更多信息,请参阅Hyper-V命令必须以管理员身份运行。
添加外部虚拟交换机。
确认您将虚拟交换机与连接到网络的网卡(有线或无线)配对。
安装 Minishift
windows上只能手动安装
-
从Minishift版本页面下载适用于您的操作系统的存档,并提取其内容。
-
解压压缩包内容到指定位置。
本次解压至:
C:\Program Files\minishift
目前minishift必须放在C盘
-
将
minishift
二进制文件添加到PATH
环境变量中。 -
使用配置选项
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
-
为了避免命令行下载
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
将
oc
路径添加到环境变量的PATH中. (见: 安装Minishift的图)-
运行
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
命令。
有关使用命令行界面和Web控制台与OpenShift交互的更多信息,请参阅OpenShift客户端二进制文件部分。
部署示例应用程序
OpenShift提供各种示例应用程序,例如模板(templates),构建器应用程序(builder applications)和快速入门(quickstarts)。以下步骤描述了如何从命令行部署示例Node.js应用程序。
-
创建一个Node.js示例应用程序:
$ oc new-app https://github.com/sclorg/nodejs-ex -l name=myapp
-
跟踪构建日志,直到应用程序构建和部署完毕:
$ 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
-
暴露route到对应service:
$ oc expose svc/nodejs-ex
-
访问应用程序:
$ minishift openshift service nodejs-ex --in-browser
-
本次自动分配的应用程序URL为: http://nodejs-ex-myproject.192.168.2.6.nip.io
-
要停止Minishift,请使用以下命令:
$ minishift stop Stopping local OpenShift cluster... Stopping "minishift"...
有关在OpenShift中创建应用程序的更多信息,请参阅OpenShift文档中的创建新应用程序。