[英]Kubernetes pod fail to connect to timescaledb in first few tries
[英]kubernetes timescaledb statefulset: Changes lost on pod recreation
我有一個Timescaledb服務器,在AKS中作為StatefulSet運行。 當我刪除並重新創建timescaledb pod時,它會出現,即使該pod與最初關聯的PV(永久卷)相關聯,更改也會丟失。 任何幫助表示贊賞。
下面是通過運行kubectl get statefulset timescaledb -o yaml
提取的statefulset的PV,PVC配置kubectl get statefulset timescaledb -o yaml
template:
metadata:
creationTimestamp: null
labels:
app: timescaledb
spec:
containers:
- args:
- -c
- config_file=/etc/postgresql/postgresql.conf
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
key: password
name: timescaledb-secret
image: docker.io/timescale/timescaledb:latest-pg9.6
name: timescaledb-backend
ports:
- containerPort: 5432
name: server
protocol: TCP
resources:
requests:
cpu: "3"
memory: 6Gi
volumeMounts:
- mountPath: /var/lib/postgresql
name: timescaledbdata
- mountPath: /etc/postgresql
name: timescaledb-config
volumes:
- configMap:
defaultMode: 420
name: timescaledb-config
name: timescaledb-config
volumeClaimTemplates:
- metadata:
annotations:
volume.alpha.kubernetes.io/storage-class: standard
creationTimestamp: null
name: timescaledbdata
spec:
accessModes:
- ReadWriteOnce
dataSource: null
resources:
requests:
storage: 200Gi
status:
phase: Pending
下面演示了在吊艙重新創建后丟失的創建的臨時數據庫test_db,並且在整個過程中,吊艙與Azure上的同一PV /磁盤相關聯。
root@e70a91715239:~/keys# k get pvc -l app=timescaledb
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
timescaledbdata-timescaledb-0 Bound pvc-c7eb99cf-6a6b-11e9-b661-be660567cc75 200Gi RWO default 83d
root@e70a91715239:~/keys# k exec -ti timescaledb-0 bash
bash-4.4# psql -U postgres;
psql (9.6.13)
Type "help" for help.
postgres=# create database test_db;
CREATE DATABASE
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
test_db | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
(4 rows)
root@e70a91715239:~/keys# k get pods | grep timescale
timescaledb-0 1/1 Running 0 12m
root@e70a91715239:~/keys# k delete pod/timescaledb-0
pod "timescaledb-0" deleted
root@e70a91715239:~/keys# k get pods | grep timescale
timescaledb-0 1/1 Running 0 14s
root@e70a91715239:~/keys# k exec -ti timescaledb-0 bash
bash-4.4# psql -U postgres
psql (9.6.13)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+------------+------------+-----------------------
postgres | postgres | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.utf8 | en_US.utf8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
root@e70a91715239:~/keys# k get pvc -l app=timescaledb
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
timescaledbdata-timescaledb-0 Bound pvc-c7eb99cf-6a6b-11e9-b661-be660567cc75 200Gi RWO default 83d
可能正在按提示進行重新初始化。 請參閱日志 。 關於為什么這樣做的任何指示。
更新1:我看了timescale
盒中的掛載,它似乎對/var/lib/postgresql
和/var/lib/postgresql/data
具有不同的分區。 我不理解為什么。
Filesystem Size Used Available Use% Mounted on
overlay 96.9G 22.1G 74.8G 23% /
tmpfs 64.0M 0 64.0M 0% /dev
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 96.9G 22.1G 74.8G 23% /docker-entrypoint-initdb.d
/dev/sda1 96.9G 22.1G 74.8G 23% /dev/termination-log
shm 64.0M 4.0K 64.0M 0% /dev/shm
/dev/sda1 96.9G 22.1G 74.8G 23% /etc/resolv.conf
/dev/sda1 96.9G 22.1G 74.8G 23% /etc/hostname
/dev/sda1 96.9G 22.1G 74.8G 23% /etc/hosts
/dev/sdc 196.7G 59.3M 196.7G 0% /var/lib/postgresql
/dev/sda1 96.9G 22.1G 74.8G 23% /var/lib/postgresql/data
不了解下面的配置如何發生上述安裝
volumeMounts:
- mountPath: /var/lib/postgresql
name: timescaledbdata
- mountPath: /etc/postgresql
name: timescaledb-config
問題是在postgres:9.6
Dockerfile中有/var/lib/postgresql/data
的VOLUME聲明,這引起了容器上的附加安裝。 當在/var/lib/postgresql
進行卷掛載時,該掛載是臨時的。 但是我們無法將AKS卷掛載到/var/lib/postgresql/data
因為該卷帶有lost+found
子目錄,而Postgres希望使用空目錄來存儲DB文件。
解決方法是在/var/lib/postgresql/data
上安裝卷,並告訴Postgres使用/var/lib/postgresql/data
下的子目錄來存儲帶有PGDATA
env var的文件。
以下是k8s statefulset配置中修復的相關部分
env:
- name: PGDATA
value: "/var/lib/postgresql/data/dbfiles"
...
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: timescaledata
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.