IBM Cloud Docs
Red Hat OpenShift Bastion 節點設置

Red Hat OpenShift Bastion 節點設置

為了啟用部署,需要配置虛擬機器 (VM) 以執行 Red Hat® OpenShift® 安裝步驟並託管 HTTP Server。 此虛擬機器稱為堡壘節點。 bastion 節點連接至 Red Hat OpenShift 邏輯交換器,並將 ESG 防火牆和 NAT 規則設定為允許從 jump-server 或遠端裝置進行 SSH 存取。

bastion 節點執行 Red Hat® Enterprise Linux®,用來託管指令碼、檔案和工具,以佈建開機架構、控制平面和計算節點。 部署完成後,建議保留 bastion 節點作為群集的管理節點。

防禦主機節點設定包含下列步驟:

  1. 設定一個Red Hat VM。
  2. 註冊Red Hat VM。
  3. 安裝 NGINX (HTTP 伺服器)。
  4. 產生 SSH 私密金鑰並將其新增到代理程式。

配置Red Hat機

根據下列規格配置Red Hat VM。 使用vCenter Server 使用者介面或使用本文檔後面介紹的PowerCLI腳本來置備 VM。 記錄在 NSX ESG 中配置的 NAT 位址。

Red Hat虛擬機器 - 配置
VM IP 位址 閘道 磁碟 (GB) 記憶體 (GB) vCPU NAT 位址
bastion 192.168.133.8 192.168.133.1 50 2 1 10.208.59.197

使用下表來記錄部署詳細資料:

Red Hat虛擬機器部署
參數 範例 您的部署
vCenter Server IP 位址
vCenter 伺服器使用者
vCenter Server 密碼
邏輯交換器 OpenShift-LS
vCenter Server 實例資料儲存庫 vsanDatastore
VM 名稱 bastion
ISO 檔名 rhel-8.x-x86_64-dvd.iso
IP 位址 192.168.133.8
網路遮罩 255.255.255.0
預設閘道 192.168.133.1

開始之前,請使用 vCenter CLI 或下列 PowerCLI Script 建立 VM。

# Connect to vCenter
connect-VIserver –server <IP_Address> -User <UserName> -Password '<Password>'

# Create VM
$ls = get-nsxtransportzone | get-nsxlogicalswitch OpenShift-LS | Get-NsxBackingPortGroup | Select-Object Name
$ds = get-datastore -Name vsanDatastore
$vm = New-VM -Name bastion -Datastore $ds -DiskGB 50 -DiskStorageFormat Thin -MemoryGB 2 -NumCpu 1 -Notes "OpenShift Bastion node" -NetworkName $ls.name -GuestId rhel8_64Guest

# Connect a CD Drive loaded with the RHEL ISO
New-CDDrive -VM $vm -IsoPath "[vsanDatastore] ISO\rhel-8.x-x86_64-dvd.iso" -StartConnected

#Start the VM
Start-VM -VM $vm

# Disconnect
Disconnect-NsxServer

虛擬機啟動後,透過Web控制台或遠端控制台連接到虛擬機,並完成以下安裝步驟。 如果需要,請參閱Red Hat Enterprise Linux文件。

  1. 選取所需的語言。
  2. 設定日期和時間。
  3. 配置網路和主機名稱。
  4. 選取安裝目的地。
  5. 設定 root 密碼。
  6. 建立使用者。

註冊Red Hat機

此步驟需要您的 Red Hat 訂閱詳細資料:

  • 使用者名稱
  • 密碼
  • 訂閱儲存區

在部署了 bastion 節點之後,您需要將它註冊並訂閱到 Red Hat 公共儲存庫。 從跳轉主機或遠端設備,透過 SSH 連接到堡壘節點。 使用 su 命令取得 root 權限,並在將使用者名稱、密碼和池替換為變數後執行以下命令。

export rhel_subscription_username=<email address>
export rhel_subscription_password=<password>
sudo subscription-manager register --username=${rhel_subscription_username} --password=${rhel_subscription_password} --force
subscription-manager refresh
subscription-manager attach --pool=<pool>
subscription-manager repos --disable="*"
subscription-manager repos --enable  rhel-8-server-rpms
subscription-manager repos --enable  rhel-8-server-extras-rpms
subscription-manager repos --enable  rhel-server-rhscl-8-rpms

安裝 NGINX(HTTP 伺服器)

