Bookstack Install On Kubernetes

tarafından
80
Bookstack Install On Kubernetes

INFO: This work has been tried on one node. This application running kubernetes master node. If you are going to try this on a cluster with multiple nodes, you have to open the mount folders on that worker node. You need to use node selector to determine which node to pod will be created on. I will not telling node selector issue here.

If you want to run bookstack applications on kubernetes cluster you can follow the steps below. If you don’t have a docker user, you must create a docker user and you must add you created docker user in docker group.

Step1:

Create Docker user and add in your docker group.

useradd docker

Then you should add you ctreated user in docker group. We will this user id and group id in yaml file.

useradd -g docker docker

Then check docker user id and save to use in yaml file in steps after.

id docker
List Of Docker User And Group Id

Step2: Create new folder under the worker node, because we are need the persistent volume and persistent volume claim to not lose the data. This on cluster with one worker node. İf you have a more than one worker node you must create folder on every each node or you can use node selector to run on  specific worker node. 

 

mkdir /opt/bookstack /opt/bookstackdb

Step3: Create yaml file for  persistent volume and persistent volume claim for bookstack applicaiton and database.

vim bokstackpv_pvc.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: bookstackpv
  labels:
    type: local
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/opt/bookstack"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: bookstackpvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
kubectl create -f bookstackpv_pvc.yaml
vim bookstackdbpv_pvc.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: bookstackdbpv
  labels:
    type: local
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/opt/bookstackdb"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: bookstackdbpvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
kubectl create -f bookstackdbpv_pvc.yaml

Check your pv and pvc resouces.

kubectl get pv
kubectl get pvc

Step4: Create DB yaml file to using for booktack application.And we will take db pod ip address to usee bookstack application yaml file. This is nor best practice. If we we want to connec the other pod we must create service to connect the other pods. Because some pods may die and a new one may up . In this time pod ip address wil change. So if we use service our ip address will not change because service  is matching the pod label.t

vim bookstackdb.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: bookstackdb
  labels:
    app: bookstackdb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: bookstackdb
  template:
    metadata:
      labels:
        app: bookstackdb
    spec:
      containers:
      - name: bookstackdb
        image: linuxserver/mariadb
        ports:
        - containerPort: 3306
        env:
        - name: PUID
          value: "1001"
        - name: PGID
          value: "986"
        - name: MYSQL_ROOT_PASSWORD
          value: "bookstack"
        - name: MYSQL_DATABASE
          value: "bookstack"
        - name: MYSQL_USER
          value: "bookstack"  
        - name: MYSQL_PASSWORD
          value: "bookstack"
        - name: TZ
          value: "Europe/London"   
        volumeMounts:
        - mountPath: "/config"
          name: bokstackdbvolume
      volumes:
      - name: bokstackdbvolume
        persistentVolumeClaim:
          claimName: bookstackdbpvc
kubectl create -f bookstackdb.yaml

Check your first pods with log output.

kubectl get pods
kubectl logs bookstackdb-5d86557d85-p2gdf
Logs Of Pods

Take the ip address from db pods.

kubectl get pods -o wide 

Step5:Create bookstack application yaml file with database pod ip address.

vim bookstack.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: bookstack
  labels:
    app: bookstack
spec:
  replicas: 1
  selector:
    matchLabels:
      app: bookstack
  template:
    metadata:
      labels:
        app: bookstack
    spec:
      containers:
      - name: bookstack
        image: linuxserver/bookstack
        ports:
        - containerPort: 80
        env:
        - name: PUID
          value: "1001"
        - name: PGID
          value: "986"
        - name: DB_HOST
          value: "10.244.0.86"
        - name: DB_USER
          value: "bookstack"
        - name: DB_PASS
          value: "bookstack"
        - name: DB_DATABASE
          value: "bookstack"
        volumeMounts:
        - mountPath: "/config"
          name: bokstackvolume
      volumes:
      - name: bokstackvolume
        persistentVolumeClaim:
          claimName: bookstackpvc
kubectl create -f bookstack.yaml

Step6:Create service yaml file to access the your application. I used the service is node port. You can change service type for your system.

vim bookstacksvc.yaml
apiVersion: v1
kind: Service
metadata:
  name: bookstack
  labels:
    app: bookstack
spec:
  ports:
  - port: 80
    protocol: TCP
  selector:
    app: bookstack
  type: NodePort
kubectl create -f bookstacksvc.yaml

List your service and check your node port number. Because we will use tihs port number to access the bookstack application.

kubectl get svc

Step7: Connect to the application with your browser.

Default Login email and password;
Email: admin@admin.com
Password: password

Test Connection The Bookstack Applicaiton