diff --git a/deploy.sh b/deploy.sh index ef2911a..a223751 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,16 +1,15 @@ #!/bin/bash - function check_for_dependencies() { - if ! command -v kubectl &> /dev/null; then + if ! command -v kubectl &>/dev/null; then echo "kubectl could not be found" exit 1 fi - if ! command -v jq &> /dev/null; then + if ! command -v jq &>/dev/null; then echo "jq could not be found" exit 1 fi - if ! command -v helm &> /dev/null; then + if ! command -v helm &>/dev/null; then echo "helm could not be found" exit 1 fi @@ -28,39 +27,37 @@ function configure_nginx_ingress() { } function configure_cert_manager() { - kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.12.5/cert-manager.yaml - kubectl wait --for=condition=available \ - --timeout=600s \ - deployment.apps/cert-manager \ - deployment.apps/cert-manager-cainjector \ - deployment.apps/cert-manager-webhook \ - -n cert-manager + helm repo add jetstack https://charts.jetstack.io --force-update + helm repo update + helm install cert-manager jetstack/cert-manager \ + --namespace cert-manager \ + --create-namespace \ + --version v1.14.2 +} + +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() { - kubectl apply -f ./deployment/portfolio-namespace.yaml - 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 \ - --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); + --from-env-file <(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ./deployment/secrets/frontendSecret.json) 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 \ - --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 + --from-env-file <(jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")|.[]" ./deployment/secrets/storageSecret.json) kubectl apply -f ./deployment/redis kubectl wait --for=condition=available \ @@ -107,9 +104,21 @@ function main() { minikube addons enable ingress-dns 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 \ ./deployment/cert-manager/cert-manager-issuer-dev.yaml @@ -118,22 +127,11 @@ function main() { ./deployment/cert-manager/cert-manager-certificate.yaml echo "http://$(/usr/bin/minikube ip)" - + else 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 \ ./deployment/cert-manager/cert-manager-issuer.yaml diff --git a/deployment/postgres/postgres-config.yaml b/deployment/postgres/postgres-config.yaml deleted file mode 100644 index 6f222a7..0000000 --- a/deployment/postgres/postgres-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - namespace: portfolio - name: postgres-config -data: - postgres_url: postgres-service \ No newline at end of file diff --git a/deployment/postgres/postgres-storage.yaml b/deployment/postgres/postgres-storage.yaml deleted file mode 100644 index 638ac3a..0000000 --- a/deployment/postgres/postgres-storage.yaml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/deployment/postgres/postgres.yaml b/deployment/postgres/postgres.yaml deleted file mode 100644 index 29b5e3e..0000000 --- a/deployment/postgres/postgres.yaml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/deployment/postgres/sgcluster.yaml b/deployment/postgres/sgcluster.yaml new file mode 100644 index 0000000..576c420 --- /dev/null +++ b/deployment/postgres/sgcluster.yaml @@ -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