Red Hat OpenShift Bastion 节点设置
为了实现部署,需要准备一台虚拟机(VM)来运行 Red Hat® OpenShift® 安装步骤并托管 HTTP Server。 这个虚拟机被称为堡垒节点。 堡垒节点连接到 Red Hat OpenShift 逻辑交换机,ESG防火墙和NAT规则配置为允许从跳转服务器或远程设备进行SSH访问。
堡垒节点运行 Red Hat® 企业版 Linux®,用于托管引导、控制平面和计算节点的脚本、文件和工具。 部署完成后,建议将堡垒节点保留为集群的管理节点。
防御主机节点设置包含以下步骤:
- 提供一个 Red Hat 虚拟机。
- 注册 Red Hat 虚拟机。
- 安装 NGINX (HTTP Server)。
- 生成 SSH 专用密钥并将其添加到代理程序。
配置 Red Hat 虚拟机
根据以下规范配置 Red Hat 虚拟机。 使用 vCenter Server 用户界面或本文档稍后将介绍的 PowerCLI 脚本来调配虚拟机。 记录在 NSX ESG 中配置的 NAT 地址。
虚拟机 | IP 地址 | 网关 | 磁盘 (GB) | 内存 (GB) | vCPU | NAT 地址 |
---|---|---|---|---|---|---|
bastion |
192.168.133.8 | 192.168.133.1 | 50 | 2 | 1 | 10.208.59.197 |
使用下表来记录部署详细信息:
参数 | 示例 | 您的部署 |
---|---|---|
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 脚本创建 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
虚拟机启动后,使用网络控制台或远程控制台连接虚拟机,完成以下安装步骤。 如有需要,请参阅 Red Hat Enterprise Linux 文档。
- 选择所需的语言。
- 设置日期和时间。
- 配置网络和主机名。
- 选择安装目标。
- 设置 root 用户密码。
- 创建用户。
注册 Red Hat 虚拟机
这一步需要您提供订阅 Red Hat 的详细信息:
- 用户名
- 密码
- 预订池
堡垒节点部署完成后,您需要将其注册并订阅到 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 Server)
Red Hat OpenShift 节点的部署使用Ignition,此过程需要 HTTP Server 才能下载所需的配置。 部署使用了堡垒节点上运行的 NGINX 实例。 要安装 NGINX,请在连接到防御主机节点并具有 root 用户特权后完成以下步骤:
-
使用文本编辑器(如vi)创建以下文件
vi /etc/yum.repos.d/nginx.repo
。 -
输入
i
以将以下信息插入并粘贴到该文件中:[nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/rhel/8/$basearch/ gpgcheck=0 enabled=1
-
按 Esc 键返回到命令方式,然后输入
:wq
以保存该文件并退出 vi。 -
使用
yum
命令安装 NGINX 软件包。yum update yum install -y nginx
-
创建缺省配置文件
vi /etc/nginx/conf.d/default.conf
。 -
输入
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; } }
-
按 Esc 键返回到命令方式,然后输入
:wq
以保存该文件并退出 vi。 -
运行以下命令启动 NGINX。
systemctl enable nginx systemctl start nginx
-
Linux 防火墙需要使用以下 firewall-cmd 命令来配置为启用 HTTP:
firewall-cmd --permanent --zone=public --add-service=http firewall-cmd --reload
生成 SSH 专用密钥并将其添加到代理程序
对于要执行安装调试或灾难恢复的 Red Hat OpenShift 容器平台集群,您必须向安装程序提供您的ssh-agent进程使用的SSH密钥。
您可以使用此密钥以用户核心身份通过SSH连接到节点。 部署集群时,密钥会添加到核心用户的 ~/.ssh/authorized_keys
列表。
必须使用本地密钥。
创建 SSH 密钥
-
在堡垒节点的 SSH 会话中,运行以下命令,该命令将在
/root/.ssh
目录中生成一对公钥或私钥rsa
:ssh-keygen -f ~/.ssh/id_rsa -t rsa -b 4096 -N ''
私钥是
/root/.ssh/id_rsa
,公钥是/root/.ssh/id_rsa.pub
。 -
将 ssh-agent 进程作为后台任务启动:
eval "$(ssh-agent -s)"
-
将 SSH 专用密钥添加到 ssh-agent:
ssh-add /root/.ssh/id_rsa
下载安装工具
有关安装 Red Hat OpenShift 4.14 的详细信息,请参阅 在 vSphere 上使用用户配置的基础架构安装群集。
有关如何访问 Red Hat OpenShift 用户提供商基础设施的更多信息,请参阅 Red Hat OpenShift 容器平台的互联网和遥测访问。
在安装 Red Hat OpenShift 容器平台之前,您需要将一些文件下载到堡垒节点上,然后解压。 完成了以下操作:
- 下载
unzip
以解压缩下载的文件。 - 创建安装目录并使其成为工作目录。
- 下载 Red Hat OpenShift 安装和客户端工具。
- 解压缩下载的捆绑软件。
- 将命令移至
/usr/local/bin
以方便使用。 - 安装 Git,下载 Red Hat OpenShift 安装程序。
- 将安装程序存储库克隆到防御主机节点。
- 下载 Terraform 并将其解压缩到
/usr/local/bin
目录以方便使用。
这些命令用于SSH会话,以访问具有root权限的堡垒节点。 将 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 用户提供程序基础结构安装。