Vultr
託管叢集3
個 worker
節點,kubectl get nodes
。k8s-paas-71a68ebbc45b Ready <none> 12d v1.23.14
k8s-paas-dbbd42d034e6 Ready <none> 12d v1.23.14
k8s-paas-f7788d4f4a38 Ready <none> 12d v1.23.14
全棧的 Kubernetes 容器雲 PaaS 解決方案。
Kubernetes 的雲原生分散式塊儲存。
非官方 k8s helm charts,大規模吞吐需建設微服務叢集
/中介軟體叢集
/邊緣儲存叢集
。
helm repo add sentry https://sentry-kubernetes.github.io/charts
kubectl create ns sentry
helm install sentry sentry/sentry -f values.yaml -n sentry
# helm install sentry sentry/sentry -n sentry
這裡我們建立 3 個 PostgreSQL 資料卷快照,分別對應 Sentry 後臺面板的不同狀態。
用於存取備份儲存的端點。支援 NFS 和 S3 協定的伺服器。
備份卷建立時間取決於你的卷大小和網路頻寬。
官方檔案:https://longhorn.io/docs/1.4.0/snapshots-and-backups/backup-and-restore/restore-statefulset/
Longhorn 支援恢復備份,此功能的一個用例是恢復用於 Kubernetes StatefulSet 的資料,這需要為備份的每個副本恢復一個卷。
要恢復,請按照以下說明進行操作。 下面的範例使用了一個 StatefulSet,其中一個卷附加到每個 Pod 和兩個副本。
Longhorn UI
頁面。在 Backup
索引標籤下,選擇 StatefulSet 卷的名稱。 單擊卷條目的下拉式選單並將其還原。將卷命名為稍後可以輕鬆參照的 Persistent Volumes
。StatefulSet
,這些副本的卷名為 pvc-01a
和 pvc-02b
,則恢復可能如下所示:Backup Name | Restored Volume |
---|---|
pvc-01a | statefulset-vol-0 |
pvc-02b | statefulset-vol-1 |
Persistent Volume
。將卷命名為以後可以輕鬆參照的 Persistent Volume Claims
。下面必須替換 storage
容量、numberOfReplicas
、storageClassName
和 volumeHandle
。在範例中,我們在 Longhorn
中參照 statefulset-vol-0
和 statefulset-vol-1
,並使用 longhorn
作為我們的 storageClassName
。apiVersion: v1
kind: PersistentVolume
metadata:
name: statefulset-vol-0
spec:
capacity:
storage: <size> # must match size of Longhorn volume
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
csi:
driver: driver.longhorn.io # driver must match this
fsType: ext4
volumeAttributes:
numberOfReplicas: <replicas> # must match Longhorn volume value
staleReplicaTimeout: '30' # in minutes
volumeHandle: statefulset-vol-0 # must match volume name from Longhorn
storageClassName: longhorn # must be same name that we will use later
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: statefulset-vol-1
spec:
capacity:
storage: <size> # must match size of Longhorn volume
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
csi:
driver: driver.longhorn.io # driver must match this
fsType: ext4
volumeAttributes:
numberOfReplicas: <replicas> # must match Longhorn volume value
staleReplicaTimeout: '30'
volumeHandle: statefulset-vol-1 # must match volume name from Longhorn
storageClassName: longhorn # must be same name that we will use later
StatefulSet
的 namespace
中,為每個 Persistent Volume
建立 PersistentVolume Claims
。Persistent Volume Claim
的名稱必須遵循以下命名方案:<name of Volume Claim Template>-<name of StatefulSet>-<index>
StatefulSet Pod 是零索引的。在這個例子中,Volume Claim Template
的名稱是 data
,StatefulSet
的名稱是 webapp
,並且有兩個副本,分別是索引 0
和 1
。
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-webapp-0
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi # must match size from earlier
storageClassName: longhorn # must match name from earlier
volumeName: statefulset-vol-0 # must reference Persistent Volume
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-webapp-1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi # must match size from earlier
storageClassName: longhorn # must match name from earlier
volumeName: statefulset-vol-1 # must reference Persistent Volume
apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
name: webapp # match this with the PersistentVolumeClaim naming scheme
spec:
selector:
matchLabels:
app: nginx # has to match .spec.template.metadata.labels
serviceName: "nginx"
replicas: 2 # by default is 1
template:
metadata:
labels:
app: nginx # has to match .spec.selector.matchLabels
spec:
terminationGracePeriodSeconds: 10
containers:
- name: nginx
image: k8s.gcr.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: data
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: data # match this with the PersistentVolumeClaim naming scheme
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: longhorn # must match name from earlier
resources:
requests:
storage: 2Gi # must match size from earlier
結果: 現在應該可以從 StatefulSet Pod 內部存取恢復的資料。
# 刪除 release
helm uninstall sentry -n sentry
# 刪除 namespace
kubectl delete ns sentry
kubectl get ns
,已無 sentry。
statefulset-vol-sentry-postgresql-0
2
,卷副本會被自動排程到不同節點,保證卷高可用。注意:這裡我們需要重新建立 namespace:sentry
kubectl create ns sentry
helm install sentry sentry/sentry -f values.yaml -n sentry
ok,成功恢復。