书山有路勤为径,学海无涯苦作舟。 知识改变命运,行动创造未来。

Mattermost安装[K8S]

Chart源码:https://github.com/mattermost/mattermost-helm/tree/master/charts/mattermost-team-edition

Helm 部署

添加helm源

# helm repo add mattermost https://helm.mattermost.com
"mattermost" has been added to your repositories
# helm repo list
NAME      	URL
stable    	http://mirror.azure.cn/kubernetes/charts/
gitlab    	https://charts.gitlab.io
mattermost	https://helm.mattermost.com
# helm search repo -l mattermost/mattermost-team-edition
NAME                              	CHART VERSION	APP VERSION	DESCRIPTION
mattermost/mattermost-team-edition	3.10.0       	5.13.2     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.9.1        	5.13.2     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.9.0        	5.13.2     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.8.3        	5.13.2     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.8.2        	5.13.2     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.8.1        	5.13.2     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.8.0        	5.13.2     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.7.0        	5.13.2     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.6.2        	5.13.2     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.6.0        	5.13.0     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.5.1        	5.12.4     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.4.1        	5.11.0     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.4.0        	5.11.0     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.3.0        	5.10.0     	Mattermost Team Edition server.
mattermost/mattermost-team-edition	3.2.0        	5.10.0     	Mattermost Team Edition server.

下载源码进行自定义

# helm fetch mattermost/mattermost-team-edition --version=3.10.0

创建namespace

kubectl create ns mattermost

创建两个PV存储数据

新建mattermost-data用于存储数据,mattermost-plugins用户存储插件。

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mattermost-data
  namespace: mattermost
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/devops/mattermost/data"
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mattermost-plugins
  namespace: mattermost
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/devops/mattermost/plugins"
[root@zeyang-nuc-service mattermost-team-edition]# kubectl create -f pv.yaml
persistentvolume/mattermost-data created
persistentvolume/mattermost-plugins created
[root@zeyang-nuc-service mattermost-team-edition]# kubectl get pv -n mattermost
NAME                 CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM                              STORAGECLASS   REASON   AGE
mattermost-data      10Gi       RWO            Retain           Available                                      manual                  9s
mattermost-plugins   1Gi        RWO            Retain           Available                                      manual                  9s

创建数据库

准备一个PG数据库,然后添加账号。

postgres=# CREATE DATABASE mattermost;
CREATE DATABASE
postgres=# CREATE USER mmuser WITH PASSWORD 'mmuser-password';
CREATE ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE mattermost to mmuser;
GRANT
postgres=# \q
could not save history to file "/var/lib/pgsql/.psql_history": No such file or directory
[postgres@zeyang-nuc-service ~]$ exit
logout

自定义value.yml

添加PV设置

##
persistence:
  ## This volume persists generated data from users, like images, attachments...
  ##
  data:
    enabled: true
    size: 10Gi
    ## If defined, volume.beta.kubernetes.io/storage-class: <storageClass>
    ## Default: volume.alpha.kubernetes.io/storage-class: default
    ##
    storageClass: manual
    accessMode: ReadWriteOnce
  # existingClaim: ""
  plugins:
    enabled: true
    size: 1Gi
    ## If defined, volume.beta.kubernetes.io/storage-class: <storageClass>
    ## Default: volume.alpha.kubernetes.io/storage-class: default
    ##
    storageClass: manual
    accessMode: ReadWriteOnce
  # existingClaim: ""

配置Ingress

ingress:
  enabled: true
  path: /
  annotations: 
    kubernetes.io/ingress.class: nginx
    #### To use the nginx cache you will need to set an http-snippet in the ingress-nginx configmap
    #### http-snippet: |
    ####     proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off;
  hosts:
    - mm.idevops.site
  tls:
    # - secretName: mattermost.example.com-tls
    #   hosts:
    #     - mattermost.example.com

连接外部数据库

mysql示例:

