注意:
- 此教程位于 Oracle 提供的免费实验室环境中。
- 它对 Oracle Cloud Infrastructure 身份证明、租户和区间使用示例值。完成实验室后,请使用特定于云环境的那些值替换这些值。
从源构建 Oracle Cloud Native Environment
简介
Oracle Cloud Native Environment (Oracle CNE) 命令行界面 (CLI) 可管理组织中 Kubernetes 集群的生命周期。它也是 GitHub 上提供的开源项目,本教程演示了如何自行构建 ocne
可执行文件。
有关 Oracle Cloud Native Environment 2 的更多信息,请参阅当前的发行文档网站。
目标
在本教程中,您将学习:
- 配置构建环境
- 构建
ocne
可执行文件 - 使用生成的可执行文件启动 Kubernetes 集群
先决条件
-
最少一个 Oracle Linux 实例
-
每个系统都应安装 Oracle Linux 并配置以下各项:
- 具有 sudo 访问权限的 Oracle 用户帐户(在安装期间使用)
- 主机之间基于密钥的 SSH(也称为无密码 SSH)
- 工作的 KVM libvirt 环境。
配置 Oracle Cloud Native Environment
注:如果在您自己的租户中运行,请阅读 linux-virt-labs
GitHub 项目 README.md ,并在部署实验室环境之前完成先决条件。
-
在 Luna 桌面上打开一个终端。
-
克隆
linux-virt-labs
GitHub 项目。git clone https://github.com/oracle-devrel/linux-virt-labs.git
-
转到工作目录。
cd linux-virt-labs/ocne2
-
安装所需的集合。
ansible-galaxy collection install -r requirements.yml
-
部署实验室环境。
ansible-playbook create_instance.yml -e localhost_python_interpreter="/usr/bin/python3.6" -e ocne_type=libvirt
空闲实验室环境需要额外的变量
local_python_interpreter
,该变量为在 localhost 上运行的播放设置ansible_python_interpreter
。此变量是必需的,因为环境为 Python 的 Oracle Cloud Infrastructure SDK 安装 RPM 程序包,该程序包位于 python3.6 模块下。默认部署配置使用 AMD CPU 和 Oracle Linux 8。要使用 Intel CPU 或 Oracle Linux 9,请将
-e instance_shape="VM.Standard3.Flex"
或-e os_version="9"
添加到部署命令。重要提示:等待剧本成功运行并进入暂停任务。在手册的这一阶段,Oracle Cloud Native Environment 的安装已完成,实例已准备就绪。记下之前的播放,该播放会打印其部署的节点的公共和专用 IP 地址以及运行实验室时所需的任何其他部署信息。
安装先决条件
-
打开终端并通过 SSH 连接到 ocne 实例。
ssh oracle@<ip_address_of_instance>
-
安装 Git。
sudo dnf install git -y
-
克隆 Oracle CNE 资料档案库。
git clone https://github.com/oracle-cne/ocne.git
-
转到工作目录。
cd ocne
-
列出可用的 Oracle Cloud Native Environment 软件包。
sudo dnf search ocne
输出示例:
[oracle@ocne ~]$ sudo dnf search ocne Last metadata expiration check: 0:01:00 ago on Fri 28 Mar 2025 11:48:50 AM GMT. ========================================================== Name Matched: ocne =========================================================== oracle-ocne-release-el8.src : Oracle Cloud Native Environment yum repository configuration oracle-ocne-release-el8.x86_64 : Oracle Cloud Native Environment yum repository configuration
-
安装系统信息库软件包。
Oracle Linux 8
sudo dnf install -y oracle-ocne-release-el8
Oracle Linux 9
sudo dnf install -y oracle-ocne-release-el9
-
启用系统信息库。
Oracle Linux 8
sudo dnf config-manager --enable ol8_ocne
Oracle Linux 9
sudo dnf config-manager --enable ol9_ocne sudo dnf config-manager --enable ol9_olcne19
-
启用 Codeready 系统信息库。
CodeReady 系统信息库为开发人员提供了许多用于构建和打包应用程序的软件包和工具。
Oracle Linux 8
sudo dnf config-manager --enable ol8_codeready_builder
Oracle Linux 9
sudo dnf config-manager --enable ol9_codeready_builder
-
确认系统信息库已启用。
sudo dnf repolist
-
更新 Oracle Linux 9 的 Helm 要求。
Oracle Linux 8
非必填字段。
Oracle Linux 9
sed -i 's/3.13.0/3.12.0/' buildrpm/ocne.spec
-
安装先决条件。
sudo yum-builddep buildrpm/ocne.spec -y
输出示例:
[oracle@ocne ocne]$ sudo yum-builddep buildrpm/ocne.spec Oracle Linux 8 BaseOS Latest (x86_64) 317 kB/s | 4.3 kB 00:00 Oracle Linux 8 Application Stream (x86_64) 69 kB/s | 4.5 kB 00:00 Oracle Linux 8 CodeReady Builder (x86_64) - Unsupported 39 MB/s | 12 MB 00:00 Oracle Linux 8 Addons (x86_64) 184 kB/s | 3.5 kB 00:00 Oracle Cloud Native Environment version 2.0 (x86_64) 30 MB/s | 6.1 MB 00:00 Dependencies resolved. ========================================================================================================================================= Package Architecture Version Repository Size ========================================================================================================================================= Installing: btrfs-progs-devel x86_64 5.15.1-2.el8 ol8_UEKR7 49 k device-mapper-devel x86_64 8:1.02.181-15.0.1.el8_10 ol8_codeready_builder 284 k golang x86_64 1.22.9-1.module+el8.10.0+90476+bb48cc15 ol8_appstream 759 k gpgme-devel x86_64 1.13.1-12.el8 ol8_codeready_builder 166 k helm x86_64 3.17.1-2.el8 ol8_ocne 12 M libassuan-devel x86_64 2.5.1-3.el8 ol8_codeready_builder 69 k rpm-build x86_64 4.14.3-32.0.1.el8_10 ol8_appstream 174 k yq x86_64 4.45.1-1.el8 ol8_ocne 3.4 M Upgrading: btrfs-progs x86_64 5.15.1-2.el8 ol8_UEKR7 864 k ... ... python3-rpm-macros-3-45.el8.noarch qt5-srpm-macros-5.15.3-1.el8.noarch redhat-rpm-config-131-1.0.1.el8.noarch rpm-build-4.14.3-32.0.1.el8_10.x86_64 rust-srpm-macros-5-2.el8.noarch systemd-devel-239-82.0.3.el8_10.3.x86_64 yq-4.45.1-1.el8.x86_64 zstd-1.4.4-1.0.1.el8.x86_64
构建可执行文件
-
检查可用选项。
make
输出示例:
[oracle@ocne ocne]$ make Usage: make <target> help Display this help. build-cli Build CLI for the current system and architecture cli Build and install the CLI clean Delete output from prior builds Linting and coverage check Run all linters check-golangci-lint Run Go linters install-golangci-lint Install golangci-lint word-linter Check for use of 'bad' words
-
构建可执行文件。
make build-cli
输出示例:
[oracle@ocne ocne]$ make cli ... ... cd repo && helm repo index . make[1]: Leaving directory '/home/oracle/ocne/build/catalog' mkdir -p pkg/catalog/embedded/charts cp build/catalog/repo/* pkg/catalog/embedded/charts mkdir -p out/linux_amd64 GOTOOLCHAIN=local GO111MODULE=on GOPRIVATE=github.com/oracle-cne/ocne go build -trimpath -ldflags "-X 'github.com/oracle-cne/ocne/cmd/info.gitCommit=1101a5b5fb72e9812aa14cf68613d28440f1bc57' -X 'github.com/oracle-cne/ocne/cmd/info.buildDate=2025-04-02T09:54:53Z' -X 'github.com/oracle-cne/ocne/cmd/info.cliVersion=2.1.2-3.el8'" -tags developer -o out/linux_amd64 ./...
-
确认存在可执行文件。
ls -al out/linux_amd64/
输出示例:
[oracle@ocne ocne]$ ls -al out/linux_amd64/ total 194744 drwxrwxr-x. 2 oracle oracle 18 Mar 28 12:35 . drwxrwxr-x. 3 oracle oracle 25 Mar 28 12:30 .. -rwxrwxr-x. 1 oracle oracle 199415168 Mar 28 12:35 ocne
-
确认其工作正常。
out/linux_amd64/ocne info
输出示例:
[oracle@ocne ocne]$ out/linux_amd64/ocne info CLI Info Name Value Version 2.1.2-3.el8 BuildDate 2025-04-02T09:54:53Z GitCommit 1101a5b5fb72e9812aa14cf68613d28440f1bc57 Environment Variables Name Description Current Value OCNE_DEFAULTS Sets the location of the default configuration file. KUBECONFIG Sets the location of the kubeconfig file. This behaves the same way as the --kubeconfig option for most ocne commands. EDITOR Sets the default document editor.
记下 Version 和 BuildDate 值。Version 反映 Main 中的最新版本,BuildDate 反映您生成
ocne
可执行文件的日期和时间。
创建单节点集群
-
创建单个节点 Oracle Cloud Native Environment 集群。
out/linux_amd64/ocne cluster start
根据计算机的可用资源,集群创建在下载映像源并设置映像源时可能需要几分钟才能完成。
完成后,输入
y
以完成安装并返回到命令提示符。忽略安装后步骤的其余部分,然后继续执行下一步。输出示例:
Run the following command to create an authentication token to access the UI: KUBECONFIG='/home/oracle/.kube/kubeconfig.ocne.local' kubectl create token ui -n ocne-system Browser window opened, enter 'y' when ready to exit: y INFO[2025-03-28T13:10:04Z] Post install information: To access the cluster from the VM host: copy /home/oracle/.kube/kubeconfig.ocne.vm to that host and run kubectl there To access the cluster from this system: use /home/oracle/.kube/kubeconfig.ocne.local To access the UI, first do kubectl port-forward to allow the browser to access the UI. Run the following command, then access the UI from the browser using via https://localhost:8443 kubectl port-forward -n ocne-system service/ui 8443:443 Run the following command to create an authentication token to access the UI: kubectl create token ui -n ocne-system
-
安装 Kubernetes 命令行工具 (kubectl )
sudo dnf install -y kubectl
-
将 kubectl 配置为使用新创建的群集。
export KUBECONFIG=$HOME/.kube/kubeconfig.ocne.local
-
确认群集仅包含一个节点。
kubectl get nodes --all-namespaces
输出示例:
[oracle@ocne ~]$ kubectl get nodes --all-namespaces NAME STATUS ROLES AGE VERSION ocne-control-plane-1 Ready control-plane 2m23s v1.31.6+1.el8
-
确认集群的成功部署。
kubectl get deployments --all-namespaces
输出示例:
[oracle@ocne ~]$ kubectl get deployments --all-namespaces NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGE kube-system coredns 2/2 2 2 15m ocne-system ocne-catalog 1/1 1 1 15m ocne-system ui 1/1 1 1 15m
-
列出部署的所有云池。
kubectl get pods --all-namespaces
输出示例:
[oracle@ocne ~]$ kubectl get pods --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE kube-flannel kube-flannel-ds-8fbm2 1/1 Running 0. 13m kube-system coredns-f7d444b54-njk46 1/1 Running 0 13m kube-system coredns-f7d444b54-xn975 1/1 Running 0 13m kube-system etcd-ocne-control-plane-1 1/1 Running 0 13m kube-system kube-apiserver-ocne-control-plane-1 1/1 Running 0 13m kube-system kube-controller-manager-ocne-control-plane-1 1/1 Running 0 13m kube-system kube-proxy-jsfqs 1/1 Running 0 13m kube-system kube-scheduler-ocne-control-plane-1 1/1 Running 0 13m ocne-system ocne-catalog-578c959566-75rr5 1/1 Running 0 13m ocne-system ui-84dd57ff69-grxlk 1/1 Running 0 13m
此输出确认您已成功从源代码构建
ocne
并创建新的 Kubernetes 集群。
后续步骤
本教程演示了如何从 GitHub 上的源代码构建 Oracle CNE CLI,这对本地测试很有帮助。然而,这只是开始。有关其他教程和内容,请查看 Oracle Linux 培训站。
相关链接
更多学习资源
浏览 docs.oracle.com/learn 上的其他实验室,或者访问 Oracle Learning YouTube 渠道上的更多免费学习内容。此外,请访问 education.oracle.com/learning-explorer 成为 Oracle Learning Explorer。
有关产品文档,请访问 Oracle 帮助中心。
Build Oracle Cloud Native Environment from Source
G33051-01
Copyright ©2025, Oracle and/or its affiliates.