From 9bc0183ba072cb40e2d6791769e7279ccf8804e2 Mon Sep 17 00:00:00 2001 From: Larry Rensing Date: Thu, 23 Feb 2017 19:01:48 -0600 Subject: [PATCH] point MaaS to postgresql instance within cluster (#199) * Initial postgresql chart * maas/postgres wip * updated readme for postgresql * Edit service dependency --- helm-toolkit/templates/_hosts.tpl | 1 + maas/README.md | 46 ++++++++++++++++--- .../bin/_import-boot-resources.sh.tpl | 2 +- .../bin/_maas-region-controller.postinst.tpl | 11 ++--- maas/templates/bin/_start.sh.tpl | 13 ------ maas/templates/db-service.yaml | 27 ----------- maas/templates/deploy-region.yaml | 27 ----------- maas/templates/etc/_postgresql-config.tpl | 3 ++ maas/values.yaml | 2 +- {maas => postgresql}/.helmignore | 5 -- 10 files changed, 50 insertions(+), 87 deletions(-) delete mode 100644 maas/templates/db-service.yaml rename {maas => postgresql}/.helmignore (90%) diff --git a/helm-toolkit/templates/_hosts.tpl b/helm-toolkit/templates/_hosts.tpl index e7adb98b3f..b2a41cd456 100644 --- a/helm-toolkit/templates/_hosts.tpl +++ b/helm-toolkit/templates/_hosts.tpl @@ -31,6 +31,7 @@ # infrastructure services {{- define "helm-toolkit.rabbitmq_host"}}memcached.{{.Release.Namespace}}.svc.{{ include "helm-toolkit.region" . }}.{{ include "helm-toolkit.tld" . }}{{- end}} {{- define "helm-toolkit.mariadb_host"}}mariadb.{{.Release.Namespace}}.svc.{{ include "helm-toolkit.region" . }}.{{ include "helm-toolkit.tld" . }}{{- end}} +{{- define "helm-toolkit.postgresql_host"}}postgresql.{{.Release.Namespace}}.svc.{{ include "helm-toolkit.region" . }}.{{ include "helm-toolkit.tld" . }}{{- end}} # nova defaults {{- define "helm-toolkit.nova_metadata_host"}}nova-api.{{ include "helm-toolkit.fqdn" . }}{{- end}} diff --git a/maas/README.md b/maas/README.md index d52af86acb..d2e63572c0 100644 --- a/maas/README.md +++ b/maas/README.md @@ -4,6 +4,22 @@ This chart installs a working version of MaaS on kubernetes. ### Quickstart +This chart requires a postgresql instance to be running. + +To install postgresql: + +``` +helm install postgresql --namespace=maas +``` + +Note: Postgresql may take a short time to reach the 'Running' state. Verify that postgresql is running: + +``` +# kubectl get pods -n maas +NAME READY STATUS RESTARTS AGE +postgresql-0 1/1 Running 0 1m +``` + To deploy your MaaS chart: ``` @@ -13,16 +29,34 @@ helm install maas --namespace=maas To verify the helm deployment was successful: ``` # helm ls -NAME REVISION UPDATED STATUS CHART -opining-ocelot 1 Wed Nov 23 19:48:41 2016 DEPLOYED maas-0.1.0 +NAME REVISION UPDATED STATUS CHART +opining-mule 1 Mon Feb 13 22:20:08 2017 DEPLOYED maas-0.1.0 +sweet-manatee 1 Mon Feb 13 21:57:41 2017 DEPLOYED postgresql-0.1.0 + ``` To check that all resources are working as intended: ``` # kubectl get all --namespace=maas +NAME READY STATUS RESTARTS AGE +po/maas-rack-3238195061-tn5fv 1/1 Running 0 11m +po/maas-region-0 1/1 Running 0 11m +po/postgresql-0 1/1 Running 0 34m + NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE -svc/maas-region-ui 10.109.228.165 80/TCP,8000/TCP 2m -NAME READY STATUS RESTARTS AGE -po/maas-rack-2449935402-ppn34 1/1 Running 0 2m -po/maas-region-638716514-miczz 1/1 Running 0 2m +svc/maas-region-ui 10.105.136.244 80/TCP,8000/TCP 11m +svc/postgresql 10.107.159.38 5432/TCP 34m + +NAME DESIRED CURRENT AGE +statefulsets/maas-region 1 1 11m +statefulsets/postgresql 1 1 34m + +NAME DESIRED SUCCESSFUL AGE +jobs/region-import-resources 1 1 11m + +NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE +deploy/maas-rack 1 1 1 1 11m + +NAME DESIRED CURRENT READY AGE +rs/maas-rack-3238195061 1 1 1 11m ``` diff --git a/maas/templates/bin/_import-boot-resources.sh.tpl b/maas/templates/bin/_import-boot-resources.sh.tpl index a4d4fabf94..9ddfa616d0 100644 --- a/maas/templates/bin/_import-boot-resources.sh.tpl +++ b/maas/templates/bin/_import-boot-resources.sh.tpl @@ -34,7 +34,7 @@ function check_for_download { } maas-region local_config_set \ - --database-host "{{ .Values.db_service_name }}.{{ .Release.Namespace }}" \ + --database-host "{{ include "helm-toolkit.postgresql_host" . }}" \ --database-name "{{ .Values.database.db_name }}" \ --database-user "{{ .Values.database.db_user }}" \ --database-pass "{{ .Values.database.db_password }}" \ diff --git a/maas/templates/bin/_maas-region-controller.postinst.tpl b/maas/templates/bin/_maas-region-controller.postinst.tpl index d43d141e02..c8f1e834d7 100644 --- a/maas/templates/bin/_maas-region-controller.postinst.tpl +++ b/maas/templates/bin/_maas-region-controller.postinst.tpl @@ -87,16 +87,13 @@ if [ "$1" = "configure" ] && [ -z "$2" ]; then ################ Configure Database ################### ######################################################### - # Need to for postgresql start so it doesn't fail on the installer - restart_postgresql - # Create the database dbc_go maas-region-controller $@ maas-region local_config_set \ - --database-host "localhost" \ - --database-name "{{ .Values.database.db_name }}" \ - --database-user "{{ .Values.database.db_user }}" \ - --database-pass "{{ .Values.database.db_password }}" + --database-host {{ include "helm-toolkit.postgresql_host" . | quote }} \ + --database-name {{ .Values.database.db_name | quote }} \ + --database-user {{ .Values.database.db_user | quote }} \ + --database-pass {{ .Values.database.db_password | quote }} # Only syncdb if we have selected to install it with dbconfig-common. db_get maas-region-controller/dbconfig-install diff --git a/maas/templates/bin/_start.sh.tpl b/maas/templates/bin/_start.sh.tpl index ec35e9776c..2b605a632f 100644 --- a/maas/templates/bin/_start.sh.tpl +++ b/maas/templates/bin/_start.sh.tpl @@ -16,19 +16,6 @@ set -ex -if ! find "/etc/postgresql" -mindepth 1 -print -quit | grep -q .; then - pg_createcluster 9.5 main - - #allow external connections to postgresql - sed -i '/#listen_addresses/s/^#//g' /etc/postgresql/9.5/main/postgresql.conf - sed -i '/^listen_addresses/ s/localhost/*/' /etc/postgresql/9.5/main/postgresql.conf - sed -i '$ a host all all 0.0.0.0/0 md5' /etc/postgresql/9.5/main/pg_hba.conf - sed -i '$ a host all all ::/0 md5' /etc/postgresql/9.5/main/pg_hba.conf -fi - -cp -r /etc/postgresql/9.5/main/*.conf /var/lib/postgresql/9.5/main/ -pg_ctlcluster 9.5 main start - echo 'running postinst' chmod 755 /var/lib/dpkg/info/maas-region-controller.postinst diff --git a/maas/templates/db-service.yaml b/maas/templates/db-service.yaml deleted file mode 100644 index bf410a548f..0000000000 --- a/maas/templates/db-service.yaml +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2017 The Openstack-Helm Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -apiVersion: v1 -kind: Service -metadata: - name: {{ .Values.db_service_name }} - labels: - app: db-service -spec: - ports: - - port: {{ .Values.network.port.db_service }} - targetPort: {{ .Values.network.port.db_service_target }} - name: db-service - selector: - app: maas-region diff --git a/maas/templates/deploy-region.yaml b/maas/templates/deploy-region.yaml index 27100f2672..96f7b769d6 100644 --- a/maas/templates/deploy-region.yaml +++ b/maas/templates/deploy-region.yaml @@ -34,18 +34,6 @@ spec: "name": "maas-config", "mountPath": "/etc/maas/" }, - { - "name": "postgresql-config", - "mountPath": "/etc/postgresql" - }, - { - "name": "postgresql-data", - "mountPath": "/var/lib/postgresql" - }, - { - "name": "postgresql-run", - "mountPath": "/var/run/postgresql" - }, { "name": "startsh", "mountPath": "/tmp/start.sh", @@ -83,25 +71,17 @@ spec: ports: - name: region-ui containerPort: {{ .Values.network.port.region_container }} - - name: postgresql - containerPort: {{ .Values.network.port.db_service }} readinessProbe: tcpSocket: port: {{ .Values.network.port.region_container }} securityContext: privileged: true volumeMounts: - - name: postgresql-data - mountPath: /var/lib/postgresql - - name: postgresql-run - mountPath: /var/run/postgresql - name: maas-lib mountPath: /var/lib/maas - name: maas-region-secret mountPath: /var/lib/maas/secret subPath: secret - - name: postgresql-config - mountPath: /etc/postgresql - name: maas-dns-config mountPath: /etc/bind/named.conf.options subPath: named.conf.options @@ -109,13 +89,6 @@ spec: mountPath: /etc/maas/regiond.conf subPath: regiond.conf volumes: - - name: postgresql-data - hostPath: - path: /var/lib/postgresql - - name: postgresql-run - emptyDir: {} - - name: postgresql-config - emptyDir: {} - name: maas-lib emptyDir: {} - name: maas-region-secret diff --git a/maas/templates/etc/_postgresql-config.tpl b/maas/templates/etc/_postgresql-config.tpl index 325a24bc65..d63c93d11c 100644 --- a/maas/templates/etc/_postgresql-config.tpl +++ b/maas/templates/etc/_postgresql-config.tpl @@ -50,6 +50,9 @@ dbc_dbname='{{ .Values.database.db_name }}' # ignored and instead is determined from /etc/mysql/debian.cnf. dbc_dbadmin='postgres' +dbc_dbserver={{ include "helm-toolkit.postgresql_host" . | quote }} +dbc_dbport={{ .Values.network.port.db_service }} + # dbc_authmethod_admin: authentication method for admin # dbc_authmethod_user: authentication method for dbuser # see the section titled "AUTHENTICATION METHODS" in diff --git a/maas/values.yaml b/maas/values.yaml index 06ba0476ea..5c7f8e926b 100644 --- a/maas/values.yaml +++ b/maas/values.yaml @@ -34,7 +34,7 @@ dependencies: - maas-region service: - maas-region-ui - - db-service + - postgresql images: maas_region: quay.io/attcomdev/maas-region:2.1.2-2 diff --git a/maas/.helmignore b/postgresql/.helmignore similarity index 90% rename from maas/.helmignore rename to postgresql/.helmignore index 2c87a915d0..f0c1319444 100644 --- a/maas/.helmignore +++ b/postgresql/.helmignore @@ -19,8 +19,3 @@ .project .idea/ *.tmproj - -secrets/ -patches/ -*.py -Makefile