溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何在兩個OpenShift集群間遷移有狀態應用

發布時間:2020-08-10 06:31:29 來源:ITPUB博客 閱讀:319 作者:portworx 欄目:開發技術
Portworx Kubemotion: 在OpenShift集群間遷移有狀態應用
如何在兩個OpenShift集群間遷移有狀態應用
Portworx是一個支撐K8S有狀態應用的持久存儲和數據管理平臺。通過Portworx,它為有狀態應用提供了一個單一的數據管理層,從而用戶可以在任何底層架構上運行類似數據庫這樣的有狀態應用。
Kubemotion是Portworx的核心功能之一,發布在Portworx企業版2.0中。它賦能K8S用戶在集群間遷移應用和數據、備份和恢復、以及做藍綠部署。(https://docs.portworx.com/portworx-install-with-kubernetes/migration/kubemotion/)
下面我們介紹如何在紅帽OpenShift集群之間,遷移有狀態應用的持久卷和相關K8S資源。
背景
在企業客戶中,一個常見的場景是:在一個云區域中運行研發測試環境,而在另一個云區域中運行生產環境。研發測試環境通常會選擇距離開發團隊比較近,以降低網絡延遲,而生產環境則會選擇離用戶比較近。
K8S的無狀態應用遷移相對比較容易,但遷移有狀態應用是一個挑戰。
在演示中,我們會在AWS位于美國東部(俄亥俄),和美國西部(俄勒岡)的兩個數據中心的Openshift集群間,遷移K8S資源。美國東部區域(俄亥俄)部署的是研發測試環境,美國西部區域(俄勒岡)部署的是生產環境。在系統的測試環節完成后,開發團隊將使用Portworx和Kubemotion,把存儲卷和應用資源,從研發測試環境,遷移到生產環境中。

如何在兩個OpenShift集群間遷移有狀態應用

研發測試環境和生產環境
我們有兩個紅帽OpenShift集群,分別是研發測試環境、以及生產環境,位于AWS的兩個不同區域上,兩個環境都安裝了最新版本的Portworx集群,并且正在運行。 如何在兩個OpenShift集群間遷移有狀態應用 如何在兩個OpenShift集群間遷移有狀態應用上面的OpenShift集群代表了運行在AWS東部區域(俄亥俄)的研發測試環境。

如何在兩個OpenShift集群間遷移有狀態應用

如何在兩個OpenShift集群間遷移有狀態應用

上面的OpenShift集群代表了運行在AWS西部區域(俄勒岡)的生產環境。
現在有一個基于LAMP的內容管理系統(CMS)運行在研發測試環境上,我們需要把它遷移到生產環境里。
研發測試環境里部署了MySQL和WordPress,它們都位于CMS命名空間里。
關于如何在OpenShift上配置高可用的WordPress,可以參考這里的文檔。(https://www.portworx.com/run-multi-tenant-ha-wordpress-platform-red-hat-openshift/) 如何在兩個OpenShift集群間遷移有狀態應用

Portworx存儲集群支撐了附加在這些Pod上的持久卷。

如何在兩個OpenShift集群間遷移有狀態應用

下面的卷附加到了MySQL pod上。

如何在兩個OpenShift集群間遷移有狀態應用

對于WordPress CMS, 有個共享的Portworx卷附加到了Pod上。

如何在兩個OpenShift集群間遷移有狀態應用

配置好的應用,可以通過WordPress相關的服務來訪問。

如何在兩個OpenShift集群間遷移有狀態應用 如何在兩個OpenShift集群間遷移有狀態應用
準備源環境和目標環境
在我們遷移之前,我們需要配置源集群和目標集群。按照下面的步驟來準備相關的環境。
創建對象存儲的訪問身份驗證我們需要在源集群和目標集群上都創建對象存儲的訪問身份驗證信息。我們需要獲得目標集群的UUID,它會被附加在訪問身份的名稱上。

為了完成這一步,你需要AWS賬戶的訪問密鑰和Secret密鑰。如果你已經配置好了AWS CLI,可以在這里發現這些密鑰。 ~/.aws/credentials

回到生產環境集群,運行下面的命令來復制UUID。

PX_POD=$(oc get pods -l name=portworx -n kube-system -o jsonpath='{.items[0].metadata.name}')oc -n=kube-system exec $PX_POD -- /opt/pwx/bin/pxctl status

如何在兩個OpenShift集群間遷移有狀態應用

記下集群的UUID,放在一個安全的地方。

我們在生產環境內,來創建生產環境集群的身份驗證信息。

oc -n=kube-system exec $PX_POD -- /opt/pwx/bin/pxctl credentials create \	--provider s3 \	--s3-access-key  \	--s3-secret-key  \	--s3-region ap-southeast-1  \	--s3-endpoint s3.ap-southeast-1.amazonaws.com clusterPair_c02528e3-30b1-43e7-91c0-c26c111d57b3

確保身份驗證信息的名稱按照這樣的格式:‘clusterPair_UUID’。

如何在兩個OpenShift集群間遷移有狀態應用回到研發測試集群,重復操作來創建身份驗證信息。 如何在兩個OpenShift集群間遷移有狀態應用
獲取目標集群的Token
下一步是獲取生產環境集群的Token,它會被用來創建集群配對的YAML文件。
到生產環境集群,運行下面的命令來訪問Token。
PX_POD=$(oc get pods -l name=portworx -n kube-system -o jsonpath='{.items[0].metadata.name}')oc -n=kube-system exec $PX_POD -- /opt/pwx/bin/pxctl cluster token show

如何在兩個OpenShift集群間遷移有狀態應用

記下集群Token,放置在一個安全的地方。
為Portworx服務獲取負載均衡的端點
我們還需要生產環境集群上的,與Portworx服務關聯的負載均衡的DNS名稱。我們可以通過下面的命令得到。
oc describe svc portworx-service -n kube-system

如何在兩個OpenShift集群間遷移有狀態應用

到這里,你已經準備好下面的數據了:

1.   目標集群的Token

2.   指向Portworx服務的負載均衡的CNAME

創建集群配對參數

我們從生產環境(目標集群)來創建YAML文件。并且把它應用到研發測試環境(源集群)。

確保你在在生產環境中,運行下面的命令。

storkctl generate clusterpair -n cms prodcluster > clusterpair.yaml

打開clusterpair.yaml,在選項中增加下面的細節信息。它們反映了目標集群里的負載均衡的IP地址或者DNS名稱,以及與目標集群關聯的Token。

如何在兩個OpenShift集群間遷移有狀態應用

為Kubemotion進行集群配對

通過為源集群配置配對參數,我們可以把集群進行配對。

我們回到源集群(研發測試環境),來進行集群配對。

oc apply -f clusterpair.yaml
oc get clusterpair -n cms

如何在兩個OpenShift集群間遷移有狀態應用

<pre>oc getclusterpairs</pre> 的輸出確認了配對已經成功。

驗證配對狀態

我們可以通過 storkctl CLI來驗證配對狀態。確保存儲的狀態,和調度器的狀態都是正常,沒有錯誤。

storkctl -n=cms get clusterpair

如何在兩個OpenShift集群間遷移有狀態應用

我們驗證了,源集群和目標集群已經配對成功。

現在我們開始遷移。

從源集群向目標集群遷移CMS應用

在研發測試環境下,通過下面的步驟開始CMS應用的遷移。

開始遷移

用下面的內容創建一個名為migration.yaml的YAML文件。

apiVersion: stork.libopenstorage.org/v1alpha1
kind: Migrationmetadata:
  name: cmsmigration  namespace: cms
spec:
  # This should be the name of the cluster pair created above
  clusterPair: prodcluster  # If set to false this will migrate only the Portworx volumes. No PVCs, apps, etc will be migrated
  includeResources: true
  # If set to false, the deployments and stateful set replicas will be set to 0 on the destination.
  # There will be an annotation with "stork.openstorage.org/migrationReplicas" on the destinationto store the replica count from the source.
  startApplications: true
  # List of namespaces to migrate
  namespaces:
  - cms

這里包括一些很重要的信息,例如集群配對的名稱、遷移中包括的命名空間,需要被遷移的資源類型。

把YAML文件提交到研發測試集群,來開始遷移。

oc apply -f migration.yaml
migration.stork.libopenstorage.org/cmsmigration created

監控遷移的過程

使用storkctl我們來監控遷移的過程。

storkctl get migration -n cms

如何在兩個OpenShift集群間遷移有狀態應用

一旦遷移完成, storkctl 會報告最后遷移到目標集群的卷的數量以及資源。

如何在兩個OpenShift集群間遷移有狀態應用

通過下面的命令,可以得到遷移過程的詳細信息。

oc describe migration cmsmigration -n=cms% oc describe migration cmsmigration -n=cmsName:         cmsmigrationNamespace:    cmsLabels:Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"stork.libopenstorage.org/v1alpha1","kind":"Migration","metadata":{"annotations":{},"name":"cmsmigration","namespace":"cms"}...API Version:  stork.libopenstorage.org/v1alpha1Kind:         MigrationMetadata:
  Creation Timestamp:  2019-11-08T02:33:44Z
  Generation:          9
  Resource Version:    346702
  Self Link:           /apis/stork.libopenstorage.org/v1alpha1/namespaces/cms/migrations/cmsmigration
  UID:                 2eeb5d56-01d0-11ea-a393-02fec625b80aSpec:
  Admin Cluster Pair:
  Cluster Pair:        prodcluster  Include Resources:   true
  Include Volumes:     true
  Namespaces:
    cms  Post Exec Rule:
  Pre Exec Rule:
  Selectors:
  Start Applications:  trueStatus:
  Finish Timestamp:  2019-11-08T02:34:56Z
  Resources:
    Group:      core    Kind:       PersistentVolume
    Name:       pvc-ac60362f-0170-11ea-8418-06c5879a6a7a
    Namespace:
    Reason:     Resource migrated successfully    Status:     Successful
    Version:    v1    Group:      core    Kind:       PersistentVolume
    Name:       pvc-c5dd1955-0170-11ea-a393-02fec625b80a
    Namespace:
    Reason:     Resource migrated successfully    Status:     Successful
    Version:    v1    Group:      core    Kind:       Service
    Name:       mysql    Namespace:  cms    Reason:     Resource migrated successfully    Status:     Successful
    Version:    v1    Group:      core    Kind:       Service
    Name:       wordpress    Namespace:  cms    Reason:     Resource migrated successfully    Status:     Successful
    Version:    v1    Group:      core    Kind:       PersistentVolumeClaim
    Name:       px-mysql-pvc    Namespace:  cms    Reason:     Resource migrated successfully    Status:     Successful
    Version:    v1    Group:      core    Kind:       PersistentVolumeClaim
    Name:       px-wp-pvc    Namespace:  cms    Reason:     Resource migrated successfully    Status:     Successful
    Version:    v1    Group:      apps    Kind:       Deployment
    Name:       mysql    Namespace:  cms    Reason:     Resource migrated successfully    Status:     Successful
    Version:    v1    Group:      apps    Kind:       Deployment
    Name:       wordpress    Namespace:  cms    Reason:     Resource migrated successfully    Status:     Successful
    Version:    v1    Group:      route.openshift.io    Kind:       Route
    Name:       wp    Namespace:  cms    Reason:     Resource migrated successfully    Status:     Successful
    Version:    v1  Stage:        Final
  Status:       Successful
  Volumes:
    Namespace:                cms    Persistent Volume Claim:  px-mysql-pvc    Reason:                   Migration successful for volume    Status:                   Successful
    Volume:                   pvc-ac60362f-0170-11ea-8418-06c5879a6a7a
    Namespace:                cms    Persistent Volume Claim:  px-wp-pvc    Reason:                   Migration successful for volume    Status:                   Successful
    Volume:                   pvc-c5dd1955-0170-11ea-a393-02fec625b80aEvents:
  Type    Reason      Age                From   Message
  ----    ------      ----               ----   -------
  Normal  Successful  82s                stork  Volume pvc-ac60362f-0170-11ea-8418-06c5879a6a7a migrated successfully  Normal  Successful  82s                stork  Volume pvc-c5dd1955-0170-11ea-a393-02fec625b80a migrated successfully  Normal  Successful  78s                stork  /v1, Kind=PersistentVolume /pvc-ac60362f-0170-11ea-8418-06c5879a6a7a: Resource migrated successfully  Normal  Successful  78s                stork  /v1, Kind=PersistentVolume /pvc-c5dd1955-0170-11ea-a393-02fec625b80a: Resource migrated successfully  Normal  Successful  78s                stork  /v1, Kind=Service cms/mysql: Resource migrated successfully  Normal  Successful  78s                stork  /v1, Kind=Service cms/wordpress: Resource migrated successfully  Normal  Successful  78s                stork  /v1, Kind=PersistentVolumeClaim cms/px-mysql-pvc: Resource migrated successfully  Normal  Successful  78s                stork  /v1, Kind=PersistentVolumeClaim cms/px-wp-pvc: Resource migrated successfully  Normal  Successful  78s                stork  apps/v1, Kind=Deployment cms/mysql: Resource migrated successfully  Normal  Successful  77s (x2 over 78s)  stork  (combined from similar events): route.openshift.io/v1, Kind=Route cms/wp: Resource migrated successfully

在生產環境上驗證遷移

回到生產環境,我們來檢查CMS命名空間里的所有資源。

oc get all -n cms

如何在兩個OpenShift集群間遷移有狀態應用

你可以通過為WordPress Pod使用port-forwardding,來訪問應用。

如何在兩個OpenShift集群間遷移有狀態應用

小結

Kubemotion為有狀態應用增加了遷移功能。它可以在本地環境和云環境之間,以及多云環境之間,無縫的遷移卷。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女