Using the Praefect chart

  • Tier: Free, Premium, Ultimate
  • Offering: GitLab Self-Managed
  • Status: Experiment

The Praefect chart is an experiment and is not suitable for production use. Upgrades may require significant manual intervention. GitLab has de-prioritized this configuration in favor of a new Gitaly storage backend. For details of alternatives to using the Praefect chart and available options, see Gitaly on Kubernetes.

The Praefect chart is used to manage Gitaly Cluster (Praefect) inside a GitLab installment deployed with the Helm charts.

Known issues

  1. The database has to be manually created.
  2. The cluster size is fixed: Gitaly Cluster (Praefect) does not support autoscaling.
  3. Using a Praefect instance in the cluster to manage Gitaly instances outside the cluster is not supported.

Requirements

This chart consumes the Gitaly chart. Settings from global.gitaly are used to configure the instances created by this chart. Documentation of these settings can be found in Gitaly chart documentation.

Important: global.gitaly.tls is independent of global.praefect.tls. They are configured separately.

By default, this chart will create 3 Gitaly Replicas.

Configuration

The chart is disabled by default. To enable it as part of a chart deploy set global.praefect.enabled=true.

Extra volumes

Use gitlab.praefect.extraVolumes with gitlab.praefect.extraVolumeMounts to add volumes and mount them in the Praefect container. Both values are template strings, so they can reference Helm template variables.

For example:

yaml
gitlab:
  praefect:
    extraVolumes: |
      - name: '{{ .Release.Name }}-praefect-data'
        emptyDir: {}
    extraVolumeMounts: |
      - name: '{{ .Release.Name }}-praefect-data'
        mountPath: /example

Replicas

The default number of replicas to deploy is 3. This can be changed by setting global.praefect.virtualStorages[].gitalyReplicas with the desired number of replicas. For example:

yaml
global:
  praefect:
    enabled: true
    virtualStorages:
    - name: default
      gitalyReplicas: 4
      maxUnavailable: 1

Multiple virtual storages

Multiple virtual storages can be configured (see Gitaly Cluster (Praefect) documentation). For example:

yaml
global:
  praefect:
    enabled: true
    virtualStorages:
    - name: default
      gitalyReplicas: 4
      maxUnavailable: 1
    - name: vs2
      gitalyReplicas: 5
      maxUnavailable: 2

This will create two sets of resources for Gitaly. This includes two Gitaly StatefulSets (one per virtual storage).

Administrators can then configure where new repositories are stored.

Persistence

It is possible to provide persistence configuration per virtual storage.

yaml
global:
  praefect:
    enabled: true
    virtualStorages:
    - name: default
      gitalyReplicas: 4
      maxUnavailable: 1
      persistence:
        enabled: true
        size: 50Gi
        accessMode: ReadWriteOnce
        storageClass: storageclass1
    - name: vs2
      gitalyReplicas: 5
      maxUnavailable: 2
      persistence:
        enabled: true
        size: 100Gi
        accessMode: ReadWriteOnce
        storageClass: storageclass2

defaultReplicationFactor

defaultReplicationFactor can be configured on each virtual storages. For more information, see configure replication-factor.

yaml
global:
  praefect:
    enabled: true
    virtualStorages:
    - name: default
      gitalyReplicas: 5
      maxUnavailable: 2
      defaultReplicationFactor: 3
    - name: secondary
      gitalyReplicas: 4
      maxUnavailable: 1
      defaultReplicationFactor: 2

Migrating to Praefect

When migrating from standalone Gitaly instances to a Praefect setup, global.praefect.replaceInternalGitaly can be set to false. This ensures that the existing Gitaly instances are preserved while the new Praefect-managed Gitaly instances are created.

yaml
global:
  praefect:
    enabled: true
    replaceInternalGitaly: false
    virtualStorages:
    - name: virtualStorage2
      gitalyReplicas: 5
      maxUnavailable: 2

When migrating to Praefect, none of Praefect’s virtual storages can be named default. This is because there must be at least one storage named default at all times, therefore the name is already taken by the non-Praefect configuration.

