注意:

部署 Oracle Cloud Native Environment

简介

Oracle Cloud Native Environment 是完全集成的云原生应用开发和管理套件。Kubernetes 模块是核心模块。它用于部署和管理容器,还会自动安装和配置 CRI-O、runC 和 Kata 容器。CRI-O 管理 Kubernetes 集群的容器运行时。运行时可以是 runC 或 Kata 容器。

目标

此实验室演示了如何:

先决条件

本节列出了用于执行本教程中的步骤的主机系统。要成功,需要:

设置实验室环境

注意:使用免费实验室环境时,请参见 Oracle Linux Lab Basics 了解连接和其他使用说明。

此实验涉及多个系统,每个系统都需要执行不同的步骤。建议首先打开三个终端窗口并连接到 ocne-operatorocne-controlocne-worker 节点。这样无需重复登录和注销。

  1. 打开一个终端并通过 ssh 连接到三个节点中的每个节点。

    ssh oracle@<ip_address_of_ol_node>
    

注意当某个步骤在练习中说“(在所有节点上)”时,对 ocne-operatorocne-controlocne-worker 执行这些操作。此方法的原因是避免重复,因为所需的操作在每个节点上将相同。

(可选)更新 Oracle Linux

  1. (在所有节点上)确保 Oracle Linux 是最新的。

    sudo dnf -y update
    

    完成此操作可能需要几分钟时间;如果此步骤单独在每个节点上并行执行,可能会节省时间。

  2. (在所有节点上)重新引导并重新连接。

    sudo reboot
    
  3. (在所有节点上)系统重新引导后,通过 ssh 重新连接到节点。

    ssh oracle@<ip_address_of_ol_node>
    

安装并启用 Oracle Cloud Native Environment Yum 资料档案库

  1. (在所有节点上)安装 yum 系统信息库。

    sudo dnf -y install oracle-olcne-release-el8
    
  2. (在所有节点上)启用当前的 Oracle Cloud Native Environment 存储库。

    sudo dnf config-manager --enable ol8_olcne15 ol8_addons ol8_baseos_latest ol8_appstream ol8_UEKR6
    
  3. (在所有节点上)禁用所有以前的系统信息库版本。

    sudo dnf config-manager --disable ol8_olcne12 ol8_olcne13 ol8_olcne14 ol8_developer
    

安装并启用 Chrony

  1. (在所有节点上)如果系统中尚不可用,请安装并启用时间较长的服务。

    检查是否已安装时序。

    sudo dnf list --installed chrony
    

    如果未安装,请按时安装。

    sudo dnf -y install chrony
    sudo systemctl enable --now chronyd
    

    注:免费实验室环境已安装并配置了时间较长的服务。

禁用交换

  1. (在所有节点上)在所有节点上禁用交换。

    sudo swapoff -a
    sudo sed -i '/swap/ s/^#*/#/' /etc/fstab
    

配置 Oracle Linux 防火墙

注:默认情况下,在 Oracle Linux 上安装并运行防火墙服务。

  1. (在 ocne-operator 上)设置操作员节点的防火墙规则。

    sudo firewall-cmd --add-port=8091/tcp --permanent
    sudo firewall-cmd --reload
    
  2. (在 ocne-control 上)设置控制层节点的防火墙规则。

    sudo firewall-cmd --zone=trusted --add-interface=cni0 --permanent
    sudo firewall-cmd --add-port=8090/tcp --permanent
    sudo firewall-cmd --add-port=10250/tcp --permanent
    sudo firewall-cmd --add-port=10255/tcp --permanent
    sudo firewall-cmd --add-port=8472/udp --permanent
    sudo firewall-cmd --add-port=6443/tcp --permanent
    sudo firewall-cmd --reload
    
  3. (在 ocne-control 上)添加用于高可用性和通过验证所需的以下内容。

    sudo firewall-cmd --add-port=10251/tcp --permanent
    sudo firewall-cmd --add-port=10252/tcp --permanent
    sudo firewall-cmd --add-port=2379/tcp --permanent
    sudo firewall-cmd --add-port=2380/tcp --permanent
    sudo firewall-cmd --reload
    
  4. (在 ocne-worker 上)设置 worker 节点的防火墙规则。

    sudo firewall-cmd --zone=trusted --add-interface=cni0 --permanent
    sudo firewall-cmd --add-port=8090/tcp --permanent
    sudo firewall-cmd --add-port=10250/tcp --permanent
    sudo firewall-cmd --add-port=10255/tcp --permanent
    sudo firewall-cmd --add-port=8472/udp --permanent
    sudo firewall-cmd --reload
    