## If use this please disable the mysql chart by setting mysql.enable to false
externalDB:
  enabled: true

  ## postgres or mysql
  externalDriverType: "mysql"

  ## postgres:  "postgres://<USERNAME>:<PASSWORD>@<HOST>:5432/<DATABASE_NAME>?sslmode=disable&connect_timeout=10"
  ## mysql:     "<USERNAME>:<PASSWORD>@tcp(<HOST>:3306)/<DATABASE_NAME>?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"
  externalConnectionString: "xxxx:xxxxx@tcp(xxxx:3306)/mattermost?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s"

postgres示例:(这是我们使用的)

## If use this please disable the mysql chart by setting mysql.enable to false
externalDB:
  enabled: true

  ## postgres or mysql
  externalDriverType: "postgres"

  ## postgres:  "postgres://<USERNAME>:<PASSWORD>@<HOST>:5432/<DATABASE_NAME>?sslmode=disable&connect_timeout=10"
  ## mysql:     "<USERNAME>:<PASSWORD>@tcp(<HOST>:3306)/<DATABASE_NAME>?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s"
  externalConnectionString: "postgres://mmuser:mmuser-password@192.168.1.200:5432/mattermost?sslmode=disable&connect_timeout=10"

验证数据库可以正常访问

psql -h 192.168.1.200 -p 5432 -d mattermost  -U mmuser

部署

helm install mattermost-server --namespace mattermost ./mattermost-team-edition
helm delete mattermost-server --namespace mattermost ./mattermost-team-edition

FAQ

err=pq: no pg_hba.conf entry for host \"10.244.0.148\", user \"mmuser\", database \"mattermost\", SSL off"}

修改pg_hba.conf、 postgres.conf

## pg_hba.conf

host   all             all            192.168.1.0/24              md5
host   all             all            10.244.0.1/24              md5


##  postgres.conf
listen_addresses = '*'

网页配置

访问: http://mm.idevops.site.

创建用户: 输入邮箱、用户名称、密码。 admin:Devops.com123

iamges

创建一个新的团队,输入团队名称。

images

创建完成

images

设置中文

images

write file: open /mattermost/config/config.json: read-only file system"}

解决配置文件无法写入问题:

创建一个pv持久化/mattermost/config目录

mkdir -p /data/devops/mattermost/config
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mattermost-config
  namespace: mattermost
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/devops/mattermost/config"
---
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mattermost-config-pvc
  namespace: mattermost
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

修改templates/deployment.yaml

#挂载pvc
volumeMounts:
- mountPath: /mattermost/config/config.json
  name: config-json
  subPath: config.json

- mountPath: /mattermost/config
  name: mattermost-config


--------------------------------------------
volumes:
- name: config-json
  secret:
    secretName: {{ include "mattermost-team-edition.fullname" . }}-config-json

- name: mattermost-config
  persistentVolumeClaim:
    claimName: {{ .Values.persistence.config.existingClaimName }}
    
    
--------------------------------------------
#删除 24行配置
checksum/config: {{ include (print $.Template.BasePath "/secret-config.yaml") . | sha256sum }}


--------------------------------------------
#删除 templates/secret-config.yaml

--------------------------------------------
# 在values.yaml中定义config pvc的名称(注意名称要与创建的一致)
persistence:
  ## This volume persists generated data from users, like images, attachments...
  ##
  config:
    existingClaimName: mattermost-config-pvc
helm delete  mattermost-server --namespace mattermost ./mattermost-team-edition
kubectl delete -f ./mattermost-team-edition/config-pvc.yaml
kubectl delete -f ./mattermost-team-edition/pv.yaml
kubectl create -f ./mattermost-team-edition/config-pvc.yaml
kubectl create -f ./mattermost-team-edition/pv.yaml
helm install  mattermost-server --namespace mattermost ./mattermost-team-edition

参考资料

https://hub.docker.com/r/mattermost/mattermost-team-edition/tags

https://github.com/mattermost/mattermost-server/blob/master/build/Dockerfile

https://github.com/mattermost/mattermost-helm/issues/100

https://github.com/mattermost/mattermost-helm/tree/master/charts/mattermost-team-edition