Thursday, December 26, 2024
Google search engine
HomeGuest BlogsInstall and Configure Mattermost on a Kubernetes Cluster

Install and Configure Mattermost on a Kubernetes Cluster

Mattermost is an open-source messaging platform designed to serve a large number of concurrent users across the world. It is the biggest competitor of MS Teams and Slack. The connection between individuals can be through video calls, normal voice calls, or chats.

Mattermost gains popularity over other messaging platforms due to the following key features:

  • Supports third Party Integrations
  • Drag & Drop features
  • IT Service desk
  • Offers file Sharing
  • Alerts/Notifications
  • Incident resolution – resolves incidents quicky and thus saving on time.
  • Data Import and Export
  • Supports document Storage
  • Application and network performance monitoring.
  • Workflow management and orchestration.

To install and configure Mattermost on a Kubernetes Cluster, follow the steps below:

Setup Requirements.

Ensure that you have a Kubernetes cluster set up. However, you can achieve this using the dedicated guides below:

You also need to have kubectl installed.

curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin

To be able to use Kubectl, you should be able to access the cluster using the generated certificate.

# For k0s
export KUBECONFIG=/var/lib/k0s/pki/admin.conf

With the requirements met, proceed as below.

1 – Create the Mattermost Namespace

We will first create the Mattemost namespace where our installation will happen. This namespace will contain several virtual clusters.

Create the namespace.

kubectl create namespace mattermost

Verify if the namespace has been created:

$ kubectl get namespaces
NAME              STATUS   AGE
default           Active   97s
kube-node-lease   Active   97s
kube-public       Active   97s
kube-system       Active   97s
mattermost        Active   45s

2 – Create the Secrets File

The secret file contains database details for the Mattermost database.

Begin by generating base64 credentials as below.

# MySQL root user
$ echo -n 'root' | base64
cm9vdA==

# MySQL root user password
$ echo -n 'StrongRootPassword' | base64
U3Ryb25nUm9vdFBhc3N3b3Jk

#Mattermost MySQL database name
$ echo -n 'mattermost' | base64
bWF0dGVybW9zdA==

# Mattermost MySQL user
$ echo -n 'mattermost' | base64
bWF0dGVybW9zdA==

# Mattermost MySQL user Password
$ echo -n 'StrongUserPassword'|base64
U3Ryb25nVXNlclBhc3N3b3Jk

Now create the secrets file

vim secrets.yaml

Add the lines below replacing appropriately

apiVersion: v1
kind: Secret
metadata:
  name: mattermost.env
  namespace: mattermost
type: Opaque
data:
  ROOT: cm9vdA==
  ROOT_PASSWORD: U3Ryb25nUm9vdFBhc3N3b3Jk
  DATABASE: bWF0dGVybW9zdA==
  USER: bWF0dGVybW9zdA==
  PASSWORD: U3Ryb25nVXNlclBhc3N3b3Jk

Apply the config file.

kubectl apply -f secrets.yaml

Verify if the config has been applied.

$ kubectl get secret -n mattermost
NAME                  TYPE                                  DATA   AGE
default-token-xlwqr   kubernetes.io/service-account-token   3      84s
mattermost.env        Opaque                                5      5s

3 – Create the Mattermost Database Pod.

For this guide, we will use the MariaDB database. Create a volume for MariaDB

sudo mkdir /var/mattermost

Create a YAML file for the database

vim database.yaml

Add the below content to the file.

---
apiVersion: v1
kind: Service
metadata:
  name: mariadb
  namespace: mattermost
spec:
  selector:
    app: mariadb
  ports:
  - name: mariadb
    protocol: TCP
    port: 3306
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mariadb
  namespace: mattermost
  labels:
    app: mariadb
spec:
  selector:
    matchLabels:
      app: mariadb
  template:
    metadata:
      labels:
        app: mariadb
    spec:
      containers:
      - name: mariadb
        image: mariadb:10.8
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mattermost.env
              key: ROOT_PASSWORD
        - name: MYSQL_DATABASE
          valueFrom:
            secretKeyRef:
              name: mattermost.env
              key: DATABASE
        - name: MYSQL_USER
          valueFrom:
            secretKeyRef:
              name: mattermost.env
              key: USER
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mattermost.env
              key: PASSWORD
        ports:
        - containerPort: 3306
          name: mariadb
        volumeMounts:
        - name: mariadb-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mariadb-storage
        hostPath:
          path: /var/mattermost
          type: Directory

Apply the configuration.

kubectl apply -f database.yaml

Verify if the pod has been created:

$ kubectl get pod -n mattermost
NAME                       READY   STATUS    RESTARTS   AGE
mariadb-5cdf7f54f4-9d7xb   1/1     Running   0          6m48s

4 – Deploy the Mattermost Service

