Helm/PostgreSQL: Difference between revisions
Jump to navigation
Jump to search
(Created page with " helm repo add bitnami https://charts.bitnami.com/bitnami helm repo update && helm repo list ==Config== <syntaxhighlight lang="properties"> export KUBECONFIG="${HOME}/.kube/dev-kubeconfig.yaml" export KUBECONFIG="${HOME}/.kube/gcp-kubeconfig.yaml" export KUBECONFIG="${HOME}/.kube/config" </syntaxhighlight> ==Install== {| |valign="top"| <syntaxhighlight lang="bash"> helm show values bitnami/postgresql --version=15.5.20|less helm show values bitnami/postgresql --version...") |
|||
(27 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
helm repo add bitnami https://charts.bitnami.com/bitnami | helm repo add bitnami https://charts.bitnami.com/bitnami | ||
helm repo update && helm repo list | helm repo update && helm repo list | ||
kubectl config get-contexts | |||
==Config== | ==Config== | ||
Line 38: | Line 39: | ||
--- | --- | ||
global: | global: | ||
defaultStorageClass: standard | |||
postgresql: | postgresql: | ||
auth: | auth: | ||
Line 45: | Line 46: | ||
password: sadaqah! | password: sadaqah! | ||
database: academia | database: academia | ||
primary: | |||
initdb: | |||
scripts: | |||
init-chorke.sql: | | |||
-- create database | |||
CREATE DATABASE academia_flair_staging; | |||
CREATE DATABASE academia_audit_staging; | |||
CREATE DATABASE academia_quote_staging; | |||
CREATE DATABASE academia_users_staging; | |||
-- create user | |||
CREATE USER chorke WITH ENCRYPTED PASSWORD 'sadaqah!'; | |||
ALTER USER chorke WITH SUPERUSER; | |||
-- grant access | |||
GRANT ALL PRIVILEGES ON DATABASE academia_flair_staging TO chorke; | |||
GRANT ALL PRIVILEGES ON DATABASE academia_audit_staging TO chorke; | |||
GRANT ALL PRIVILEGES ON DATABASE academia_quote_staging TO chorke; | |||
GRANT ALL PRIVILEGES ON DATABASE academia_users_staging TO chorke; | |||
YML | YML | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 54: | Line 74: | ||
|valign='top'| | |valign='top'| | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
echo -n password: ; read -s PGPASSWORD; export PGPASSWORD; echo | |||
psql -h psql.k8s.local -p 5432 -U academia academia | psql -h psql.k8s.local -p 5432 -U academia academia | ||
psql -h psql.k8s.local -p 5432 -U postgres postgres | psql -h psql.k8s.local -p 5432 -U postgres postgres | ||
Line 60: | Line 81: | ||
|valign='top'| | |valign='top'| | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
echo -n password: ; read -s PGPASSWORD; export PGPASSWORD; echo | |||
psql 'postgres://academia:@psql.k8s.local:5432/academia' | psql 'postgres://academia:@psql.k8s.local:5432/academia' | ||
psql 'postgres://postgres:@psql.k8s.local:5432/postgres' | psql 'postgres://postgres:@psql.k8s.local:5432/postgres' | ||
Line 73: | Line 95: | ||
kubectl delete namespace postgresql | kubectl delete namespace postgresql | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Swiss Knife== | |||
<syntaxhighlight lang="bash"> | |||
kubectl -n postgresql run -i --tty --rm psql --image=alpine --restart=Never -- sh | |||
echo -n password: ; read -s PGPASSWORD; export PGPASSWORD; echo | |||
apk --update add --no-cache postgresql-client inetutils-telnet | |||
psql -d postgres -U postgres -h postgresql.postgresql.svc.cluster.local | |||
psql -d postgres -U postgres -h postgresql.postgresql.svc | |||
psql -d postgres -U postgres -h postgresql.postgresql | |||
psql -d postgres -U postgres -h postgresql | |||
</syntaxhighlight> | |||
==AWS » EKS== | |||
===AWS » EKS » EBS=== | |||
<syntaxhighlight lang="yaml"> | |||
cat << YML | kubectl apply -f - | |||
--- | |||
apiVersion: v1 | |||
kind: PersistentVolume | |||
metadata: | |||
name: postgresql-pv | |||
spec: | |||
accessModes: | |||
- ReadWriteOnce | |||
awsElasticBlockStore: | |||
fsType: ext4 | |||
volumeID: aws://ap-southeast-1/vol-0bbbd80804f1ae62a | |||
capacity: | |||
storage: 10Gi | |||
persistentVolumeReclaimPolicy: Retain | |||
storageClassName: "gp2" | |||
--- | |||
apiVersion: v1 | |||
kind: PersistentVolumeClaim | |||
metadata: | |||
labels: | |||
app.kubernetes.io/name: postgresql | |||
name: postgresql-pvc | |||
namespace: postgresql | |||
spec: | |||
accessModes: | |||
- ReadWriteOnce | |||
resources: | |||
requests: | |||
storage: 10Gi | |||
storageClassName: "gp2" | |||
volumeName: postgresql-pv | |||
YML | |||
</syntaxhighlight> | |||
===AWS » EKS » Patch=== | |||
{| | |||
|colspan="2"| | |||
<syntaxhighlight lang="yaml"> | |||
kubectl -n postgresql get sts/postgresql -ojson|jq -r '.spec.template.spec.nodeSelector' | |||
</syntaxhighlight> | |||
|- | |||
|colspan="2"| | |||
---- | |||
|- | |||
|valign="top"| | |||
<syntaxhighlight lang="yaml"> | |||
cat <<YML | kubectl -n postgresql patch sts/postgresql --patch-file=/dev/stdin | |||
--- | |||
spec: | |||
template: | |||
spec: | |||
nodeSelector: | |||
topology.kubernetes.io/zone: minikube | |||
YML | |||
</syntaxhighlight> | |||
|valign="top"| | |||
<syntaxhighlight lang="yaml"> | |||
cat <<YML | kubectl -n postgresql patch sts/postgresql --patch-file=/dev/stdin | |||
--- | |||
spec: | |||
template: | |||
spec: | |||
nodeSelector: | |||
topology.kubernetes.io/zone: ap-southeast-1a | |||
YML | |||
</syntaxhighlight> | |||
|- | |||
|colspan="2"| | |||
---- | |||
|- | |||
|colspan="2"| | |||
<syntaxhighlight lang="yaml"> | |||
kubectl -n postgresql get sts/postgresql -ojson|jq -r '.spec.template.spec.nodeSelector' | |||
kubectl -n postgresql delete pods --all | |||
</syntaxhighlight> | |||
|} | |||
==Playground== | ==Playground== | ||
Line 95: | Line 214: | ||
kubectl -n postgresql exec -it svc/postgresql -c postgresql -- bash | kubectl -n postgresql exec -it svc/postgresql -c postgresql -- bash | ||
kubectl -n postgresql exec -it svc/postgresql -- psql -Upostgres | kubectl -n postgresql exec -it svc/postgresql -- psql -Upostgres | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 154: | Line 259: | ||
| valign="top" | | | valign="top" | | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
kubectl -n postgresql exec -it postgresql-0 | kubectl -n postgresql exec -it postgresql-0 -- psql -Upostgres | ||
kubectl -n postgresql | kubectl -n postgresql logs -f svc/postgresql -c postgresql | ||
kubectl -n postgresql | kubectl -n postgresql logs -f svc/postgresql | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 171: | Line 276: | ||
* [[Helm/Cert Manager|Helm » Cert Manager]] | * [[Helm/Cert Manager|Helm » Cert Manager]] | ||
* [https://artifacthub.io/packages/helm/bitnami/postgresql Helm » PostgreSQL] | * [https://artifacthub.io/packages/helm/bitnami/postgresql Helm » PostgreSQL] | ||
* [[Helm/MariaDB|Helm » MariaDB]] | |||
* [[Helm/GitLab|Helm » GitLab]] | |||
* [[Helm]] | * [[Helm]] | ||
| valign="top" | | | valign="top" | | ||
* [[Helm/PgAdmin4|Helm » PgAdmin4]] | |||
| valign="top" | | | valign="top" | | ||
Line 185: | Line 293: | ||
* [https://github.com/bitnami/charts/tree/main/bitnami/postgresql PostgreSQL » Bitnami » Helm Charts] | * [https://github.com/bitnami/charts/tree/main/bitnami/postgresql PostgreSQL » Bitnami » Helm Charts] | ||
* [https://bitnami.com/stack/postgresql/helm PostgreSQL » Bitnami » Package] | * [https://bitnami.com/stack/postgresql/helm PostgreSQL » Bitnami » Package] | ||
* [[Dockerized PostgreSQL|PostgreSQL » Dockerized]] | |||
* [[PostgreSQL]] | * [[PostgreSQL]] | ||
Line 211: | Line 320: | ||
* [[K8s/CSI Hostpath Driver|K8s » CSI Hostpath Driver]] | * [[K8s/CSI Hostpath Driver|K8s » CSI Hostpath Driver]] | ||
* [[K8s/Ingress|K8s » Ingress]] | * [[K8s/Ingress|K8s » Ingress]] | ||
* [[K8s/Service|K8s » Service]] | |||
* [[K8s/Run|K8s » Run]] | |||
* [[MinIO]] | * [[MinIO]] | ||
* [[CIDR]] | * [[CIDR]] |
Revision as of 01:12, 17 November 2024
helm repo add bitnami https://charts.bitnami.com/bitnami helm repo update && helm repo list kubectl config get-contexts
Config
export KUBECONFIG="${HOME}/.kube/dev-kubeconfig.yaml"
export KUBECONFIG="${HOME}/.kube/gcp-kubeconfig.yaml"
export KUBECONFIG="${HOME}/.kube/config"
Install
helm show values bitnami/postgresql --version=15.5.20|less
helm show values bitnami/postgresql --version=15.5.21|less
|
kubectl get ns|grep postgresql
kubectl delete ns postgresql
|
kubectl get ns|grep postgresql
kubectl create ns postgresql
|
| ||
cat <<YML | helm -n postgresql install postgresql bitnami/postgresql --version=15.5.21 -f -
---
global:
defaultStorageClass: standard
postgresql:
auth:
postgresPassword: sadaqah!
username: academia
password: sadaqah!
database: academia
primary:
initdb:
scripts:
init-chorke.sql: |
-- create database
CREATE DATABASE academia_flair_staging;
CREATE DATABASE academia_audit_staging;
CREATE DATABASE academia_quote_staging;
CREATE DATABASE academia_users_staging;
-- create user
CREATE USER chorke WITH ENCRYPTED PASSWORD 'sadaqah!';
ALTER USER chorke WITH SUPERUSER;
-- grant access
GRANT ALL PRIVILEGES ON DATABASE academia_flair_staging TO chorke;
GRANT ALL PRIVILEGES ON DATABASE academia_audit_staging TO chorke;
GRANT ALL PRIVILEGES ON DATABASE academia_quote_staging TO chorke;
GRANT ALL PRIVILEGES ON DATABASE academia_users_staging TO chorke;
YML
| ||
| ||
echo -n password: ; read -s PGPASSWORD; export PGPASSWORD; echo
psql -h psql.k8s.local -p 5432 -U academia academia
psql -h psql.k8s.local -p 5432 -U postgres postgres
|
echo -n password: ; read -s PGPASSWORD; export PGPASSWORD; echo
psql 'postgres://academia:@psql.k8s.local:5432/academia'
psql 'postgres://postgres:@psql.k8s.local:5432/postgres'
|
Uninstall
helm uninstall -n postgresql postgresql
kubectl delete namespace postgresql
Swiss Knife
kubectl -n postgresql run -i --tty --rm psql --image=alpine --restart=Never -- sh
echo -n password: ; read -s PGPASSWORD; export PGPASSWORD; echo
apk --update add --no-cache postgresql-client inetutils-telnet
psql -d postgres -U postgres -h postgresql.postgresql.svc.cluster.local
psql -d postgres -U postgres -h postgresql.postgresql.svc
psql -d postgres -U postgres -h postgresql.postgresql
psql -d postgres -U postgres -h postgresql
AWS » EKS
AWS » EKS » EBS
cat << YML | kubectl apply -f -
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgresql-pv
spec:
accessModes:
- ReadWriteOnce
awsElasticBlockStore:
fsType: ext4
volumeID: aws://ap-southeast-1/vol-0bbbd80804f1ae62a
capacity:
storage: 10Gi
persistentVolumeReclaimPolicy: Retain
storageClassName: "gp2"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
app.kubernetes.io/name: postgresql
name: postgresql-pvc
namespace: postgresql
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: "gp2"
volumeName: postgresql-pv
YML
AWS » EKS » Patch
kubectl -n postgresql get sts/postgresql -ojson|jq -r '.spec.template.spec.nodeSelector'
| |
| |
cat <<YML | kubectl -n postgresql patch sts/postgresql --patch-file=/dev/stdin
---
spec:
template:
spec:
nodeSelector:
topology.kubernetes.io/zone: minikube
YML
|
cat <<YML | kubectl -n postgresql patch sts/postgresql --patch-file=/dev/stdin
---
spec:
template:
spec:
nodeSelector:
topology.kubernetes.io/zone: ap-southeast-1a
YML
|
| |
kubectl -n postgresql get sts/postgresql -ojson|jq -r '.spec.template.spec.nodeSelector'
kubectl -n postgresql delete pods --all
|
Playground
helm -n postgresql install postgresql bitnami/postgresql --version=15.5.20
helm -n postgresql upgrade -i postgresql bitnami/postgresql --version=15.5.21
helm show values bitnami/postgresql --version=15.5.21|less
| |
| |
kubectl -n postgresql get secret postgresql -o json|jq -r '.data."postgres-password"'|base64 -d;echo
kubectl -n postgresql get secret postgresql -o json|jq -r '.data.password'|base64 -d;echo
kubectl -n postgresql exec -it svc/postgresql -c postgresql -- psql -Upostgres
kubectl -n postgresql exec -it svc/postgresql -c postgresql -- bash
kubectl -n postgresql exec -it svc/postgresql -- psql -Upostgres
| |
| |
kubectl config --kubeconfig=${HOME}/.kube/aws-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/dev-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/gcp-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/config view --flatten
| |
| |
kubectl -n postgresql delete all --all
kubectl -n postgresql delete ing --all
kubectl -n postgresql delete sts --all
|
kubectl -n postgresql delete svc --all
kubectl -n postgresql delete pvc --all
kubectl -n postgresql delete pv --all
|
| |
kubectl -n postgresql rollout history sts postgresql
kubectl -n postgresql rollout restart sts postgresql
kubectl -n postgresql rollout status sts postgresql
|
kubectl -n postgresql exec -it postgresql-0 -- psql -Upostgres
kubectl -n postgresql logs -f svc/postgresql -c postgresql
kubectl -n postgresql logs -f svc/postgresql
|
References
| ||
| ||