docs/main/deployment-guide/server/kubernetes/deploy-k8s.mdx
You can use the Mattermost Kubernetes Operator to deploy Mattermost on Kubernetes using S3-compatible storage and a managed database service. While the operator supports a range of configurations, we strongly recommend using a cloud-native approach for production environments.
<Tip>Need a FIPS / STIG-compliant image? Point the Operator manifest's version/image field at mattermost/mattermost-enterprise-fips-edition image and the rest of this procedure is unchanged. See FIPS / STIG container builds.
Before you begin, ensure you have the following:
The installation process involves setting up necessary operators and then deploying Mattermost itself.
Follow the instructions in the Kubernetes deployment documentation to install the NGINX ingress controller on your Kubernetes cluster. Mattermost recommends installing the Nginx Operator via helm, regardless of platform you are installing to.
The Mattermost Kubernetes Operator can be installed using Helm.
shhelm repo add mattermost https://helm.mattermost.com
config.yaml and populate it with the contents of the Mattermost operator values file. This file allows for customization of the operator.shkubectl create ns mattermost-operator
shhelm install <your-release-name> mattermost/mattermost-operator -n <namespace_name>For example:
shhelm install mattermost-operator mattermost/mattermost-operator -n mattermost-operatorTo use your custom
config.yamlfile:shhelm install mattermost-operator mattermost/mattermost-operator -n mattermost-operator -f config.yaml
Replicas: 1 to the spec section in step 2 below. See the high availability documentation for more on highly-available deployments.mattermost-license-secret.yaml with the following content, replacing [LICENSE_FILE_CONTENTS] with your actual license:yamlapiVersion: v1 kind: Secret metadata: name: my-mattermost-license type: Opaque stringData: license: <LICENSE_FILE_CONTENTS>
mattermost-installation.yaml. File names in this guide are suggestions; you can use different names. Use the following template, adjusting the values as needed:yamlapiVersion: installation.mattermost.com/v1beta1 kind: Mattermost metadata: name: <INSTALLATION_NAME_HERE> # Example: mm-example-full spec: size: <SIZE_VALUE_HERE> # Example: 5000users ingress: enabled: true host: <FULL_DOMAIN_NAME_HERE> # Example: example.mattermost-example.com annotations: kubernetes.io/ingress.class: nginx version: <VERSION_HERE> # Example: 9.3.0 licenseSecret: "" # If you created a license secret, put the name hereKey fields in the manifest include:
metadata.name: The name of your Mattermost deployment in Kubernetes.spec.size: The size of your installation (e.g., "100users", "1000users", etc.).spec.ingress.host: The DNS name for your Mattermost installation.spec.version: The Mattermost version. See the server version archive for available versions. You should use a supported version of Mattermost in conjunction with the latest version of the Mattermost Operator.spec.licenseSecret: The name of the Kubernetes secret containing your license (required for Enterprise).For a full list of configurable fields, see the example manifest and the Custom Resource Definition.
mattermost-database-secret.yaml for database credentials. This secret must be in the same namespace as the Mattermost installation.<Note>yamlapiVersion: v1 data: DB_CONNECTION_CHECK_URL: <DB_CONNECTION_CHECK_URL> DB_CONNECTION_STRING: <DB_CONNECTION_STRING> MM_SQLSETTINGS_DATASOURCEREPLICAS: <MM_SQLSETTINGS_DATASOURCEREPLICAS> kind: Secret metadata: name: my-postgres-connection type: OpaqueExample for AWS Aurora with PostgreSQL (
DB_CONNECTION_CHECK_URL,DB_CONNECTION_STRING, andMM_SQLSETTINGS_DATASOURCEREPLICASare the base64-encoded form of your Aurora connection URL, e.g.postgres://user:password@host:5432/mattermost):yamlapiVersion: v1 data: DB_CONNECTION_CHECK_URL: cG9zdGdyZXM6Ly91c2Vy... # base64-encoded connection URL DB_CONNECTION_STRING: cG9zdGdyZXM6Ly91c2Vy... # base64-encoded connection URL MM_SQLSETTINGS_DATASOURCEREPLICAS: cG9zdGdyZXM6... # base64-encoded replica URL kind: Secret metadata: name: my-postgres-connection type: Opaque
The DB_CONNECTION_CHECK_URL value is consumed by the operator's legacy postgres:13 + pg_isready readiness init container (the default external mode of spec.database.readinessCheck). New deployments are encouraged to set spec.database.readinessCheck.mode: builtin (see Step 5 below), in which case the readiness init container runs the in-image mattermost db ping command and the DB_CONNECTION_CHECK_URL field is no longer required. The legacy external mode remains the default for backward compatibility but is slated for deprecation in a future operator release.
Create a file named mattermost-filestore-secret.yaml to store the credentials for your object storage service (e.g., AWS S3 or any S3-compatible service). This secret must be created in the same namespace where you intend to install Mattermost. The file should contain the following YAML structure:
apiVersion: v1
kind: Secret
metadata:
name: <secret-name> # Choose a descriptive name (e.g., my-s3-credentials)
type: Opaque
data:
accesskey: <base64-encoded-access-key>
secretkey: <base64-encoded-secret-key>
The accesskey and secretkey values must be base64-encoded. Do not enter the raw keys directly. Use a command-line tool to generate the base64 strings.
Example (AWS S3):
apiVersion: v1
kind: Secret
metadata:
name: my-s3-credentials
type: Opaque
data:
accesskey: QUNDRVNTX0tFWQo= # Example: Replace with your actual encoded key
secretkey: U1VQRVJfU0VDUkVUX0tFWQo= # Example: Replace with your actual encoded key
mattermost-installation.yaml file (created in step 2) to connect Mattermost to your external database and object storage. Refer to the supported fields for guidance on where to add these configurations within the YAML structure.
Add the following to the
specsection of your manifest:yamlspec: database: external: secret: <database-secret-name> # The name of the database secret (e.g., my-postgres-connection)
(Recommended) Configure the database-readiness init container to use the in-image
mattermost db pingcommand instead of the legacypostgres:13+pg_isreadyflow. This avoids the need to pull a separatepostgres:13image (the primary motivation for air-gapped clusters that can't mirror it) and keeps your readiness check in sync with the Mattermost release you're running.yamlspec: database: external: secret: <database-secret-name> readinessCheck: mode: builtin timeout: 5m # optional; default is 5mUsing
builtinmode requires a Mattermost release that ships themattermost db pingcommand (see the Mattermost server pull request for availability).Omitting
readinessCheck(or settingmode: external) preserves the legacypostgres:13+pg_isreadybehavior. The legacy mode is the current default for backward compatibility and will be deprecated in a future operator release. See the Mattermost CRD reference for the fullreadinessCheckfield schema.
Add the following to the
specsection of your manifest:yamlspec: fileStore: external: url: <storage-service-url> # The URL of your storage service (e.g., s3.amazonaws.com) bucket: <bucket-name> # The name of your storage bucket secret: <filestore-secret-name> # The name of the filestore secret (e.g., my-s3-credentials)
mattermostEnv section:yamlspec: mattermostEnv: MM_FILESETTINGS_AMAZONS3SSL: true MM_FILESETTINGS_AMAZONS3SSE: true
After a Mattermost installation has been created with the Operator, you can review its status with the following:
kubectl -n [namespace] get mattermost
The kubectl describe command can be used to obtain more information about the Mattermost server pods:
kubectl -n [namespace] describe pod
Follow logs
The following command can be used to follow logs on any kubernetes pod:
kubectl -n [namespace] logs -f [pod name]
If the -n [namespace] is omitted, then the default namespace of the current context is used. We recommend specifying the namespace based on your deployment.
This command can be used to review the Mattermost Operator or Mattermost server logs as needed.
<Note>While generally speaking, the Operator should be compatible with most, or all versions of Mattermost Server, we recommend always using the latest version of the Operator in conjunction with a supported version of Mattermost Server.