forked from civo/kubernetes-marketplace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e1146c
commit bf3185d
Showing
4 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: postgres-config | ||
labels: | ||
app: postgres | ||
data: | ||
POSTGRES_DB: postgresdb | ||
POSTGRES_USER: $USERNAME | ||
POSTGRES_PASSWORD: $PASSWORD | ||
--- | ||
apiVersion: v1 | ||
kind: PersistentVolume | ||
metadata: | ||
name: postgresql-pv-volume | ||
labels: | ||
type: local | ||
spec: | ||
storageClassName: manual | ||
capacity: | ||
storage: $VOLUME_SIZE | ||
accessModes: | ||
- ReadWriteOnce | ||
hostPath: | ||
path: "/mnt/data" | ||
--- | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: postgresql-pv-claim | ||
spec: | ||
storageClassName: manual | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: $VOLUME_SIZE | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: postgresql | ||
spec: | ||
ports: | ||
- port: 5432 | ||
selector: | ||
app: postgresql | ||
clusterIP: None | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: postgresql | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: postgresql | ||
strategy: | ||
type: Recreate | ||
template: | ||
metadata: | ||
labels: | ||
app: postgresql | ||
spec: | ||
containers: | ||
- image: postgresql:11.5 | ||
name: postgresql | ||
envFrom: | ||
- configMapRef: | ||
name: postgres-config | ||
volumeMounts: | ||
- name: postgresql-persistent-storage | ||
mountPath: /var/lib/postgresql/data | ||
ports: | ||
- containerPort: 5432 | ||
name: postgresql | ||
volumes: | ||
- name: postgresql-persistent-storage | ||
persistentVolumeClaim: | ||
claimName: postgresql-pv-claim |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
name: PostgreSQL | ||
version: 11.5 | ||
maintainer: [email protected] | ||
description: The PostgreSQL object-relational database system provides reliability and data integrity. | ||
url: https://www.postgresql.org | ||
category: database | ||
dependencies: | ||
- Longhorn | ||
plans: | ||
- label: "5GB" | ||
configuration: | ||
VOLUME_SIZE: | ||
value: 5Gi | ||
- label: "10GB" | ||
configuration: | ||
VOLUME_SIZE: | ||
value: 10Gi | ||
- label: "20GB" | ||
configuration: | ||
VOLUME_SIZE: | ||
value: 20Gi | ||
configuration: | ||
USERNAME: | ||
label: "Admin username" | ||
value: "CIVO:ALPHANUMERIC(10)" | ||
PASSWORD: | ||
label: "Admin password" | ||
value: "CIVO:ALPHANUMERIC(30)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
## PostgreSQL - reliable SQL database | ||
|
||
### External access | ||
|
||
By default external access to the PostgreSQL port isn't available. This is easily changed by applying the following YAML to your cluster with `kubectl apply -f postgresql-service.yaml` (or whatever you call the file containing the contents below): | ||
|
||
``` | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: postgresql-service | ||
spec: | ||
type: LoadBalancer | ||
ports: | ||
- port: 5432 | ||
targetPort: 5432 | ||
protocol: TCP | ||
selector: | ||
app: postgresql | ||
``` | ||
|
||
This will open up http://YOUR_CLUSTER_ID.k8s.civo.com:5432 to the whole world. You should lock this down in the [firewall](https://www.civo.com/account/firewalls) automatically created in Civo for your Kubernetes cluster. Locking down the firewall will only affect access from OUTSIDE of your Kubernetes cluster, access from your applications within Kubernetes will not be affected. | ||
|
||
### Usage instruction | ||
|
||
You can use this application from within your cluster by just using the hostname `postgresql` and can create databases and users using the admin access credentials above this message. For example, to create an application's database and user credentials and given that the `kubectx` and [Civo CLI](https://github.com/civo/cli) are installed, with a Civo Kubernetes cluster called `my-cluster-name`: | ||
|
||
``` | ||
$ civo k3s config my-cluster-name --save | ||
$ kubectx my-cluster-name | ||
$ kubectl run tmp-shell --generator=run-pod/v1 --rm -i \ | ||
--tty --image alpine -- /bin/sh | ||
/ # apk update | ||
/ # apk add postgresql-client | ||
/ # psql postgresql://ADMIN_USERNAME:ADMIN_PASSWORD@postgresql | ||
psql=# CREATE DATABASE yourdbname; | ||
psql=# CREATE USER youruser WITH ENCRYPTED PASSWORD 'super-strong-password'; | ||
psql=# GRANT ALL PRIVILEGES ON DATABASE yourdbname TO youruser; | ||
``` |