附註:
- 此教學課程可在 Oracle 提供的免費實驗室環境中取得。
- 它使用 Oracle Cloud Infrastructure 證明資料、租用戶及區間的範例值。完成實驗室時,請將這些值取代為您雲端環境特定的值。
從來源建置 Oracle Cloud Native Environment
簡介
Oracle Cloud Native Environment (Oracle CNE) Command Line Interface (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
,此變數會設定ansible_python_interpreter
代表在 localhost 上執行的播放。環境會安裝 Oracle Cloud Infrastructure SDK for Python 的 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 build-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=be1686eb469d885d293df74d6b5232f576fcdae8' -X 'github.com/oracle-cne/ocne/cmd/info.buildDate=2025-05-20T09:14:21Z' -X 'github.com/oracle-cne/ocne/cmd/info.cliVersion=2.1.2-5.el8'" -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 值。版本反映主要中的最新版本,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
-
列出所有已部署的 Pod。
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 Training Station 以獲取其他教學和內容。
相關連結
其他學習資源
探索 docs.oracle.com/learn 上的其他實驗室,或存取 Oracle Learning YouTube 頻道上的更多免費學習內容。此外,請造訪 education.oracle.com/learning-explorer 以成為 Oracle Learning Explorer。
如需產品文件,請造訪 Oracle Help Center 。
Build Oracle Cloud Native Environment from Source
G33054-02
Copyright ©2025, Oracle and/or its affiliates.