Back to Charts

PostgreSQL

stable/anchore-engine/charts/postgresql/README.md

latest11.9 KB
Original Source

PostgreSQL

PostgreSQL is a powerful, open source object-relational database system. It has more than 15 years of active development and a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness.

TL;DR;

bash
$ helm install stable/postgresql

Introduction

This chart bootstraps a PostgreSQL deployment on a Kubernetes cluster using the Helm package manager.

Prerequisites

  • Kubernetes 1.4+ with Beta APIs enabled
  • PV provisioner support in the underlying infrastructure (Only when persisting data)

Installing the Chart

To install the chart with the release name my-release:

bash
$ helm install --name my-release stable/postgresql

The command deploys PostgreSQL on the Kubernetes cluster in the default configuration. The configuration section lists the parameters that can be configured during installation.

Tip: List all releases using helm list

Uninstalling the Chart

To uninstall/delete the my-release deployment:

bash
$ helm delete my-release

The command removes all the Kubernetes components associated with the chart and deletes the release.

Configuration

The following table lists the configurable parameters of the PostgreSQL chart and their default values.

ParameterDescriptionDefault
imagepostgres image repositorypostgres
imageTagpostgres image tag9.6.2
imagePullPolicyImage pull policyAlways if imageTag is latest, else IfNotPresent
imagePullSecretsImage pull secretsnil
postgresUserUsername of new user to create.postgres
postgresPasswordPassword for the new user.random 10 characters
usePasswordFileInject the password via file instead of env varfalse
postgresDatabaseName for new database to create.postgres
postgresInitdbArgsInitdb Argumentsnil
schedulerNameName of an alternate schedulernil
existingSecretUse Existing secret for Admin passwordnil
postgresConfigRuntime Config Parametersnil
pgHbaConfContent of pg_hba.confnil (do not create pg_hba.conf)
persistence.enabledUse a PVC to persist datatrue
persistence.existingClaimProvide an existing PersistentVolumeClaimnil
persistence.storageClassStorage class of backing PVCnil (uses alpha storage class annotation)
persistence.accessModeUse volume as ReadOnly or ReadWriteReadWriteOnce
persistence.annotationsPersistent Volume annotations{}
persistence.sizeSize of data volume8Gi
persistence.subPathSubdirectory of the volume to mount atpostgresql-db
persistence.mountPathMount path of data volume/var/lib/postgresql/data/pgdata
persistence.resourcePolicyset resource-policy Helm annotation on PVC. Can be nil or "keep"nil
resourcesCPU/Memory resource requests/limitsMemory: 256Mi, CPU: 100m
metrics.enabledStart a side-car prometheus exporterfalse
metrics.imageExporter imagewrouesnel/postgres_exporter
metrics.imageTagExporter imagev0.1.1
metrics.imagePullPolicyExporter image pull policyIfNotPresent
metrics.resourcesExporter resource requests/limitMemory: 256Mi, CPU: 100m
metrics.customMetricsAdditional custom metricsnil
service.externalIPsExternal IPs to listen on[]
service.portTCP port5432
service.typek8s service type exposing ports, e.g. NodePortClusterIP
service.nodePortNodePort value if service.type is NodePortnil
networkPolicy.enabledEnable NetworkPolicyfalse
networkPolicy.allowExternalDon't require client label for connectionstrue
nodeSelectorNode labels for pod assignment{}
affinityAffinity settings for pod assignment{}
tolerationsToleration labels for pod assignment[]
terminationGracePeriodSecondsOptional duration in seconds the pod needs to terminate gracefullynil
probes.liveness.initialDelayLiveness probe initial delay60
probes.liveness.timeoutSecondsLiveness probe timeout seconds5
probes.liveness.failureThresholdLiveness probe failure threshold6
probes.readiness.initialDelayReadiness probe initial delay5
probes.readiness.timeoutSecondsReadiness probe timeout seconds3
probes.readiness.failureThresholdReadiness probe failure threshold5
podAnnotationsAnnotations for the postgresql pod{}
deploymentAnnotationsAnnotations for the postgresql deployment{}
extraEnvAny extra environment variables you would like to pass on to the pod{}

The above parameters map to the env variables defined in postgres. For more information please refer to the postgres image documentation.

Specify each parameter using the --set key=value[,key=value] argument to helm install. For example,

bash
$ helm install --name my-release \
  --set postgresUser=my-user,postgresPassword=secretpassword,postgresDatabase=my-database \
    stable/postgresql

The above command creates a PostgreSQL user named my-user with password secretpassword. Additionally it creates a database named my-database.

Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example,

bash
$ helm install --name my-release -f values.yaml stable/postgresql

Tip: You can use the default values.yaml

Persistence

The postgres image stores the PostgreSQL data and configurations at the /var/lib/postgresql/data/pgdata path of the container.

The chart mounts a Persistent Volume at this location. The volume is created using dynamic volume provisioning. If the PersistentVolumeClaim should not be managed by the chart, define persistence.existingClaim.

Note: When using persistence ensure that you either provide a postgresPassword or use existingSecret, otherwise helm update will generate a new random password which is ignored by postgres. That will cause confusing behaviour especially if services depend on the secret

Existing PersistentVolumeClaims

  1. Create the PersistentVolume
  2. Create the PersistentVolumeClaim
  3. Install the chart
bash
$ helm install --set persistence.existingClaim=PVC_NAME postgresql

The volume defaults to mount at a subdirectory of the volume instead of the volume root to avoid the volume's hidden directories from interfering with initdb. If you are upgrading this chart from before version 0.4.0, set persistence.subPath to "".

Metrics

The chart optionally can start a metrics exporter for prometheus. The metrics endpoint (port 9187) is not exposed and it is expected that the metrics are collected from inside the k8s cluster using something similar as the described in the example Prometheus scrape configuration.

The exporter allows to create custom metrics from additional SQL queries. See the Chart's values.yaml for an example and consult the exporters documentation for more details.

NetworkPolicy

To enable network policy for PostgreSQL, install a networking plugin that implements the Kubernetes NetworkPolicy spec, and set networkPolicy.enabled to true.

For Kubernetes v1.5 & v1.6, you must also turn on NetworkPolicy by setting the DefaultDeny namespace annotation. Note: this will enforce policy for all pods in the namespace:

kubectl annotate namespace default "net.beta.kubernetes.io/network-policy={\"ingress\":{\"isolation\":\"DefaultDeny\"}}"

With NetworkPolicy enabled, traffic will be limited to just port 5432.

For more precise policy, set networkPolicy.allowExternal=false. This will only allow pods with the generated client label to connect to PostgreSQL. This label will be displayed in the output of a successful install.