將應用程式建置到「Oracle 受管理的 Kubernetes 叢集」
若要將容器建置到 Oracle Container Engine for Kubernetes 叢集,請將影像上傳到登錄檔,然後建立描述建置到 Oracle Container Engine for Kubernetes 叢集的建置資訊清單檔案。
上傳 Docker Image 至 Oracle Cloud Infrastructure Registry
Oracle Cloud Infrastructure 登錄檔是一種專用登錄檔,可供您儲存應用程式影像。只要您的雲端基礎架構可供存取,您就可以使用任何登錄。
若要將影像上傳到 Oracle Cloud Infrastructure Registry,您必須適當標記它,然後將它上傳到登錄檔。若要上傳影像至 Oracle Cloud Infrastructure Registry,請指定 Oracle Cloud Infrastructure Registry 中您要上傳影像的目標位置完整路徑 (選擇性包括儲存區域名稱)。您已在此處指定 build.gradle
中的標記名稱,將 Docker Plugin 標記為抑制標記。
tag = 'data-region.ocir.io/my-tenant/my-repo/omc-sample-app:latest'
影像準備好上傳至 Oracle Cloud Infrastructure Registry 之後,請登入 Oracle Cloud Infrastructure 主控台來設定 Oracle Cloud Infrastructure 中的存取記號。存取記號可協助您使用 Docker 命令行介面 (CLI) 登入 Oracle Cloud Infrastructure。
- 在 Oracle Cloud Infrastructure 主控台的右上角按一下使用者功能表,然後按一下使用者設定值來檢視詳細資訊。
- 在「認證記號」頁面中,按一下產生記號。
- 在產生記號對話方塊中,輸入認證記號的易記描述,然後按一下產生記號。就會顯示新的認證記號。
- 將認證記號複製到可供您之後擷取的安全位置,因為您在 Oracle Cloud Infrastructure 主控台中不會再次看到認證記號。
- 關閉「產生記號」對話方塊並關閉 Oracle Cloud Infrastructure 主控台。
建立認證記號之後,請將您的影像上傳到 Oracle Cloud Infrastructure Registry。
- 使用標準 Docker CLI 登入 Oracle Cloud Infrastructure。
docker login data-region.ocir.io
- 以
my-tenant/username@example.com
格式輸入您的使用者名稱。在出現提示時,輸入您先前儲存的認證記號。 - 將您的影像上傳到 Oracle Cloud Infrastructure Registry。
docker push data-region.ocir.io/my-tenant/my-repo/omc-sample-app
上傳之後,您可以檢視儲存區域中的影像。
將應用程式建置到 Oracle Container Engine for Kubernetes 叢集
上傳影像之後,您必須設定 Kubernetes 部署資訊清單,才能將您的應用程式當作部署單元來管理,然後部署 Kubernetes 叢集。
此資訊清單描述根據您建立的影像,需要有一個複本的 Deployment
物件。
- 在您目前的目錄中建立類似下列的資訊清單檔案
omc-sample-svc.yaml
。apiVersion: apps/v1 kind: Deployment metadata: name: omc-sample-app spec: selector: matchLabels: app: omc-sample-app replicas: 1 template: metadata: labels: app: omc-sample-app spec: containers: - name: omc-sample-app image: data-region.ocir.io/my-tenant/my-repo/omc-sample-app:latest ports: - containerPort: 8080 --- apiVersion: v1 kind: Service metadata: name: omc-sample-app spec: selector: app: omc-sample-app ports: - protocol: "TCP" port: 8080 targetPort: 8080 type: LoadBalancer
部署名為
omc-sample-app
,可建立應用程式容器。若要整體啟用部署存取,您需要建立服務,在此例中為LoadBalancer
類型。建置時,這會自動啟動設定Oracle Cloud Infrastructure Load Balancing 執行處理,以管理和遞送流量至應用程式。 - 從目前的目錄執行
kubectl
以建置應用程式影像。kubectl apply -f omc-sample-svc.yaml