The instructions to migrate to Gitaly Cluster (Praefect) can then be followed to move data from the default storage to virtualStorage2. If additional storages were defined under global.gitaly.internal.names, be sure to migrate repositories from those storages as well.

After the repositories have been migrated to virtualStorage2, replaceInternalGitaly can be set back to true if a storage named default is added in the Praefect configuration.

yaml
global:
  praefect:
    enabled: true
    replaceInternalGitaly: true
    virtualStorages:
    - name: default
      gitalyReplicas: 4
      maxUnavailable: 1
    - name: virtualStorage2
      gitalyReplicas: 5
      maxUnavailable: 2

The instructions to migrate to Gitaly Cluster (Praefect) can be followed again to move data from virtualStorage2 to the newly-added default storage if desired.

Finally, see the repository storage paths documentation to configure where new repositories are stored.

Creating the database

Praefect uses its own database to track its state. This has to be manually created in order for Praefect to be functional.

  1. Log into your database instance. The exact connection command may vary depends on your setup.

    shell
    psql -U postgres -d template1
  2. Create the database user:

    sql
    CREATE ROLE praefect WITH LOGIN;
  3. Set the database user password.

    By default, the shared-secrets Job will generate a secret for you.

    1. Fetch the password:

      shell
      kubectl get secret RELEASE_NAME-praefect-dbsecret -o jsonpath="{.data.secret}" | base64 --decode
    2. Set the password in the psql prompt:

      sql
      \password praefect
  4. Create the database:

    sql
    CREATE DATABASE praefect WITH OWNER praefect;

Running Praefect over TLS

Praefect supports communicating with client and Gitaly nodes over TLS. This is controlled by the settings global.praefect.tls.enabled and global.praefect.tls.secretName. To run Praefect over TLS follow these steps:

  1. The Helm chart expects a certificate to be provided for communicating over TLS with Praefect. This certificate should apply to all the Praefect nodes that are present. Hence all hostnames of each of these nodes should be added as a Subject Alternate Name (SAN) to the certificate or alternatively, you can use wildcards.

    To know the hostnames to use, check the file /srv/gitlab/config/gitlab.yml file in the Toolbox Pod and check the various gitaly_address fields specified under repositories.storages key within it.

    shell
    kubectl exec -it <Toolbox Pod> -- grep gitaly_address /srv/gitlab/config/gitlab.yml

A basic script for generating custom signed certificates for internal Praefect Pods can be found in this repository. Users can use or refer that script to generate certificates with proper SAN attributes.

The script covers both the partial addresses (.svc) and the fully qualified addresses (.svc.cluster.local). The certificate stays valid whether or not global.clusterDomain is set. If your cluster uses a different domain, pass it as CLUSTER_DOMAIN:

shell
CLUSTER_DOMAIN=k8s.example ./scripts/generate_certificates.sh praefect

The gitaly_address values from the previous step show which names the certificate must cover.

  1. Create a TLS Secret using the certificate created.

    shell
    kubectl create secret tls <secret name> --cert=praefect.crt --key=praefect.key
  2. Redeploy the Helm chart by passing --set global.praefect.tls.enabled=true.

When running Gitaly over TLS, a secret name must be provided for each virtual storage.

yaml
global:
  gitaly:
    tls:
      enabled: true
  praefect:
    enabled: true
    tls:
      enabled: true
      secretName: praefect-tls
    virtualStorages:
    - name: default
      gitalyReplicas: 4
      maxUnavailable: 1
      tlsSecretName: default-tls
    - name: vs2
      gitalyReplicas: 5
      maxUnavailable: 2
      tlsSecretName: vs2-tls

Installation command line options

The table below contains all the possible charts configurations that can be supplied to the helm install command using the --set flags.

