티스토리 뷰

1.k8s 으로 postgreSQL DB 생성 PV, PVC , configmap, secret 생성하기

2. Keycloak Docker / postgresql 사용

3. K8s 에서 postsql POD 생성및 터널링 진행

4. Centos Postgresql 설치하는 방법

5. 포스트 그레

6. Kubernetes 환경의 PostgreSQL 설치하기

7.Postgresql 설치및 간단한 사용방법정리!

8. postgresql Vacuum 기본에대해 알아보자!

9. PostgreSQL Pod 접속

 

참조 url : https://jmholly.tistory.com/entry/%EC%BF%A0%EB%B2%84%EB%84%A4%ED%8B%B0%EC%8A%A4-%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%B2%A0%EC%9D%B4%EC%8A%A4-pod%EA%B3%BC-%EC%96%B4%ED%94%8C%EB%A6%AC%EC%BC%80%EC%9D%B4%EC%85%98-%EC%97%B0%EA%B2%B0-postgre-DB

 

1.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: test-db-secret
  namespace: operations
data:
  POSTGRES_DB: dGVzdGRi
  POSTGRES_USER: dGVzdGFkbWlu
  POSTGRES_PASSWORD: dGVzdA==
  
*-  *-  *-  *-  *-  *-  *-  *-  *-  
  POSTGRES_DB: testdb
  POSTGRES_USER: testadmin
  POSTGRES_PASSWORD: test

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:15
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432
          envFrom:
            - configMapRef:          #configMap 을 사용한 경우
                name: postgres-config
            - secretRef:             #secret 을 사용한 경우
                name: test-db-secret # <secret 이름>
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgredb
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: pvc-local-testi

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-db
  namespace: operations
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
      tier: postgresql
  template:
    metadata:
      labels:
        app: test
        tier: postgresql
    spec:
      containers:
      - name: postgres
        image: postgres:15
        imagePullPolicy: "IfNotPresent"
        ports:
        - containerPort: 5432
        envFrom:
          - secretRef:
              name: test-db-secret
        volumeMounts:
        - mountPath: /var/lib/postgresql/data
          name: pv-local #test-db-pv
      volumes:
      - name: pv-local #test-db-pv
        persistentVolumeClaim:
          claimName: pvc-local-testi #test-db-pv-claim

 

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 <계정명> --password -p <NodePort> <Database 명>
psql -h localhost -U testadmin --password -p 5432 testdb
 

POSTGRES_PASSWORD: test

 

psql -h localhost -U testadmin --password -p 5432 testdb

 

 

댓글