Add“postgres deploy with k8s”

This commit is contained in:
timlackhan
2019-09-04 17:25:37 +08:00
committed by ZhongbaoShi
parent 91839f8525
commit fa8a8a5bd1
3 changed files with 138 additions and 0 deletions
+37
View File
@@ -56,6 +56,43 @@ Docker Hub.
<!-- Optional -->
### 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=<your-postgres-db> \
--from-literal=POSTGRES_PASSWORD=<your-postgres-pwd> \
--from-literal=POSTGRES_USER=<your-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<nodeIP> -U<your-postgres-user> --password -p30001 <your-postgres-db>
```
<!-- Required -->
## Build and modify:
+51
View File
@@ -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
+50
View File
@@ -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