• OpenShift 本地开发环境配置(基于 Minishift)


    本文要做什么?

    很多为了验证应用在 OpenShift 平台的行为是否正常,或者组成一个简单的开发环境,直接搭建一个 OpenShift/Origin 环境可能太重了,而且运行在本机可能占用内存也太多。此时使用 MiniShift 来组成自己的开发环境就比较合适了。

    本文就简单介绍下如何配置 MiniShift 环境,无论是 Windows/Linux/MacOS都是可以安装的,前提是你需要安装个虚拟机软件 virtualbox。此处将以笔者 Linux 开发环境进行演示,操作大同小异可供参考。

    安装 Minishift

    官方 Github Relese Page https://github.com/minishift/minishift/releases,

    cd ~/Downloads
    #下载v1.34.3 minishift
    wget https://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

    官方下载地址 https://www.virtualbox.org/wiki/Downloads

    根据自己的平台下载安装即可。

    简易搭建docker registry

    注意,请提前规划好docker registry端口号,配置到docker上再重启docker服务。

    docker run --name myRegistry --restart=always -d -p 5000:5000 registry
    

    webUI 可以参考 CSDN 胡了了 的博客 https://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 https://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 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.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:
        https://192.168.99.115:8443/console
    

    此时直接访问输出的地址就能访问平台了,最好先执行下边的命令再进平台。

    启动后配置命令:

    #启用admin用户
    minishift addons apply admin-user
    #启用任意用户uid,允许pod使用root用户运行(便于调试)
    minishift addons apply anyuid
    

    访问 Minishift WebUI,那个 console 地址(本例中为https://192.168.99.115:8443/console),使用 developer 和任意密码即可登录。

    可以使用默认的 My Project 也可以自己新建,这里使用默认的就行。

    到这个熟悉的 OpenShift 界面就可以了。除了 logo 不大一样,其余功能都差不多。

    马上更新自定义OpenShift镜像,静请期待!

    本文同步发布以下两个地址,未经许可禁止转载。

  • 相关阅读:
    HDU 3833 YY's new problem ()
    从文件读入16进制数转化为10进制数再输出到文件中
    UESTC 1215 (思维题 旋转)
    HDU2067卡特兰数
    HDU2050离散数学折线分割平面
    cshell学习
    C++学习1
    QT学习1
    QT Creator常用快捷键
    Ubuntu14.04安装QT5.5
  • 原文地址:https://www.cnblogs.com/hellxz/p/15585460.html
Copyright © 2020-2023  润新知