ParameterDefaultDescription
common.labels{}Supplemental labels that are applied to all objects created by this chart.
failover.enabledtrueWhether Praefect should perform failover on node failure
failover.readonlyAftertrueWhether the nodes should be in read-only mode after failover
autoMigratetrueAutomatically run migrations on startup
image.repositoryregistry.gitlab.com/gitlab-org/build/cng/gitalyThe default image repository to use. Praefect is bundled as part of the Gitaly image
podLabels{}Supplemental Pod labels. Will not be used for selectors.
ntpHostpool.ntp.orgConfigure the NTP server Praefect should ask the for the current time.
service.namepraefectThe name of the service to create
service.typeClusterIPThe type of service to create
service.internalPort8075The internal port number that the Praefect pod will be listening on
service.externalPort8075The port number the Praefect service should expose in the cluster
service.trafficDistributionSets spec.trafficDistribution on the Service. Not set by default.
init.resources
init.image
init.containerSecurityContext.allowPrivilegeEscalationfalseinitContainer specific: Controls whether a process can gain more privileges than its parent process
init.containerSecurityContext.runAsNonRoottrueinitContainer specific: Controls whether the container runs with a non-root user
init.containerSecurityContext.capabilities.drop[ "ALL" ]initContainer specific: Removes Linux capabilities for the container
extraVolumeMountsList of extra volume mounts to create
extraVolumesList of extra volumes to create
extraEnvFromList of extra environment variables from other data sources to expose
logging.levelLog level
logging.formatjsonLog format
logging.sentryDsnSentry DSN URL - Exceptions from Go server
logging.sentryEnvironmentSentry environment to be used for logging
metrics.enabledtrueIf a metrics endpoint should be made available for scraping
metrics.port9236Metrics endpoint port
metrics.separate_database_metricstrueIf true then metrics scrapes will not perform database queries, setting to false may cause performance problems
metrics.path/metricsMetrics endpoint path
metrics.serviceMonitor.enabledfalseIf a ServiceMonitor should be created to enable Prometheus Operator to manage the metrics scraping, note that enabling this removes the prometheus.io scrape annotations
affinity{}Affinity rules for pod assignment
metrics.serviceMonitor.additionalLabels{}Additional labels to add to the ServiceMonitor
metrics.serviceMonitor.endpointConfig{}Additional endpoint configuration for the ServiceMonitor
securityContext.runAsUser1000
securityContext.fsGroup1000
securityContext.fsGroupChangePolicyPolicy for changing ownership and permission of the volume (requires Kubernetes 1.23)
securityContext.seLinuxChangePolicyPolicy for changing SELinux labels on the volume. MountOption uses a mount option instead of recursive relabeling. Requires Kubernetes 1.32
securityContext.seccompProfile.typeRuntimeDefaultSeccomp profile to use
containerSecurityContext.allowPrivilegeEscalationfalseControls whether a process of the container can gain more privileges than its parent process
containerSecurityContext.runAsNonRoottrueControls whether the container runs with a non-root user
containerSecurityContext.capabilities.drop[ "ALL" ]Removes Linux capabilities for the Gitaly container
serviceAccount.annotations{}ServiceAccount annotations
serviceAccount.automountServiceAccountTokenfalseIndicates whether or not the default ServiceAccount access token should be mounted in pods
serviceAccount.createfalseIndicates whether or not a ServiceAccount should be created
serviceAccount.enabledfalseIndicates whether or not to use a ServiceAccount
serviceAccount.nameName of the ServiceAccount. If not set, the full chart name is used
serviceLabels{}Supplemental service labels
statefulset.strategy{}Allows one to configure the update strategy utilized by the statefulset
statefulset.revisionHistoryLimitThe number of previous revisions to keep. When not provided and global.revisionHistoryLimit is unset, the Kubernetes default is used.

serviceAccount

This section controls if a ServiceAccount should be created and if the default access token should be mounted in pods.

NameTypeDefaultDescription
annotationsMap{}ServiceAccount annotations.
automountServiceAccountTokenBooleanfalseControls if the default ServiceAccount access token should be mounted in pods. You should not enable this unless it is required by certain sidecars to work properly (for example, Istio).
createBooleanfalseIndicates whether or not a ServiceAccount should be created.
enabledBooleanfalseIndicates whether or not to use a ServiceAccount.
nameStringName of the ServiceAccount. If not set, the full chart name is used.

affinity

For more information, see affinity.