装入桥过滤模块

  1. (在 ocne-controlocne-worker 上)启用并装入模块。

    sudo modprobe br_netfilter
    sudo sh -c 'echo "br_netfilter" > /etc/modules-load.d/br_netfilter.conf'
    

设置操作员节点

操作员节点执行和管理环境部署,包括部署 Kubernetes 集群。操作员节点可以是 Kubernetes 集群中的节点或单独的主机,例如本教程中的节点。在操作员节点上安装 Oracle Cloud Native Environment Platform CLI、Platform API 服务器和实用程序。

  1. (在 ocne-operator 上)安装平台 CLI、平台 API 服务器和实用程序。

    sudo dnf -y install olcnectl olcne-api-server olcne-utils
    
  2. (在 ocne-operator 上)启用 olcne-api-server 服务,但不启动该服务。

    sudo systemctl enable olcne-api-server.service
    

设置 Kubernetes 节点

Kubernetes 控制层和 worker 节点包含 Oracle Cloud Native Environment Platform Agent 和实用程序包。

  1. (在 ocne-controlocne-worker 上)安装平台代理软件包和实用程序。

    sudo dnf -y install olcne-agent olcne-utils
    
  2. (在 ocne-controlocne-worker 上)启用 olcne-agent(但不启动)。

    sudo systemctl enable olcne-agent.service
    

以上步骤为每个节点完成初始设置和软件安装。

(可选)代理服务器配置

如果使用代理服务器,请在每个 Kubernetes 节点上使用 CRI-O 进行配置。

注意:在免费实验室环境中需要此操作。

  1. (在所有节点上)创建 CRIO 服务。

    sudo mkdir /etc/systemd/system/crio.service.d
    
  2. (在所有节点上)打开带有 vi 的代理配置文件并将其设置为“插入”模式。

    sudo vi /etc/systemd/system/crio.service.d/proxy.conf
    
  3. (在所有节点上)使用以下示例文件替换环境中的相应代理值。

    [Service]
    Environment="HTTP_PROXY=proxy.example.com:80"
    Environment="HTTPS_PROXY=proxy.example.com:80"
    Environment="NO_PROXY=.example.com,192.0.2.*"
    

设置 X.509 专用 CA 证书

