摘要:摘要通過(guò)阿里云容器服務(wù)開(kāi)啟你的數(shù)據(jù)服務(wù)之旅一云上運(yùn)維自建數(shù)據(jù)庫(kù)之痛,使用容器服務(wù)自動(dòng)恢復(fù)數(shù)據(jù)庫(kù)實(shí)例概述本文為大家介紹一種容器化的數(shù)據(jù)服務(wù),通過(guò)使用云盤(pán)自動(dòng)掛載實(shí)現(xiàn)的塊存儲(chǔ)來(lái)做到數(shù)據(jù)庫(kù)的免運(yùn)維恢復(fù)。
摘要: 通過(guò)阿里云Kubernetes容器服務(wù),開(kāi)啟你的數(shù)據(jù)服務(wù)之旅 (一)云上運(yùn)維自建數(shù)據(jù)庫(kù)之痛,使用容器服務(wù)自動(dòng)恢復(fù)數(shù)據(jù)庫(kù)postgresql實(shí)例 概述 本文為大家介紹一種容器化的數(shù)據(jù)服務(wù) posgresql db on ACK,通過(guò)使用云盤(pán)自動(dòng)掛載實(shí)現(xiàn)的塊存儲(chǔ)PVC來(lái)做到數(shù)據(jù)庫(kù)的免運(yùn)維恢復(fù)。
容器開(kāi)啟數(shù)據(jù)服務(wù)之旅系列(一):Kubernetes如何解自建PostgreSQL運(yùn)維之痛
概述
本文為大家介紹一種容器化的數(shù)據(jù)服務(wù) posgresql db on ACK,通過(guò)使用云盤(pán)自動(dòng)掛載實(shí)現(xiàn)的塊存儲(chǔ)PVC來(lái)做到數(shù)據(jù)庫(kù)的免運(yùn)維恢復(fù)。借助阿里云Kubernetes服務(wù)與阿里云存儲(chǔ)資源的深度整合,打造數(shù)據(jù)庫(kù)實(shí)例的免運(yùn)維異地(ECS)恢復(fù)的不死神話。
先決條件
1. 你已經(jīng)通過(guò)阿里云容器服務(wù)創(chuàng)建了一個(gè)Kubernetes集群,詳細(xì)步驟參見(jiàn)創(chuàng)建Kubernetes集群
2. 阿里云容器服務(wù)的存儲(chǔ)插件(默認(rèn)情況存儲(chǔ)插件已經(jīng)自動(dòng)部署在阿里云Kubernetes容器服務(wù))
從容器服務(wù)控制臺(tái)創(chuàng)建一個(gè)posgresql實(shí)例
使用三次點(diǎn)擊來(lái)創(chuàng)建一個(gè)postgresql的不死實(shí)例
1. 登錄 https://cs.console.aliyun.com/
2. 點(diǎn)擊 “應(yīng)用目錄”
3. 選擇 "postgresql"
?
4.(可選)選擇你的Kubernetes集群. e.g. k8s-gpu
5.(可選)選擇你的應(yīng)用的命名空間。默認(rèn): default
6. 給你的數(shù)據(jù)庫(kù)應(yīng)用取個(gè)容易記住的名字。 e.g. postgresql-online
?
7.(可選) 點(diǎn)擊 “參數(shù)” 來(lái)定制你的數(shù)據(jù)庫(kù)實(shí)例
1.修改 persistence.size: 20Gi 增加數(shù)據(jù)庫(kù)云盤(pán)的容量
2.修改 persistence.storageClass: alicloud-disk-efficiency 調(diào)整數(shù)據(jù)卷所在云盤(pán)的性能。比如改為alicloud-disk-ssd 掛載ssd類型的
?
## Persist data to a persitent volume persistence: enabled: true ## A manually managed Persistent Volume and Claim ## Requires persistence.enabled: true ## If defined, PVC must be created manually before volume will be bound # existingClaim: ## database data Persistent Volume Storage Class ## if defined, user has to define storageClassName: alicloud-disk to support dynamic provision of alicloud-disk ## If defined, storageClassName:## If set to "-", storageClassName: "", which disables dynamic provisioning ## If undefined (the default) or set to null, no storageClassName spec is ## set, choosing the default provisioner. (gp2 on AWS, standard on ## GKE, AWS & OpenStack) ## #storageClass: "alicloud-disk-ssd" storageClass: "alicloud-disk-efficiency" accessMode: ReadWriteOnce size: 20Gi subPath: "postgresql-db"
8 點(diǎn)擊 “部署”, 完成數(shù)據(jù)發(fā)布
9 點(diǎn)擊 “Kubernetes 控制臺(tái)”,查看部署實(shí)例
?
10 點(diǎn)擊容器組,點(diǎn)擊 postgresql-online-postgresql 查看數(shù)據(jù)庫(kù)實(shí)例密碼。容器實(shí)例啟動(dòng)在節(jié)點(diǎn):cn-hangzhou.i-bp1fazljd8u2ylk2otdo
?
?
11 測(cè)試postgresql數(shù)據(jù)庫(kù)的異地(ECS)恢復(fù)
1.添加測(cè)試數(shù)據(jù)
ssh` # kubectl run my-pg-postgresql-client --rm --tty -i --image postgres --env "PGPASSWORD=$PGPASSWORD" --command -- psql -U postgres -h postgresql-online-postgresql postgres If you don"t see a command prompt, try pressing enter. postgres=# create table t1 (id int); CREATE TABLE postgres=# insert into t1 values(10); INSERT 0 1 postgres=# select * from t1; id ---- 10 (1 row)
驅(qū)逐數(shù)據(jù)庫(kù)實(shí)例從ECS節(jié)點(diǎn) i-bp1fazljd8u2ylk2otdo 到 i-
bp1fazljd8u2ylk2otdp #kubectl get pod -o wide | grep postgresql-online-postgresql postgresql-online-postgresql-78884fbcf6-6mfzz 1/1 Running 0 36m 172.30.4.4 cn-hangzhou.i-bp1fazljd8u2ylk2otdo #kubectl cordon cn-hangzhou.i-bp1fazljd8u2ylk2otdo #kubectl delete pod postgresql-online-postgresql-78884fbcf6-6mfzz pod "postgresql-online-postgresql-78884fbcf6-6mfzz" deleted # kubectl get pod -o wide|grep postgresql-online-postgresql #postgresql-online-postgresql-78884fbcf6-87ttg 0/1 Running 0 15s 172.30.3.5 cn-hangzhou.i-bp1fazljd8u2ylk2otdp
檢驗(yàn)數(shù)據(jù),實(shí)例遷移, 數(shù)據(jù)庫(kù)實(shí)例自動(dòng)化恢復(fù), 數(shù)據(jù)不丟失。
# kubectl get pod -o wide|grep postgresql-online-postgresql #postgresql-online-postgresql-78884fbcf6-87ttg 0/1 Running 0 15s 172.30.3.5 cn-hangzhou.i-bp1fazljd8u2ylk2otdp kubectl run my-pg-postgresql-client --rm --tty -i --image postgres > --env "PGPASSWORD=$PGPASSWORD" > --command -- psql -U postgres > -h postgresql-online-postgresql postgres If you don"t see a command prompt, try pressing enter. postgres=# select * from t1; id ---- 10 (1 row)
CLI控: 使用命令行完成postgresql實(shí)例的創(chuàng)建,遷移驗(yàn)證
login k8s master and deploy an postgresql db in seconds.
sshhelm install -n postgresql-online --set "persistence.size=30Gi,persistence.storageClass=alicloud-disk-ssd" stable/postgresql
To get your user password run:
PGPASSWORD=$(kubectl get secret --namespace default my-pg-postgresql -o jsonpath="{.data.postgres-password}" | base64 --decode; echo)
To connect to your database run the following command (using the env variable from above):
kubectl run my-pg-postgresql-client --rm --tty -i --image postgres --env "PGPASSWORD=$PGPASSWORD" --command -- psql -U postgres -h postgresql-online-postgresql postgres
To connect to your database directly from outside the K8s cluster:
PGHOST=127.0.0.1 PGPORT=5432 # Execute the following commands to route the connection: export POD_NAME=$(kubectl get pods --namespace default -l "app=my-pg-postgresql" -o jsonpath="{.items[0].metadata.name}") kubectl port-forward $POD_NAME 5432:5432 #kubectl get pod -o wide | grep postgresql-online-postgresql postgresql-online-postgresql-78884fbcf6-6mfzz 1/1 Running 0 36m 172.30.4.4 cn-hangzhou.i-bp1fazljd8u2ylk2otdo #kubectl cordon cn-hangzhou.i-bp1fazljd8u2ylk2otdo #kubectl delete pod postgresql-online-postgresql-78884fbcf6-6mfzz pod "postgresql-online-postgresql-78884fbcf6-6mfzz" deleted # kubectl get pod -o wide|grep postgresql-online-postgresql #postgresql-online-postgresql-78884fbcf6-87ttg 0/1 Running 0 15s 172.30.3.5 cn-hangzhou.i-bp1fazljd8u2ylk2otdp
Test original postgresql db could be recovered on different node.
#kubectl get pod -o wide|grep postgresql-online-postgresql #postgresql-online-postgresql-78884fbcf6-87ttg 0/1 Running 0 15s 172.30.3.5 cn-hangzhou.i-bp1fazljd8u2ylk2otdp kubectl run my-pg-postgresql-client --rm --tty -i --image postgres > --env "PGPASSWORD=$PGPASSWORD" > --command -- psql -U postgres > -h postgresql-online-postgresql postgres If you don"t see a command prompt, try pressing enter. postgres=# select * from t1; id ---- 10 (1 row)
原文鏈接
閱讀更多干貨好文,請(qǐng)關(guān)注掃描以下二維碼:
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/17729.html
摘要:目前,高德主要有地圖導(dǎo)航兩個(gè)產(chǎn)品,以及地圖,同時(shí)還開(kāi)放了服務(wù),方便移動(dòng)開(kāi)發(fā)者更好地為用戶提供高質(zhì)量基于位置的服務(wù)。另外,高德經(jīng)常有大型活動(dòng),用戶訪問(wèn)量會(huì)在某個(gè)階段激增,這時(shí)就需基于阿里云的彈性伸縮服務(wù),就能實(shí)現(xiàn)快速擴(kuò)展的基礎(chǔ)設(shè)施。 摘要: 云計(jì)算帶來(lái)的變革不言而喻,作為一種新型的IT交付模式,切實(shí)為企業(yè)節(jié)省IT成本、加快IT與企業(yè)業(yè)務(wù)結(jié)合效率、提升創(chuàng)新能力、加強(qiáng)管理水平以及增強(qiáng)系統(tǒng)本身...
閱讀 2810·2021-11-22 15:22
閱讀 1726·2021-11-22 14:56
閱讀 3699·2021-09-22 15:12
閱讀 2473·2021-09-02 15:41
閱讀 2216·2021-08-27 16:26
閱讀 1184·2019-08-30 15:55
閱讀 2200·2019-08-29 17:30
閱讀 736·2019-08-29 16:26