Veleroのバックアップと復元テストの例
    • PDF

    Veleroのバックアップと復元テストの例

    • PDF

    Article Summary

    VPC環境で利用できます。

    Veleroプラグインで説明した内容に基づき、バックアップと復元機能が正常に作動するかテストする例です。

    nginx配布の例

    バックアップと復元テストの例を行えるように、先にnginxを配布します。

    以下は、nginxを配布する例です。

    1. 以下のコードをコピーしてnginx-example.yamlファイルで保存します。
      # nginx-example.yaml
      ---
      apiVersion: v1
      kind: Namespace
      metadata:
        name: nginx-example
        labels:
          app: nginx
      ---
      
      kind: PersistentVolumeClaim
      apiVersion: v1
      metadata:
        name: nginx-log-pvc
        namespace: nginx-example
        labels:
          app: nginx
      spec:
        storageClassName: nks-block-storage
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 10Gi
      
      ---
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: nginx-deploy
        namespace: nginx-example
        labels:
          app: nginx
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: nginx
        template:
          metadata:
            labels:
              app: nginx
          spec:
            volumes:
              - name: nginx-logs
                persistentVolumeClaim:
                 claimName: nginx-log-pvc
            containers:
            - image: nks.kr.ncr.ntruss.com/nginx:1.9
              name: nginx
              ports:
              - containerPort: 80
              volumeMounts:
              - mountPath: "/var/log/nginx"
                name: nginx-logs
                readOnly: false
      
    2. 以下のコマンドを実行してクラスタにnginxを配布します。
      $ kubectl --kubeconfig $KUBE_CONFIG apply -f nginx-example.yaml
      
    3. nginxにアクセスできるように、以下のコマンドを順に実行してPodを確認した後、ポートフォワードを行います。
      $ kubectl --kubeconfig $KUBE_CONFIG get pods --namespace nginx-example
      
      $ kubectl --kubeconfig $KUBE_CONFIG --namespace nginx-example port-forward pod/nginx-deploy-749cb5ff64-x8j4w 9191:80
      
    4. フォワードされたポートをブラウザに入力するか、curlコマンドを使用してnginxにアクセスした後、画面が正常に表示されるか確認します。

    Veleroを用いたバックアップの例

    以下は、Veleroを用いてバックアップを行う例です。

    1. 以下のコマンドを順に実行してNGINXコンテナでログを確認し、コンテナから出ます。
      $ kubectl --kubeconfig $KUBE_CONFIG exec -it nginx-deploy-749cb5ff64-x8j4w --namespace nginx-example -- /bin/bash
      
      nginx-deploy-749cb5ff64-x8j4w:/# cat /var/log/nginx/access.log
      
      $ exit
      
    2. 以下のコマンドを実行して現在のクラスタ状態のバックアップを作成します。
      $ velero --kubeconfig $KUBE_CONFIG backup create nginx-backup --selector app=nginx
      
      • nginxのKubernetesオブジェクトをObject Storageに保存し、nginxを配布する際に作成したPersistentVolumeのスナップショットを作成します。
      • --selector app=nginxオプションは、VeleroサーバがLabel Selectorを通じてapp=nginxというLabelが設定されているKubernetesオブジェクトのみバックアップするように指定します。

    Veleroを用いた復元の例

    以下は、Veleroでバックアップしたデータを使用して復元を行う例です。

    1. 以下のコマンドを順に実行してnginx-example名前空間を削除し、正常に削除されたか確認します。
      $ kubectl --kubeconfig $KUBE_CONFIG delete namespace nginx-example
      
      $ kubectl --kubeconfig $KUBE_CONFIG get deployments --namespace=nginx-example
      
    2. 以下のコマンドを実行して復元を行います。
    velero --kubeconfig $KUBE_CONFIG restore create --from-backup nginx-backup
    
    1. 以下のコマンドをそれぞれ実行して復元が正常に行われたか確認します。
      • 復元されたDeployementの状態を確認
      $ kubectl --kubeconfig $KUBE_CONFIG get deployments --namespace=nginx-example
      
      • PersistentVolumeが作成されたか確認
      $ kubectl --kubeconfig $KUBE_CONFIG get pvc --namespace=nginx-example
      
      • 以下のコマンドを順に実行して復元前と同じログが表示されるのか確認
      $ kubectl --kubeconfig $KUBE_CONFIG get pods --namespace nginx-example
      
      $ kubectl --kubeconfig $KUBE_CONFIG exec -it nginx-deploy-749cb5ff64-x8j4w --namespace nginx-example -- /bin/bash
      
      $ nginx-deploy-749cb5ff64-x8j4w:/# cat /var/log/nginx/access.log
      

    この記事は役に立ちましたか?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.