From fa8a8a5bd10647f34d1942f3f9bf7321cfd83165 Mon Sep 17 00:00:00 2001 From: timlackhan <727781157@qq.com> Date: Wed, 4 Sep 2019 17:25:37 +0800 Subject: [PATCH] =?UTF-8?q?Add=E2=80=9Cpostgres=20deploy=20with=20k8s?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- postgres/README.md | 37 +++++++++++++++++++ postgres/postgres-deployment-conf.yaml | 51 ++++++++++++++++++++++++++ postgres/postgres-deployment.yaml | 50 +++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 postgres/postgres-deployment-conf.yaml create mode 100644 postgres/postgres-deployment.yaml diff --git a/postgres/README.md b/postgres/README.md index 5aaf262..4819051 100644 --- a/postgres/README.md +++ b/postgres/README.md @@ -56,6 +56,43 @@ Docker Hub. ### Deploy with Kubernetes +This image can also be deployed on a Kubernetes cluster, such as [minikube](https://kubernetes.io/docs/setup/learning-environment/minikube/).The following example YAML files are provided in the repository as reference for Kubernetes deployment: + +- [`postgres-deployment.yaml`](https://github.com/clearlinux/dockerfiles/blob/master/postgres/postgres-deployment.yaml): example using default configuration with secret to create a basic postgres service. +- [`postgres-deployment-conf.yaml`](https://github.com/clearlinux/dockerfiles/blob/master/postgres/postgres-deployment-conf.yaml): example using your own custom configuration with secret to create postgres service. + + + +Steps to deploy Postgres on a Kubernetes cluster: + +1. Create secret for postgres service. + + ``` + kubectl create secret generic postgres-config \ + --from-literal=POSTGRES_DB= \ + --from-literal=POSTGRES_PASSWORD= \ + --from-literal=POSTGRES_USER= + ``` + +2. If you want to deploy `postgres-deployment.yaml` + + ``` + kubectl create -f postgres-deployment.yaml + ``` + + Or if you want to deploy `postgres-deployment-conf.yaml` + + ``` + kubectl create -f postgres-deployment-conf.yaml + ``` + +3. Install PostgreSQL bundle and connect to the service, where 30001 is the port number defined in your service. + + ``` + swupd bundle-add postgresql + psql -h -U --password -p30001 + ``` + ## Build and modify: diff --git a/postgres/postgres-deployment-conf.yaml b/postgres/postgres-deployment-conf.yaml new file mode 100644 index 0000000..fc37279 --- /dev/null +++ b/postgres/postgres-deployment-conf.yaml @@ -0,0 +1,51 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: postgres +spec: + replicas: 1 + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: docker.io/clearlinux/postgres + imagePullPolicy: "IfNotPresent" + ports: + - containerPort: 5432 + # customize your conf here + args: ["-c", "max_connections=666", "-c", "shared_buffers=1GB"] + env: + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: postgres-config + key: POSTGRES_DB + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: postgres-config + key: POSTGRES_PASSWORD + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: postgres-config + key: POSTGRES_USER + +--- +apiVersion: v1 +kind: Service +metadata: + name: postgres + labels: + app: postgres +spec: + type: NodePort + ports: + - port: 5432 + targetPort: 5432 + nodePort: 30001 + selector: + app: postgres \ No newline at end of file diff --git a/postgres/postgres-deployment.yaml b/postgres/postgres-deployment.yaml new file mode 100644 index 0000000..8eb130c --- /dev/null +++ b/postgres/postgres-deployment.yaml @@ -0,0 +1,50 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: postgres +spec: + replicas: 1 + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: docker.io/clearlinux/postgres + imagePullPolicy: "IfNotPresent" + ports: + - containerPort: 5432 + env: + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: postgres-config + key: POSTGRES_DB + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: postgres-config + key: POSTGRES_PASSWORD + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: postgres-config + key: POSTGRES_USER + +--- +apiVersion: v1 +kind: Service +metadata: + name: postgres + labels: + app: postgres +spec: + type: NodePort + ports: + - port: 5432 + targetPort: 5432 + nodePort: 30001 + selector: + app: postgres +