Implements Cluster PostgreSQL
This commit is contained in:
80
deploy.sh
80
deploy.sh
@@ -1,16 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
function check_for_dependencies() {
|
function check_for_dependencies() {
|
||||||
if ! command -v kubectl &> /dev/null; then
|
if ! command -v kubectl &>/dev/null; then
|
||||||
echo "kubectl could not be found"
|
echo "kubectl could not be found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if ! command -v jq &> /dev/null; then
|
if ! command -v jq &>/dev/null; then
|
||||||
echo "jq could not be found"
|
echo "jq could not be found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if ! command -v helm &> /dev/null; then
|
if ! command -v helm &>/dev/null; then
|
||||||
echo "helm could not be found"
|
echo "helm could not be found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -28,39 +27,37 @@ function configure_nginx_ingress() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function configure_cert_manager() {
|
function configure_cert_manager() {
|
||||||
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.12.5/cert-manager.yaml
|
helm repo add jetstack https://charts.jetstack.io --force-update
|
||||||
kubectl wait --for=condition=available \
|
helm repo update
|
||||||
--timeout=600s \
|
helm install cert-manager jetstack/cert-manager \
|
||||||
deployment.apps/cert-manager \
|
--namespace cert-manager \
|
||||||
deployment.apps/cert-manager-cainjector \
|
--create-namespace \
|
||||||
deployment.apps/cert-manager-webhook \
|
--version v1.14.2
|
||||||
-n cert-manager
|
}
|
||||||
|
|
||||||
|
function configure_postgres() {
|
||||||
|
helm install --create-namespace \
|
||||||
|
--namespace portfolio stackgres-operator \
|
||||||
|
--set-string adminui.service.type=ClusterIP \
|
||||||
|
https://stackgres.io/downloads/stackgres-k8s/stackgres/latest/helm/stackgres-operator.tgz
|
||||||
|
|
||||||
|
kubectl wait deployment -l group=stackgres.io --for=condition=Available -n portfolio
|
||||||
|
kubectl apply -f ./deployment/postgres/sgcluster.yaml
|
||||||
}
|
}
|
||||||
|
|
||||||
function application_deploy() {
|
function application_deploy() {
|
||||||
|
|
||||||
kubectl apply -f ./deployment/portfolio-namespace.yaml
|
|
||||||
|
|
||||||
kubectl create secret generic backend-secret -n portfolio \
|
kubectl create secret generic backend-secret -n portfolio \
|
||||||
--from-env-file <(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ./deployment/secrets/backendSecret.json);
|
--from-env-file <(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ./deployment/secrets/backendSecret.json)
|
||||||
|
|
||||||
kubectl create secret generic frontend-secret -n portfolio \
|
kubectl create secret generic frontend-secret -n portfolio \
|
||||||
--from-env-file <(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ./deployment/secrets/frontendSecret.json);
|
--from-env-file <(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ./deployment/secrets/frontendSecret.json)
|
||||||
|
|
||||||
kubectl create secret generic postgres-secret -n portfolio \
|
|
||||||
--from-env-file <(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ./deployment/secrets/postgresSecret.json);
|
|
||||||
|
|
||||||
kubectl create secret generic redis-secret -n portfolio \
|
kubectl create secret generic redis-secret -n portfolio \
|
||||||
--from-env-file <(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ./deployment/secrets/redisSecret.json);
|
--from-env-file <(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ./deployment/secrets/redisSecret.json)
|
||||||
|
|
||||||
kubectl create secret generic storage-secret -n portfolio \
|
kubectl create secret generic storage-secret -n portfolio \
|
||||||
--from-env-file <(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ./deployment/secrets/storageSecret.json);
|
--from-env-file <(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ./deployment/secrets/storageSecret.json)
|
||||||
|
|
||||||
kubectl apply -f ./deployment/postgres
|
|
||||||
kubectl wait --for=condition=available \
|
|
||||||
--timeout=600s \
|
|
||||||
deployment.apps/postgres-deployment \
|
|
||||||
-n portfolio
|
|
||||||
|
|
||||||
kubectl apply -f ./deployment/redis
|
kubectl apply -f ./deployment/redis
|
||||||
kubectl wait --for=condition=available \
|
kubectl wait --for=condition=available \
|
||||||
@@ -107,9 +104,21 @@ function main() {
|
|||||||
minikube addons enable ingress-dns
|
minikube addons enable ingress-dns
|
||||||
minikube addons enable ingress
|
minikube addons enable ingress
|
||||||
|
|
||||||
application_deploy
|
else
|
||||||
|
|
||||||
configure_cert_manager
|
configure_nginx_ingress
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
kubectl apply -f ./deployment/portfolio-namespace.yaml
|
||||||
|
|
||||||
|
configure_postgres
|
||||||
|
|
||||||
|
application_deploy
|
||||||
|
|
||||||
|
configure_cert_manager
|
||||||
|
|
||||||
|
if [[ $1 == "--local" || $1 == "-l" ]]; then
|
||||||
|
|
||||||
kubectl apply -f \
|
kubectl apply -f \
|
||||||
./deployment/cert-manager/cert-manager-issuer-dev.yaml
|
./deployment/cert-manager/cert-manager-issuer-dev.yaml
|
||||||
@@ -118,22 +127,11 @@ function main() {
|
|||||||
./deployment/cert-manager/cert-manager-certificate.yaml
|
./deployment/cert-manager/cert-manager-certificate.yaml
|
||||||
|
|
||||||
echo "http://$(/usr/bin/minikube ip)"
|
echo "http://$(/usr/bin/minikube ip)"
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
configure_nginx_ingress
|
configure_nginx_ingress
|
||||||
|
|
||||||
application_deploy
|
|
||||||
|
|
||||||
external_ip=""
|
|
||||||
while [ -z $external_ip ]; do
|
|
||||||
echo "Waiting for end point..."
|
|
||||||
external_ip=$(kubectl get svc --namespace=ingress-nginx ingress-nginx-controller --template="{{range .status.loadBalancer.ingress}}{{.ip}}{{end}}")
|
|
||||||
[ -z "$external_ip" ] && sleep 10
|
|
||||||
done
|
|
||||||
|
|
||||||
configure_cert_manager
|
|
||||||
|
|
||||||
kubectl apply -f \
|
kubectl apply -f \
|
||||||
./deployment/cert-manager/cert-manager-issuer.yaml
|
./deployment/cert-manager/cert-manager-issuer.yaml
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: ConfigMap
|
|
||||||
metadata:
|
|
||||||
namespace: portfolio
|
|
||||||
name: postgres-config
|
|
||||||
data:
|
|
||||||
postgres_url: postgres-service
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
kind: PersistentVolume
|
|
||||||
apiVersion: v1
|
|
||||||
metadata:
|
|
||||||
namespace: portfolio
|
|
||||||
name: postgres-pv-volume
|
|
||||||
labels:
|
|
||||||
type: local
|
|
||||||
app: postgres
|
|
||||||
spec:
|
|
||||||
storageClassName: manual
|
|
||||||
capacity:
|
|
||||||
storage: 5Gi
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
hostPath:
|
|
||||||
path: "/mnt/data"
|
|
||||||
---
|
|
||||||
kind: PersistentVolumeClaim
|
|
||||||
apiVersion: v1
|
|
||||||
metadata:
|
|
||||||
namespace: portfolio
|
|
||||||
name: postgres-pv-claim
|
|
||||||
labels:
|
|
||||||
app: postgres
|
|
||||||
spec:
|
|
||||||
storageClassName: manual
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteMany
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: 5Gi
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
namespace: portfolio
|
|
||||||
name: postgres-deployment
|
|
||||||
spec:
|
|
||||||
replicas: 1
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: postgres
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: postgres
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: postgres
|
|
||||||
image: postgres:14-bullseye
|
|
||||||
imagePullPolicy: "IfNotPresent"
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
memory: "256Mi"
|
|
||||||
cpu: "250m"
|
|
||||||
limits:
|
|
||||||
memory: "512Mi"
|
|
||||||
cpu: "250m"
|
|
||||||
ports:
|
|
||||||
- containerPort: 5432
|
|
||||||
env:
|
|
||||||
- name: POSTGRES_PASSWORD
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: postgres-secret
|
|
||||||
key: postgresPassword
|
|
||||||
|
|
||||||
- name: POSTGRES_USER
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: postgres-secret
|
|
||||||
key: postgresUser
|
|
||||||
|
|
||||||
- name: POSTGRES_DB
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: postgres-secret
|
|
||||||
key: postgresDatabase
|
|
||||||
volumeMounts:
|
|
||||||
- mountPath: /var/lib/postgresql/data
|
|
||||||
name: postgredb
|
|
||||||
volumes:
|
|
||||||
- name: postgredb
|
|
||||||
persistentVolumeClaim:
|
|
||||||
claimName: postgres-pv-claim
|
|
||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
namespace: portfolio
|
|
||||||
name: postgres-service
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
app: postgres
|
|
||||||
ports:
|
|
||||||
- port: 5432
|
|
||||||
protocol: TCP
|
|
||||||
targetPort: 5432
|
|
||||||
type: ClusterIP
|
|
||||||
27
deployment/postgres/sgcluster.yaml
Normal file
27
deployment/postgres/sgcluster.yaml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
apiVersion: stackgres.io/v1
|
||||||
|
kind: SGInstanceProfile
|
||||||
|
metadata:
|
||||||
|
namespace: portfolio
|
||||||
|
name: postgres-portfolio-profile
|
||||||
|
spec:
|
||||||
|
cpu: "250m"
|
||||||
|
memory: "512Mi"
|
||||||
|
containers:
|
||||||
|
pg-main-container:
|
||||||
|
cpu: "250m"
|
||||||
|
memory: "512Mi"
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: stackgres.io/v1
|
||||||
|
kind: SGCluster
|
||||||
|
metadata:
|
||||||
|
namespace: portfolio
|
||||||
|
name: postgres-cluster
|
||||||
|
spec:
|
||||||
|
instances: 1
|
||||||
|
postgres:
|
||||||
|
version: "latest"
|
||||||
|
pods:
|
||||||
|
persistentVolume:
|
||||||
|
size: "5Gi"
|
||||||
|
sgInstanceProfile: postgres-portfolio-profile
|
||||||
Reference in New Issue
Block a user