--- title: "Veleroのバックアップと復元テストの例" slug: "k8s-k8sexamples-velero" updated: 2026-09-17T09:31:49Z published: 2026-09-17T09:31:49Z canonical: "guide.ncloud-docs.com/k8s-k8sexamples-velero" stale: true --- > ## Documentation Index > Fetch the complete documentation index at: https://guide.ncloud-docs.com/llms.txt > Use this file to discover all available pages before exploring further. # Veleroのバックアップと復元テストの例 VPC環境で利用できます。 [Veleroプラグイン](/docs/ja/k8s-k8suse-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. 以下のコマンドをそれぞれ実行して復元が正常に行われたか確認します。 ``` $ kubectl --kubeconfig $KUBE_CONFIG get deployments --namespace=nginx-example ``` ``` $ 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 ``` - 復元されたDeployementの状態を確認 - `PersistentVolume`が作成されたか確認 - 以下のコマンドを順に実行して復元前と同じログが表示されるのか確認