17.velero的使用.md 6.3 KB

1.安装minio

1.使用外部安装

首先拉取镜像

docker pull minio

使用命令安装minio,指定端口号

docker run -p 30900:9000 --name minio \
-d --restart=always \
-e "MINIO_ACCESS_KEY=admin" \
-e "MINIO_SECRET_KEY=admin123456" \
-v /home/data:/data \
-v /home/config:/root/.minio \
minio/minio server --console-address :30900 /data

2.使用内部安装

minio 官方推荐安装在k8s集群中,在上步解压的压缩包中里的examples/minio/00-minio-deployment.yaml包含了在k8s中安装minio的yaml文件,内容如下,可按照如下步骤修改minio的service类型为NodePort,进行安装:

---
apiVersion: v1
kind: Namespace
metadata:
  name: velero

---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: velero
  name: minio
  labels:
    component: minio
spec:
  strategy:
    type: Recreate
  selector:
    matchLabels:
      component: minio
  template:
    metadata:
      labels:
        component: minio
    spec:
      volumes:
      - name: storage
        emptyDir: {}
      - name: config
        emptyDir: {}
      containers:
      - name: minio
        image: minio/minio:latest
        imagePullPolicy: IfNotPresent
        args:
        - server
        - /storage
        - --config-dir=/config
        env:
        - name: MINIO_ACCESS_KEY
          value: "minio"
        - name: MINIO_SECRET_KEY
          value: "minio123"
        ports:
        - containerPort: 9000
        volumeMounts:
        - name: storage
          mountPath: "/storage"
        - name: config
          mountPath: "/config"
      volumes:
      - name: config
        hostPath:
         path: /minio/config
      - name: storage
        hostPath:
         path: /minio/storage
         
---
apiVersion: v1
kind: Service
metadata:
  namespace: velero
  name: minio
  labels:
    component: minio
spec:
  # ClusterIP is recommended for production environments.
  # Change to NodePort if needed per documentation,
  # but only if you run Minio in a test/trial environment, for example with Minikube.
  type: NodePort
  ports:
    - port: 9000
      targetPort: 9000
      protocol: TCP
      nodePort: 30900
  selector:
    component: minio

---
apiVersion: batch/v1
kind: Job
metadata:
  namespace: velero
  name: minio-setup
  labels:
    component: minio
spec:
  template:
    metadata:
      name: minio-setup
    spec:
      restartPolicy: OnFailure
      volumes:
      - name: config
        emptyDir: {}
      containers:
      - name: mc
        image: minio/mc:latest
        imagePullPolicy: IfNotPresent
        command:
        - /bin/sh
        - -c
        - "mc --config-dir=/config config host add velero http://minio:9000 minio minio123 && mc --config-dir=/config mb -p velero/velero"
        volumeMounts:
        - name: config
          mountPath: "/config"

将config和stroge文件挂载到/minio/stroge和/minio/config

2.安装velero

1.安装在集群外部需要额外创建服务

由于minio安装在集群外,pod无法访问外部服务,需要创建一个external类型的服务,用来访问外部minio,yaml内容如下:(注意端口号对应)

---
apiVersion: v1
kind: Namespace
metadata:
  name: velero
---
apiVersion: v1
kind: Service
metadata:
  name: minio
  namespace: velero
spec:
  ports:
    - port: 9000
---
kind: Endpoints
apiVersion: v1
metadata:
  name: minio
  namespace: velero
subsets:
  - addresses:
      - ip: (这个端口号为内部端口)通过kubectl get svc 查看
    ports:
      - port: 9000

执行命令

kubectl apply -f minio-service.yaml

2.安装集群内部直接运行

将velero放入 /usr/local/bin/目录下,创建 minio 的访问密钥文件 credentials-velero

cat <<'EOF' > credentials-velero
[default]
aws_access_key_id = minio
aws_secret_access_key = minio123
EOF

安装velero

velero install    \
--image velero/velero:v1.6.1  \
--plugins velero/velero-plugin-for-aws:v1.0.0  \
--provider aws   \
--bucket velero   \
--namespace velero  \
--secret-file ./credentials-velero  \
--velero-pod-cpu-request 200m   \
--velero-pod-mem-request 200Mi   \
--velero-pod-cpu-limit 1000m  \
--velero-pod-mem-limit 1000Mi   \
--use-volume-snapshots=false   \
--use-restic   \
--restic-pod-cpu-request 200m   \
--restic-pod-mem-request 200Mi   \
--restic-pod-cpu-limit 1000m  \
--restic-pod-mem-limit 1000Mi  \
--backup-location-config region=minio,s3ForcePathStyle="true",s3Url=http://内部端口:9000

如果您想从集群中完全卸载Velero,则以下命令将删除由velero install创建的所有资源:

kubectl delete namespace/velero clusterrolebinding/velero
kubectl delete crds -l component=velero

3.创建备份

1.备份指定 namespaces

velero backup create 备份名字 --include-namespaces 命名空间名字

2.备份全部 namespaces

velero backup create all

4.恢复备份

  • 恢复备份

    velero restore create --from-backup test-1
    
  • 查看恢复

    velero restore get
    
  • 查看恢复日志、描述

    velero restore logs name
    velero restore describe name
    
  • 查看恢复的 Pod

    kubectl get pod -n velero-test
    

5.定时备份

velero schedule create velero-test-daily --schedule="0 7 * * *" --include-namespaces 名字

schedule任务 注意:由于"月份中的日期"和"星期中的日期"这两个元素互斥的,如果设置其中一个,就必须要对另外的一个设置?

*  *  *  *  *  *
┬  ┬  ┬  ┬  ┬  ┬
│  │  │  │  │  |
│  │  │  │  │  └ day of week (0 - 7) (0 or 7 is Sun)
│  │  │  │  └───── month (1 - 12)
│  │  │  └────────── day of month (1 - 31)
│  │  └─────────────── hour (0 - 23)
│  └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

6.参考文档

使用 Velero 备份 Kubernetes 集群

Velero安装与使用手册

Kubernetes数据卷介绍及yaml示例

velero文档