OpenShift 本地開發環境配置(基於 Minishift)
- 2021 年 11 月 21 日
- 筆記
- docker, Kubernetes/OpenShift
本文要做什麼?
很多為了驗證應用在 OpenShift 平台的行為是否正常,或者組成一個簡單的開發環境,直接搭建一個 OpenShift/Origin 環境可能太重了,而且運行在本機可能佔用記憶體也太多。此時使用 MiniShift 來組成自己的開發環境就比較合適了。
本文就簡單介紹下如何配置 MiniShift 環境,無論是 Windows/Linux/MacOS都是可以安裝的,前提是你需要安裝個虛擬機軟體 virtualbox。此處將以筆者 Linux 開發環境進行演示,操作大同小異可供參考。
安裝 Minishift
官方 Github Relese Page //github.com/minishift/minishift/releases,
cd ~/Downloads
#下載v1.34.3 minishift
wget //github.com/minishift/minishift/releases/download/v1.34.3/minishift-1.34.3-linux-amd64.tgz
#解壓到/usr/bin目錄下
sudo tar zxvf minishift-1.34.3-linux-amd64.tgz -C /usr/bin
#驗證是否能執行,有版本輸出即正常
minishift version
#添加自動補全,重開shell自動提示即正常
sudo minishift completion bash > /etc/bash_completion.d/minishift
對於 Win 環境,將下載的 zip 包解壓到任意目錄,然後將minishift.exe添加環境變數Path中即可,Win下自動補全功能好像沒有。
安裝 virtualbox
官方下載地址 //www.virtualbox.org/wiki/Downloads
根據自己的平台下載安裝即可。
簡易搭建docker registry
注意,請提前規劃好docker registry埠號,配置到docker上再重啟docker服務。
docker run --name myRegistry --restart=always -d -p 5000:5000 registry
webUI 可以參考 CSDN 胡了了
的部落格 //blog.csdn.net/huqigang/article/details/76655854
搭建 Gitea
基於 docker-compose 搭建 Gitea 用於 Minishift 上傳程式碼構建鏡像。
gitea/docker-compose.yml
version: "3"
networks:
gitea:
external: false
services:
server:
image: gitea/gitea:1.15.6
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
restart: always
networks:
- gitea
volumes:
- ./gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "222:22"
啟動 Gitea
cd gitea
docker-compose up -d
啟動完成後,訪問 3000 新建用戶即可使用。
配置與啟動 Minishift
以下命令依次執行,記憶體、CPU、硬碟、非安全docker倉庫按需配置即可。
#設置虛擬機驅動
minishift config set vm-driver virtualbox
#設置openshift版本
minishift config set openshift-version 3.11.0
#設置虛擬機cpu核數
minishift config set cpus 2
#設置虛擬機記憶體
minishift config set memory 9GB
#設置虛擬機磁碟大小
minishift config set disk-size 20GB
#設置docker registry倉庫地址,剛才創建的那個
minishift config set insecure-registry 192.168.99.1:5000
#設置鏡像快取,方便刪除集群後再創建,不需要再重新拉鏡像(不開以後再拉較慢)
minishift config set image-caching true
#啟用管理員用戶插件
minishift addon enable admin-user
#啟用任意用戶uid,不設置會導致自定義鏡像部署時用戶設置不正常
minishift addon enable anyuid
#設置靜態ip,也可以不設置
minishift ip --set-static
啟動 Minishift
#啟動minishift,等待初始化完成,首次初始化較慢
hellxz@debian:~/WorkSpace/openshift$ minishift start
-- Starting profile 'minishift'
-- Check if deprecated options are used ... OK
-- Checking if //github.com is reachable ... FAIL
-- Checking if requested OpenShift version 'v3.11.0' is valid ... SKIP
-- Checking if requested OpenShift version 'v3.11.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
-- Checking if provided oc flags are supported ... OK
-- Starting the OpenShift cluster using 'virtualbox' 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 ... OK
-- Checking HTTP connectivity from the VM ...
Retrieving //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.99.115 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 ...
I1121 10:47:29.719658 2437 flags.go:30] Running "create-kubelet-flags"
I1121 10:47:30.136043 2437 run_kubelet.go:49] Running "start-kubelet"
I1121 10:47:30.373865 2437 run_self_hosted.go:181] Waiting for the kube-apiserver to be ready ...
I1121 10:48:00.400822 2437 interface.go:26] Installing "kube-proxy" ...
I1121 10:48:00.401522 2437 interface.go:26] Installing "kube-dns" ...
I1121 10:48:00.401530 2437 interface.go:26] Installing "openshift-service-cert-signer-operator" ...
I1121 10:48:00.401535 2437 interface.go:26] Installing "openshift-apiserver" ...
I1121 10:48:00.401559 2437 apply_template.go:81] Installing "openshift-apiserver"
I1121 10:48:00.402465 2437 apply_template.go:81] Installing "kube-proxy"
I1121 10:48:00.403006 2437 apply_template.go:81] Installing "kube-dns"
I1121 10:48:00.403118 2437 apply_template.go:81] Installing "openshift-service-cert-signer-operator"
I1121 10:48:35.202811 2437 interface.go:41] Finished installing "kube-proxy" "kube-dns" "openshift-service-cert-signer-operator" "openshift-apiserver"
I1121 10:48:45.237092 2437 run_self_hosted.go:242] openshift-apiserver available
I1121 10:48:45.237114 2437 interface.go:26] Installing "openshift-controller-manager" ...
I1121 10:48:45.237133 2437 apply_template.go:81] Installing "openshift-controller-manager"
I1121 10:48:47.120838 2437 interface.go:41] Finished installing "openshift-controller-manager"
Adding default OAuthClient redirect URIs ...
Adding centos-imagestreams ...
Adding registry ...
Adding router ...
Adding persistent-volumes ...
Adding web-console ...
Adding sample-templates ...
I1121 10:48:47.161522 2437 interface.go:26] Installing "centos-imagestreams" ...
I1121 10:48:47.161533 2437 interface.go:26] Installing "openshift-image-registry" ...
I1121 10:48:47.161541 2437 interface.go:26] Installing "openshift-router" ...
I1121 10:48:47.161546 2437 interface.go:26] Installing "persistent-volumes" ...
I1121 10:48:47.161554 2437 interface.go:26] Installing "openshift-web-console-operator" ...
I1121 10:48:47.161560 2437 interface.go:26] Installing "sample-templates" ...
I1121 10:48:47.161607 2437 interface.go:26] Installing "sample-templates/postgresql" ...
I1121 10:48:47.161614 2437 interface.go:26] Installing "sample-templates/nodejs quickstart" ...
I1121 10:48:47.161620 2437 interface.go:26] Installing "sample-templates/rails quickstart" ...
I1121 10:48:47.161626 2437 interface.go:26] Installing "sample-templates/jenkins pipeline ephemeral" ...
I1121 10:48:47.161632 2437 interface.go:26] Installing "sample-templates/mongodb" ...
I1121 10:48:47.161637 2437 interface.go:26] Installing "sample-templates/mysql" ...
I1121 10:48:47.161647 2437 interface.go:26] Installing "sample-templates/cakephp quickstart" ...
I1121 10:48:47.161653 2437 interface.go:26] Installing "sample-templates/dancer quickstart" ...
I1121 10:48:47.161662 2437 interface.go:26] Installing "sample-templates/django quickstart" ...
I1121 10:48:47.161684 2437 interface.go:26] Installing "sample-templates/sample pipeline" ...
I1121 10:48:47.161724 2437 interface.go:26] Installing "sample-templates/mariadb" ...
I1121 10:48:47.161772 2437 apply_list.go:67] Installing "sample-templates/mariadb"
W1121 10:48:47.162234 2437 create_secret.go:78] Error reading $HOME/.docker/config.json: open /home/docker/.docker/config.json: no such file or directory, imagestream import credentials will not be setup
I1121 10:48:47.162270 2437 apply_list.go:67] Installing "centos-imagestreams"
I1121 10:48:47.162982 2437 apply_list.go:67] Installing "sample-templates/mongodb"
I1121 10:48:47.163194 2437 apply_list.go:67] Installing "sample-templates/mysql"
I1121 10:48:47.163346 2437 apply_list.go:67] Installing "sample-templates/cakephp quickstart"
I1121 10:48:47.163459 2437 apply_list.go:67] Installing "sample-templates/dancer quickstart"
I1121 10:48:47.163564 2437 apply_list.go:67] Installing "sample-templates/django quickstart"
I1121 10:48:47.163670 2437 apply_list.go:67] Installing "sample-templates/sample pipeline"
I1121 10:48:47.163706 2437 apply_template.go:81] Installing "openshift-web-console-operator"
I1121 10:48:47.163904 2437 apply_list.go:67] Installing "sample-templates/postgresql"
I1121 10:48:47.163958 2437 apply_list.go:67] Installing "sample-templates/nodejs quickstart"
I1121 10:48:47.164070 2437 apply_list.go:67] Installing "sample-templates/rails quickstart"
I1121 10:48:47.164091 2437 apply_list.go:67] Installing "sample-templates/jenkins pipeline ephemeral"
I1121 10:48:55.790359 2437 interface.go:41] Finished installing "sample-templates/postgresql" "sample-templates/nodejs quickstart" "sample-templates/rails quickstart" "sample-templates/jenkins pipeline ephemeral" "sample-templates/mongodb" "sample-templates/mysql" "sample-templates/cakephp quickstart" "sample-templates/dancer quickstart" "sample-templates/django quickstart" "sample-templates/sample pipeline" "sample-templates/mariadb"
I1121 10:48:59.606507 2437 interface.go:41] Finished installing "centos-imagestreams" "openshift-image-registry" "openshift-router" "persistent-volumes" "openshift-web-console-operator" "sample-templates"
Server Information ...
OpenShift server started.
The server is accessible via web console at:
//192.168.99.115:8443/console
此時直接訪問輸出的地址就能訪問平台了,最好先執行下邊的命令再進平台。
啟動後配置命令:
#啟用admin用戶
minishift addons apply admin-user
#啟用任意用戶uid,允許pod使用root用戶運行(便於調試)
minishift addons apply anyuid
訪問 Minishift WebUI,那個 console 地址(本例中為//192.168.99.115:8443/console),使用 developer 和任意密碼即可登錄。
可以使用默認的 My Project
也可以自己新建,這裡使用默認的就行。
到這個熟悉的 OpenShift 介面就可以了。除了 logo 不大一樣,其餘功能都差不多。
馬上更新自定義OpenShift鏡像,靜請期待!
本文同步發布以下兩個地址,未經許可禁止轉載。