티스토리 뷰
CLOUD/Kubernetes
[쿠버네티스] 데이터베이스 pod과 어플리케이션 연결 (postgreSQL DB) configMap, secret
헐리 2021. 9. 27. 16:011.PV생성
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-local
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
2.PVC생성
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-local-testi
namespace: operations
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
3.config 또는 secret생성
ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-config
labels:
app: postgres
namespace: operations
data:
POSTGRES_DB: postgresdb
POSTGRES_USER: root
POSTGRES_PASSWORD: admin123
Secret
apiVersion: v1
kind: Secret
metadata:
name: 이름
namespace: operations
data:
POSTGRES_DB: <base64>
POSTGRES_USER: <base64>
POSTGRES_PASSWORD: <base64>
4.postgreSQL deployment 생성
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: operations
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:13.3
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: 5432
envFrom:
- configMapRef: #configMap 을 사용한 경우
name: postgres-config
- secretRef: #secret 을 사용한 경우
name: <secret 이름>
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgredb
volumes:
- name: postgredb
persistentVolumeClaim:
claimName: pvc-local-testi
5.postgreSQL service 생성
apiVersion: v1
kind: Service
metadata:
name: postgres
labels:
app: postgres
namespace: operations
spec:
type: NodePort
ports:
- port: 5432
selector:
app: postgres
postgreSQL연동 test
psql -h localhost -U root --password -p <NodePort> postgresdb