Microshift 安裝

circle-info

本文轉寫時間為 2024年01月02日,內容可能會有變動,僅記錄

什麼是 MicroShift?

MicroShift 的 Red Hat® 版本是一個輕量級的 Kubernetes 容器編排解決方案,由 Red Hat® OpenShift® 的邊緣功能構建,基於同名的開源社區項目。作為 Red Hat Device Edge 的一部分,它具有特意構建的最小占地面積,結合了運行在由 Red Hat Enterprise Linux 構建的邊緣優化操作系統上的 MicroShift 企業就緒發行版。MicroShift 將 Kubernetes 的強大和可擴展性帶到邊緣,作為 OpenShift 環境的自然擴展,使應用程序只需編寫一次,就能在需要的地方運行 - 靠近數據源或終端用戶。基本上,這是一個微型的 Kubernetes。

第一種安裝 透過 CentOS 8

需求

  • os: Centos 8 Stream

  • CPU: 2core

  • Memory: 2GB

步驟

  1. 安裝 cri-o

    exoprt OS=CentOS_8_Stream
    export VERSION=1.24
    
    curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable.repo https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/devel:kubic:libcontainers:stable.repo
    curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.repo https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$VERSION/$OS/devel:kubic:libcontainers:stable:cri-o:$VERSION.repo
    
    yum install cri-o cri-tools
    systemctl enable crio --now
  2. 由於centos8和cri-o 1.24 有Bug 需要修改 /etc/containers/policy.json ,需修改 keyPaths 為以下內容

    "keyPath": "/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release"
  3. 關閉防火牆

    systemctl stop firewalld.service
    systemctl disable firewalld.service
  4. 安裝 mircoshift

    yum copr enable  -y @redhat-et/microshift
    yum install -y microshift
    systemctl enable microshift --now
  5. 下載 oc cli

    wget https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/4.8.30/openshift-client-linux.tar.gz
    
    tar -xvf openshift-client-linux.tar.gz
    
    mv openshift-client-linux/oc /usr/local/bin
  6. 取得 kubeconfig

    mkdir .kube
    cp /var/lib/microshift/resources/kubeadmin/kubeconfig .kube/config
  7. 使用 oc 確認狀態

     oc get pod -A
    
    NAMESPACE                       NAME                                  READY   STATUS    RESTARTS   AGE
    kube-system                     kube-flannel-ds-rb4fx                 1/1     Running   0          130m
    kubevirt-hostpath-provisioner   kubevirt-hostpath-provisioner-kgzdq   1/1     Running   0          127m
    openshift-dns                   dns-default-6sf47                     2/2     Running   0          123m
    openshift-dns                   node-resolver-kwws6                   1/1     Running   0          169m
    openshift-ingress               router-default-6c96f6bc66-gjdg6       1/1     Running   0          169m
    openshift-service-ca            service-ca-7bffb6f6bf-k42km           1/1     Running   0          169m

第二種安裝 透過 Rhel 9.2

需求

  • os: Rhel 9.2

  • CPU: 2core

  • Memory: 2GB

步驟

  1. 註冊 redhatarrow-up-right 帳號 https://tinyl.io/9yyw

  1. 下載rhel 9.2 ISO

  2. 安裝rhel,請安裝 GUI,還有過程中需要輸入redhat 帳號註冊

  3. 安裝完成後進入 OS

  4. 安裝 Flatpak

  5. 啟用 Red Hat build of MicroShift repositories

  6. 安裝 microshift

  7. Red Hat Hybrid Cloud Consolearrow-up-right 下載 pull-secret 到暫存目錄 $HOME/openshift-pull-secret,這個 pull-secret 可允許對container image 進行身份驗證,該image 由 MicroShift 的 Red Hat 版本使用的 container registry 提供。

  1. 複製 pull-secret 到 /etc/crio

  2. 修改 /etc/crio/openshift-pull-secret 的使用者為 root 和 600 權限

  1. 設定 firewall

  1. 啟動 microshift

  1. 取得 kubeconfig

  2. 確認服務是否正常

Podman integration microshift

https://www.opensourcerers.org/2023/11/13/podman-desktop-integration-with-microshift-in-a-rhel-virtual-machine/

安裝podman Desktop

  1. 安裝podman Desktop

安裝完成後,可以啟動 podman Desktop

透過podman 佈署 pod

  1. 重啟 podman Desktop,會看到下方出現 microshift

  2. 如果要看到其他 namespace 的 pod 請修改 .kube/config 內的 namespace 名稱,這裡我們保持使用 default namespace

  3. 接下來透過 podman Desktop 佈署服務到 MicroShift ,下載 nginx image

  4. 這裡可以先建一個 container (由 podman 管理)

    佈署後可以看到 container

  5. 從剛剛的 container 選擇 Deploy to kubernetes

    選項需勾選 security context

  6. 回到 microshift 使用 oc cli 查看pod,可以看到都pod svc 都有建立

  7. 透過瀏覽器存取 svc IP,成功連到 nginx

Last updated