The Mattermost service will be used to expose our application running on port 8065. There are several ways to deploy a service such as NodePort, ClusterIP, or LoadBalancer

Create the Mattermost service file:

vim service.yaml

Here, we will deploy a LoadBalancer service.

apiVersion: v1
kind: Service
metadata:
  name: "mattermost-service"
  namespace: mattermost
spec:
  type: LoadBalancer
  ports:
    - name: http
      port: 8065
      targetPort: 8065
      protocol: TCP
  selector:
    app: mattermost-app

Apply the config.

kubectl apply -f service.yaml

Verify if the service has been created:

$ kubectl get svc -n mattermost
NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
mariadb              ClusterIP   10.100.76.56   <none>        3306/TCP         7m36s
mattermost-service   LoadBalancer    10.99.90.154   <none>        8065:30095/TCP   5s

5 – Deploy the Mattermost Application.

Now deploy the application. Create the deployment YAML as below

vim mattermost_app.yaml

To the file, add the lines below:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mattermost-app
  labels:
    app: mattermost-app
    tier: app
  namespace: mattermost
spec:
  selector:
    matchLabels:
      app: mattermost-app
  template:
    metadata:
      labels:
        app: mattermost-app
    spec:
      containers:
      - name: mattermost-app
        image: "mattermost/mattermost-team-edition:6.3.2"
        env:
        - name: DB_TYPE
          value: "mariadb"
        - name: DB_HOST
          value: "mariadb"
        - name: DB_PORT_NUMBER
          value: "3306"
        - name: MM_USERNAME
          valueFrom:
            secretKeyRef:
              name: mattermost.env
              key: USER
        - name: MM_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mattermost.env
              key: PASSWORD
        - name: MM_DBNAME
          valueFrom:
            secretKeyRef:
              name: mattermost.env
              key: DATABASE
        - name: MM_SQLSETTINGS_DATASOURCE 
          value: "mattermost:StrongUserPassword@tcp(mariadb:3306)/mattermost?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"
        - name: MM_SQLSETTINGS_DRIVERNAME
          value: "mysql"
        ports:
        - containerPort: 8065
          name: http
        volumeMounts:
        # optional persistent storage
        #- name: appdata
          #mountPath: /mattermost/data
        - name: etclocaltime
          mountPath: /etc/localtime
          readOnly: true
      volumes:
      # optional persistent storage
      #- name: appdata
        #persistentVolumeClaim:
        #  claimName: mattermost-app
      - name: etclocaltime
        hostPath:
          path: /etc/localtime

Deploy the application:

kubectl apply -f mattermost_app.yaml

View if the deployment is successful.

$ kubectl get deploy -n mattermost
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
mariadb          1/1     1            1           12m
mattermost-app   1/1     1            1           27s

Get pods in the Mattermost namespace.

$ kubectl get pods -nmattermost
NAME                              READY   STATUS    RESTARTS   AGE
mariadb-5cdf7f54f4-9d7xb          1/1     Running   0          13m
mattermost-app-795578f4bc-5862k   1/1     Running   0          83s

Obtain the poet on which the Mattermost application has been exposed.

$ kubectl get svc -n mattermost
NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
mariadb              ClusterIP   10.100.76.56   <none>        3306/TCP         14m
mattermost-service   LoadBalancer    10.99.90.154   <none>        8065:30095/TCP   6m46s

6 – Access the Mattermost Web Interface

Now the Web UI should be accessible on port 30095. If you have a firewall enabled, allow the port through it.

##For Firewalld
sudo firewall-cmd --add-service=30095/tcp --permanent
sudo firewall-cmd --reload

##For UFW
sudo ufw allow 30095

Now access the Mattermost Web Interface on your browser using the URL http://IP_Address:30095 or http://domain-name:30095

How To Install and Configure Mattermost on a Kubernetes Cluster

Create the Mattermost account and proceed to log in.

How To Install and Configure Mattermost on a Kubernetes Cluster 1

Now you are set to manage your Mattermost installation. There are two options, create a team or proceed to the System console where you make admin changes to your server. The system console appears as below.

How To Install and Configure Mattermost on a Kubernetes Cluster 2

To create a team and begin communication, proceed as below.

How To Install and Configure Mattermost on a Kubernetes Cluster 3

Set the Team URL:

How To Install and Configure Mattermost on a Kubernetes Cluster 4

Finish up the Team creation by providing the required details.

How To Install and Configure Mattermost on a Kubernetes Cluster 5

Once created, you will have the team ready for communication as shown.

How To Install and Configure Mattermost on a Kubernetes Cluster 6

Books For Learning Kubernetes Administration:

Conclusion.

That was enough learning!

We have successfully walked through how to install and configure Mattermost on a Kubernetes Cluster. I hope this was impactful.

See more:

RELATED ARTICLES

Most Popular

Recent Comments