Red Hat OpenShift 節點的部署使用 Ignition,這個過程需要 HTTP Server 可用來下載所需的組態。 此部署使用在 bastion 節點上執行的 NGINX 實例。 若要安裝 NGINX,請在連接至防禦主機節點並具有 root 專用權後完成下列步驟:

  1. 使用 vi 等文字編輯器建立下列檔案 vi /etc/yum.repos.d/nginx.repo

  2. 鍵入 i 進行插入,然後將下列資訊貼到檔案中:

    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/mainline/rhel/8/$basearch/
    gpgcheck=0
    enabled=1
    
  3. 按下 Esc 回到指令模式,然後鍵入 :wq 以儲存檔案,並結束 vi。

  4. 使用 yum 指令安裝 NGINX 套件。

    yum update
    yum install -y nginx
    
  5. 建立預設配置檔 vi /etc/nginx/conf.d/default.conf

  6. 鍵入 i 進行插入,然後將下列資訊貼到檔案中:

    server {
        listen       80;
        server_name  localhost;
    
        #charset koi8-r;
        #access_log  /var/log/nginx/host.access.log  main;
    
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
    }
    
  7. 按下 Esc 回到指令模式,然後鍵入 :wq 以儲存檔案,並結束 vi。

  8. 執行下列指令以啟動 NGINX。

    systemctl enable nginx
    systemctl start nginx
    
  9. Linux 防火牆需要使用下列 firewall-cmd 指令來配置為啟用 HTTP:

    firewall-cmd --permanent --zone=public --add-service=http
    firewall-cmd --reload
    

產生 SSH 私密金鑰並將其新增到代理程式

對於要執行安裝除錯或災難復原的 Red Hat OpenShift 容器平台叢集,您必須向安裝程式提供 ssh-agent 程序使用的 SSH 金鑰。

您可以使用此密鑰,以使用者 core 的身份 SSH 進入節點。 部署叢集時,金鑰會新增到核心使用者的 ~/.ssh/authorized_keys 清單。

必須使用本端金鑰。

建立 SSH 金鑰

  1. 在 bastion 節點的 SSH 會話中,執行下列指令,即可在 /root/.ssh 目錄中產生公開或私人 rsa 金鑰對:

    ssh-keygen -f ~/.ssh/id_rsa -t rsa -b 4096 -N ''
    

    私鑰是 /root/.ssh/id_rsa,公鑰是 /root/.ssh/id_rsa.pub

  2. 將 ssh-agent 處理程序作為背景作業啟動:

    eval "$(ssh-agent -s)"
    
  3. 將 SSH 私密金鑰新增到 ssh-agent:

    ssh-add /root/.ssh/id_rsa
    

下載安裝工具

有關安裝Red Hat OpenShift 4.14更多信息,請參閱 使用用戶置備的基礎架構在vSphere上安裝叢集

有關如何存取 Red Hat OpenShift 使用者提供者基礎架構的詳細資訊,請參閱 Internet and Telemetry access for Red Hat OpenShift Container Platform

在您安裝 Red Hat OpenShift Container Platform 之前,您需要下載一些檔案到 bastion 節點,然後解壓縮它們。 完成了下列動作:

  • 下載 unzip 以解壓縮下載的檔案。
  • 建立安裝目錄並使其成為工作目錄。
  • 下載 Red Hat OpenShift 安裝和用戶端工具。
  • 解壓縮下載的組合。
  • 將指令移至 /usr/local/bin 以方便使用。
  • 安裝 Git 下載 Red Hat OpenShift 安裝程式。
  • 將安裝程式儲存庫複製到防禦主機節點。
  • 下載 Terraform 並將其解壓縮到 /usr/local/bin 目錄以方便使用。

這些指令會在具有 root 權限的 bastion 節點的 SSH 會話中使用。 將4.x替換為目前的Red Hat OpenShift版本,例如4.14。

# Download unzip
yum install -y wget unzip

# Create an installation directory and make it the working directory
mkdir -p /opt/ocpinstall
cd /opt/ocpinstall

# Download the OpenShift installer and client tools
wget https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest-4.x/openshift-client-linux.tar.gz
wget https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest-4.x/openshift-install-linux.tar.gz

# Extract the downloaded bundles
tar -xvf openshift-client-linux.tar.gz
tar -xvf openshift-install-linux.tar.gz

# Move commands to /usr/local/bin for ease of use
mv kubectl oc openshift-install /usr/local/bin
mv openshift-install /usr/local/bin

# Install git and clone the OpenShift installer
yum install -y git
git clone -b release-4.x https://github.com/openshift/installer

# Download and extract terraform
wget https://releases.hashicorp.com/terraform/0.11.13/terraform_0.11.13_linux_amd64.zip
unzip terraform_0.11.13_linux_amd64.zip
mv terraform /usr/local/bin

Bastion 節點現在已準備好執行安裝Red Hat OpenShift 4.14步驟,這些步驟在 Red Hat OpenShift 4.14使用者提供者基礎架構安裝 中進行了說明。