반응형
이번 글은 postgres 배포입니다.
곧 사용할 것 같은 RDB이고, 큰 비중은 없어서 postgres 선택했습니다.
아래와 같은 순서로 진행됩니다.
- 네임스페이스 작성
- 컨피그맵 작성
- 스토리지 작성
- 퍼시스턴트 볼륨
- 퍼시스턴트 볼륨 클래임
- 배포(deployment) 작성
- 서비스 작성
- 배포 실행
- hello world 입력
# vim postgres-ns
apiVersion: v1
kind: Namespace
metadata:
name: db
- 네임스페이스 생성
# vim postgres-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-config
namespace: db
labels:
app: postgres
data:
POSTGRES_DB: postgresdb
POSTGRES_USER: admin
POSTGRES_PASSWORD: over090
- configmap 생성
# vim postgres-storage.yaml
kind: PersistentVolume
apiVersion: v1
metadata:
name: postgres-pv-volume
labels:
type: local
app: postgres
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
hostPath:
path: "/mnt/data"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres-pv-claim
namespace: db
labels:
app: postgres
spec:
storageClassName: manual
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
- PersistentVolume, PersistentVolumeClaim 생성
# postgres-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: db
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: 5432
envFrom:
- configMapRef:
name: postgres-config
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgredb
volumes:
- name: postgredb
persistentVolumeClaim:
claimName: postgres-pv-claim
- deploy 생성
# vim postgres-service.yaml
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: db
labels:
app: postgres
spec:
selector:
app: postgres
ports:
- port: 5432
- service 생성
kubectl apply -f .
- 작성한 파일 모두 deploy
k exec -it postgres-67d4f7cc7d-dqjms -n db -- psql -h localhost -U admin --password -p 5432 postgresdb
반응형
'kubernetes' 카테고리의 다른 글
kubernetes nginx-ingress-controller 504 bad gateway 해결 (0) | 2022.12.23 |
---|---|
deploy prometheus and grafana on kubernetes (0) | 2022.12.21 |
install kubernetes v1.25.5 on ubuntu 22.10 - kubeadm (0) | 2022.12.17 |
installation kubernetes by kubespray on-premise (0) | 2022.12.09 |
delete kubernetes all (0) | 2022.10.09 |