使用提供的 /etc/olcne/gen-certs-helper.sh 脚本为节点生成专用 CA 和证书。从操作员节点上的 /etc/olcne 目录运行脚本,将证书文件保存在当前目录中。

  1. (在 ocne-operator 上创建 X.509 证书。

    cd /etc/olcne
    sudo ./gen-certs-helper.sh \
    --cert-request-organization-unit "My Company Unit" \
    --cert-request-organization "My Company" \
    --cert-request-locality "My Town" \
    --cert-request-state "My State" \
    --cert-request-country US \
    --cert-request-common-name pub.linuxvirt.oraclecvn.com \
    --nodes ocne-worker.pub.linuxvirt.oraclevcn.com,ocne-control.pub.linuxvirt.oraclevcn.com,ocne-operator.pub.linuxvirt.oraclevcn.com
    

    使用 --cert-request* 选项提供专用 CA 信息。示例中存在其中一些选项。运行 gen-certs-helper.sh --help 命令以获取完整的选项列表。

    • --cert-request-common-name:为您的环境提供适当的域名系统 (Domain Name System, DNS) 域名。
    • --nodes:提供操作员、控制层和 worker 节点的全限定域名 (FQDN)。

传输 X.509 专用 CA 证书

生成证书后,将其复制到每个节点。

  1. (在 ocne-operator 上)更新提供的传输脚本中的用户详细信息。

    sudo sed -i 's/USER=opc/USER=oracle/g' configs/certificates/olcne-tranfer-certs.sh
    

    教程需要此步骤,因为脚本的默认用户是 opc。自使用用户 oracle 安装产品以来,请相应地更新脚本中的 USER 变量。

  2. (在 ocne-operator 上)为证书创建脚本生成的每个 node.key 设置权限。

    sudo chmod 644 /etc/olcne/configs/certificates/tmp-olcne/ocne-control.pub.linuxvirt.oraclevcn.com/node.key
    sudo chmod 644 /etc/olcne/configs/certificates/tmp-olcne/ocne-operator.pub.linuxvirt.oraclevcn.com/node.key
    sudo chmod 644 /etc/olcne/configs/certificates/tmp-olcne/ocne-worker.pub.linuxvirt.oraclevcn.com/node.key
    
  3. (在 ocne-operator 上)将脚本传输到每个节点。

    此步骤要求在节点之间配置无口令 SSH。此教程的配置超出本教程的范围,但在免费实验室环境中进行了预配置。

    bash -ex /etc/olcne/configs/certificates/olcne-tranfer-certs.sh
    
  4. (在所有节点上)验证正确复制的文件。

    sudo -u olcne ls /etc/olcne/configs/certificates/production
    

    输出示例:

    [oracle@ocne-control ~]$ sudo -u olcne ls /etc/olcne/configs/certificates/production
    ca.cert  node.cert  node.key
    

为 externalIPs Kubernetes 服务设置 X.509 证书

externalip-validation-webhook-service Kubernetes 服务要求在部署 Kubernetes 之前设置 X.509 证书。

  1. (在 ocne-operator 上)生成证书。

    cd /etc/olcne
    sudo ./gen-certs-helper.sh \
    --cert-dir /etc/olcne/configs/certificates/restrict_external_ip/ \
    --cert-request-organization-unit "My Company Unit" \
    --cert-request-organization "My Company" \
    --cert-request-locality "My Town" \
    --cert-request-state "My State" \
    --cert-request-country US \
    --cert-request-common-name cloud.example.com \
    --nodes externalip-validation-webhook-service.externalip-validation-system.svc,\
    externalip-validation-webhook-service.externalip-validation-system.svc.cluster.local \
    --one-cert \
    --byo-ca-cert /etc/olcne/configs/certificates/production/ca.cert \
    --byo-ca-key /etc/olcne/configs/certificates/production/ca.key
    
    • --byo-ca-*:此选项使用以前创建的 CA 证书和密钥。
  2. (在 ocne-operator 上)设置包含证书创建脚本生成的 node.key 的目录的权限。

    sudo chown -R oracle:oracle /etc/olcne/configs/certificates/restrict_external_ip/
    

引导平台 API 服务器

  1. (在 ocne-operator 上)运行引导脚本以将平台 API 服务器配置为使用证书。

    sudo /etc/olcne/bootstrap-olcne.sh \
    --secret-manager-type file \
    --olcne-node-cert-path /etc/olcne/configs/certificates/production/node.cert \
    --olcne-ca-path /etc/olcne/configs/certificates/production/ca.cert \
    --olcne-node-key-path /etc/olcne/configs/certificates/production/node.key \
    --olcne-component api-server
    

    输出示例:

    [oracle@ocne-operator olcne]$ sudo /etc/olcne/bootstrap-olcne.sh \
    > --secret-manager-type file \
    > --olcne-node-cert-path /etc/olcne/configs/certificates/production/node.cert \
    > --olcne-ca-path /etc/olcne/configs/certificates/production/ca.cert \
    > --olcne-node-key-path /etc/olcne/configs/certificates/production/node.key \
    > --olcne-component api-server
    * olcne-api-server.service - API server for Oracle Linux Cloud Native Environments
       Loaded: loaded (/usr/lib/systemd/system/olcne-api-server.service; enabled; vendor preset: disabled)
      Drop-In: /etc/systemd/system/olcne-api-server.service.d
               `-10-auth.conf
       Active: active (running) since Wed 2022-05-11 13:35:19 GMT; 2s ago
     Main PID: 96132 (olcne-api-serve)
        Tasks: 7 (limit: 203120)
       Memory: 12.2M
       CGroup: /system.slice/olcne-api-server.service
               `-96132 /usr/libexec/olcne-api-server -i /etc/olcne/modules --secret-manager-type file --olcne-ca-path /etc/olcne...
    
    May 11 13:35:19 ocne-operator systemd[1]: Started API server for Oracle Linux Cloud Native Environments.
    May 11 13:35:19 ocne-operator olcne-api-server[96132]: time=11/05/22 13:35:19 level=info msg=Api server listening on: 8091
    
    • 或者,可以使用由 HashiCorp Vault 管理的证书。本教程不包括使用该方法。
  2. (在 ocne-operator 上)确认平台 API 服务器正在运行。

    sudo systemctl status olcne-api-server
    

    输出示例:

    [oracle@ocne-operator olcne]$ sudo systemctl status olcne-api-server
     * olcne-api-server.service - API server for Oracle Linux Cloud Native Environments
       Loaded: loaded (/usr/lib/systemd/system/olcne-api-server.service; enabled; vendor preset: disabled)
      Drop-In: /etc/systemd/system/olcne-api-server.service.d
               `-10-auth.conf
       Active: active (running) since Wed 2022-05-11 10:44:30 GMT; 9min ago
     Main PID: 59600 (olcne-api-serve)
        Tasks: 7 (limit: 203120)
       Memory: 12.6M
       CGroup: /system.slice/olcne-api-server.service
               `-59600 /usr/libexec/olcne-api-server -i /etc/olcne/modules --secret-manager-type file --olcne-ca-path /etc/olcne/c>
    
    May 11 10:44:30 ocne-operator systemd[1]: Started API server for Oracle Linux Cloud Native Environments.
    May 11 10:44:30 ocne-operator olcne-api-server[59600]: time=11/05/22 10:44:30 level=info msg=Api server listening on: 8091 ...
    
  3. (在 ocne-operator 上)按 'q' 退出进程并继续执行下一步。

引导平台代理

  1. (在 ocne-control 和 ocne-worker 上)运行引导脚本以将平台代理配置为使用证书。

    sudo /etc/olcne/bootstrap-olcne.sh \
    --secret-manager-type file \
    --olcne-node-cert-path /etc/olcne/configs/certificates/production/node.cert \
    --olcne-ca-path /etc/olcne/configs/certificates/production/ca.cert \
    --olcne-node-key-path /etc/olcne/configs/certificates/production/node.key \
    --olcne-component agent
    

输出示例:

[oracle@ocne-worker ~]$ sudo /etc/olcne/bootstrap-olcne.sh \
> --secret-manager-type file \
> --olcne-node-cert-path /etc/olcne/configs/certificates/production/node.cert \
> --olcne-ca-path /etc/olcne/configs/certificates/production/ca.cert \
> --olcne-node-key-path /etc/olcne/configs/certificates/production/node.key \
> --olcne-component agent
* olcne-agent.service - Agent for Oracle Linux Cloud Native Environments
   Loaded: loaded (/usr/lib/systemd/system/olcne-agent.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/olcne-agent.service.d
           `-10-auth.conf
   Active: active (running) since Wed 2022-05-11 11:13:58 GMT; 2s ago
 Main PID: 66500 (olcne-agent)
    Tasks: 8 (limit: 203120)
   Memory: 7.1M
   CGroup: /system.slice/olcne-agent.service
           `-66500 /usr/libexec/olcne-agent --secret-manager-type file --olcne-ca-path /etc/olcne/configs/certificates/produc...

May 11 11:13:58 ocne-control systemd[1]: Started Agent for Oracle Linux Cloud Native Environments.
May 11 11:13:58 ocne-control olcne-agent[66500]: time=11/05/22 11:13:58 level=info msg=Started server on[::]:8090

创建平台 CLI 配置文件

管理员可以使用配置文件来简化环境和模块的创建和管理。以有效的 YAML 语法编写的配置文件包含有关要创建的环境和模块的所有信息。使用配置文件可以保存平台 CLI 命令选项的重复条目。

在实验室部署期间,将自动生成配置文件并准备在练习中使用。有关手动创建配置文件的更多信息,请参见Using a Configuration File中的文档。

  1. (在 ocne-operator 上)查看配置文件内容。

    cat ~/myenvironment.yaml
    

创建环境和 Kubernetes 模块

  1. (在 ocne-operator 上)创建环境。

    cd ~
    olcnectl environment create --config-file myenvironment.yaml
    

    输出示例:

    [oracle@ocne-operator ~]$ olcnectl environment create --config-file myenvironment.yaml
    Environment myenvironment created.
    
  2. (在 ocne-operator 上)创建 Kubernetes 模块。

    olcnectl module create --config-file myenvironment.yaml
    

    输出示例:

    [oracle@ocne-operator ~]$ olcnectl module create --config-file myenvironment.yaml
    Modules created successfully.
    
  3. (在 ocne-operator 上)验证 Kubernetes 模块。

    olcnectl module validate --config-file myenvironment.yaml
    

    输出示例:

    [oracle@ocne-operator ~]$ olcnectl module validate --config-file myenvironment.yaml
    Validation of module mycluster succeeded.
    

    在此示例中,没有验证错误。如果存在任何错误,则修复节点所需的命令将作为此命令的输出提供。

  4. (在 ocne-operator 上)安装 Kubernetes 模块。

    olcnectl module install --config-file myenvironment.yaml
    

    将 Kubernetes 部署到节点可能需要几分钟时间才能完成。

    输出示例:

    [oracle@ocne-operator ~]$ olcnectl module install --config-file myenvironment.yaml
    Modules installed successfully.
    
  5. (在 ocne-operator 上)验证 Kubernetes 模块的部署。

    olcnectl module instances --config-file myenvironment.yaml
    

    输出示例:

    [oracle@ocne-operator ~]$ olcnectl module instances --config-file myenvironment.yaml
    INSTANCE                                     	MODULE    	STATE    
    mycluster                                    	kubernetes	installed
    ocne-control.pub.linuxvirt.oraclevcn.com:8090	node      	installed
    ocne-worker.pub.linuxvirt.oraclevcn.com:8090 	node      	installed
    

设置 kubectl

  1. (在 ocne-control 上)设置 kubectl 命令。

    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config
    export KUBECONFIG=$HOME/.kube/config
    echo 'export KUBECONFIG=$HOME/.kube/config' >> $HOME/.bashrc
    
  2. (在 ocne-control 上)验证 kubectl 是否正常工作。

    kubectl get nodes
    

    输出示例:

    [oracle@ocne-control ~]$ kubectl get nodes
    NAME           STATUS   ROLES                  AGE   VERSION
    ocne-control   Ready    control-plane,master   10m   v1.22.8+1.el8
    ocne-worker    Ready    <none>                 10m   v1.22.8+1.el8
    

详细信息

更多学习资源

docs.oracle.com/learn 上浏览其他实验室,或者在 Oracle Learning YouTube 渠道上访问更多免费学习内容。此外,访问 education.oracle.com/learning-explorer 以成为 Oracle Learning Explorer。

有关产品文档,请访问 Oracle 帮助中心