User Tools

Site Tools


сервис_postgresql

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
сервис_postgresql [2025/10/05 18:33]
val [Kubernetes]
сервис_postgresql [2026/06/11 11:11] (current)
val [Kubernetes]
Line 19: Line 19:
 ==== Kubernetes ==== ==== Kubernetes ====
  
-  * Как не надо делать:​ [[https://​www.digitalocean.com/​community/​tutorials/​how-to-deploy-postgres-to-kubernetes-cluster]]+  * Как не надо делать (уже исправили,​ но, комментарии остались:[[https://​www.digitalocean.com/​community/​tutorials/​how-to-deploy-postgres-to-kubernetes-cluster]]
  
 === Helm === === Helm ===
Line 28: Line 28:
   * Dynamic Volume Provisioning [[Система Kubernetes#​longhorn]]   * Dynamic Volume Provisioning [[Система Kubernetes#​longhorn]]
  
 +  * !!! Поменять repository и allowInsecureImages по аналогии Keycloak в [[Сервис Keycloak#​Kubernetes]]
 <​code>​ <​code>​
 kube1:​~/​my-postgres#​ helm show values oci://​registry-1.docker.io/​bitnamicharts/​postgresql --version 16.6.2 | tee values.yaml.orig kube1:​~/​my-postgres#​ helm show values oci://​registry-1.docker.io/​bitnamicharts/​postgresql --version 16.6.2 | tee values.yaml.orig
Line 56: Line 57:
   * [[https://​habr.com/​ru/​companies/​oleg-bunin/​articles/​766898/​|Операторы в Kubernetes]] и [[https://​habr.com/​ru/​companies/​flant/​articles/​684202/​|Обзор операторов PostgreSQL для Kubernetes. Часть 3: CloudNativePG]]   * [[https://​habr.com/​ru/​companies/​oleg-bunin/​articles/​766898/​|Операторы в Kubernetes]] и [[https://​habr.com/​ru/​companies/​flant/​articles/​684202/​|Обзор операторов PostgreSQL для Kubernetes. Часть 3: CloudNativePG]]
  
-  * [[Система Kubernetes#​rancher local-path-provisioner]]+  * Dynamic Volume Provisioning ​[[Система Kubernetes#​rancher local-path-provisioner]]
  
 <​code>​ <​code>​
Line 62: Line 63:
  
 kube1:~# kubectl -n cnpg-system get all kube1:~# kubectl -n cnpg-system get all
 +
 +kube1:~# mkdir my-pgcluster;​ cd $_
  
 kube1:​~/​my-pgcluster#​ echo -n keycloak | base64 kube1:​~/​my-pgcluster#​ echo -n keycloak | base64
Line 92: Line 95:
   storage:   storage:
     size: 10Gi     size: 10Gi
 +#    storageClass:​ local-path
 </​code><​code>​ </​code><​code>​
 kube1:​~/​my-pgcluster#​ kubectl create ns my-pgcluster-ns kube1:​~/​my-pgcluster#​ kubectl create ns my-pgcluster-ns
 +</​code>​ 
 +  * [[Система Kubernetes#​Kustomize]] 
 +<​code>​
 kube1:​~/​my-pgcluster#​ kubectl -n my-pgcluster-ns apply -f keycloak-db-secret.yaml,​my-pgcluster.yaml kube1:​~/​my-pgcluster#​ kubectl -n my-pgcluster-ns apply -f keycloak-db-secret.yaml,​my-pgcluster.yaml
- +</​code>​ 
-kube1# ​watch kubectl -n my-pgcluster-ns get all +== Проверка состояния кластера cnpg == 
- +<​code>​ 
-kube1# ###kubectl -n my-pgcluster-ns exec -it pod/​my-pgcluster-1 -- psql+kube1:​~/​my-pgcluster# kubectl -n my-pgcluster-ns get cluster 
 +NAME AGE INSTANCES READY STATUS PRIMARY 
 +... 
 +</​code>​ 
 +== Подключение к кластеру cnpg == 
 +<​code>​ 
 +kube1# kubectl -n my-pgcluster-ns exec -it pod/​my-pgcluster-1 -- psql
  
 kube1# ###psql postgres://​keycloak:​strongpassword@my-pgcluster-rw.my-pgcluster-ns:​5432/​keycloak kube1# ###psql postgres://​keycloak:​strongpassword@my-pgcluster-rw.my-pgcluster-ns:​5432/​keycloak
Line 112: Line 124:
  
 kube1:~# kubectl cnpg status my-pgcluster -n my-pgcluster-ns kube1:~# kubectl cnpg status my-pgcluster -n my-pgcluster-ns
 +
 +kube1:~# kubectl cnpg promote -n my-pgcluster-ns my-pgcluster my-pgcluster-1
  
 kube1:~# kubectl cnpg logs cluster my-pgcluster -n my-pgcluster-ns kube1:~# kubectl cnpg logs cluster my-pgcluster -n my-pgcluster-ns
 +</​code>​
 +== Миграция с вышедшего из строя узла ==
 +<​code>​
 +kube2:~# kubectl -n my-pgcluster-ns get pods
 +...
 +my-pgcluster-3 ​  ​0/​1 ​    ​Pending ​  ​0 ​         80m
 +
 +kube2# kubectl -n my-pgcluster-ns delete pvc my-pgcluster-3
 +
 +kube2# kubectl -n my-pgcluster-ns delete pods/​my-pgcluster-3
 </​code>​ </​code>​
 ===== Клиент psql ===== ===== Клиент psql =====
Line 124: Line 148:
  
 # sudo -u postgres psql # sudo -u postgres psql
 +
 +postgres=# SELECT version();
  
 postgres=# ALTER USER postgres WITH PASSWORD '​strongpassword';​ postgres=# ALTER USER postgres WITH PASSWORD '​strongpassword';​
Line 130: Line 156:
  
 postgres=# \l postgres=# \l
 +postgres=>​ SELECT datname FROM pg_database;​
  
 postgres=# CREATE USER keycloak WITH PASSWORD '​strongpassword';​ postgres=# CREATE USER keycloak WITH PASSWORD '​strongpassword';​
Line 185: Line 212:
 server# systemctl restart postgresql server# systemctl restart postgresql
  
-client$ psql postgres://​postgres:​strongpassword@IP_OR_DNS_NAME:​5432/​postgres #-c "​\dt"​+client$ psql postgres://​postgres:​strongpassword@IP_OR_DNS_NAME:​5432/​postgres 
 + 
 +root@my-debian:​~psql postgres://​keycloak:​strongpassword@my-pgcluster-rw.my-pgcluster-ns:​5432/​keycloak ​-c "​\dt"​ 
 + 
 +kube1:~# host my-pgcluster-rw.my-pgcluster-ns.svc.cluster.local 169.254.25.10 
 + 
 +kube1:~# telnet 10.233.N.M 5432
 </​code>​ </​code>​
  
сервис_postgresql.1759678390.txt.gz · Last modified: 2025/10/05 18:33 by val