Bookstack Install On Kubernetes

tarafından
1022
Bookstack Install On Kubernetes

INFO:This work has been tried on one node and this  application will run on kubernetes master node. If you are going to try this installation on a cluster that has a multiple nodes, you should create the mount folders on your choosen worker node or you can use the storage class(recomended). Also if you choose pv and pvc resources you need to use node selector. I will not give information about node selector here. But, you can find a lot of information about pod assign for node on this link.

Let’s try to this installation.

Step1:

Create Docker user and add in your docker group. Because, we will define id number on yaml file for environment.

useradd docker
useradd -g docker docker

Take your id number of docker users.

id docker
List Of Docker User And Group Id

Step2: Create new folder under the worker node. If 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  pv and pvc.

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 yaml file for database of bookstack.And we will take db pod ip address to use bookstack application yaml file. This is not best practice. If we want to connect the other pod we should create service resources to connect the other pods. Because some pods may die and a new one may up . In this time pod ip address will change. So if we use service, it does not matter even if ip changing because service  is matching the pod label.

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 DB service yaml file to access the database pod.

vim bookstackdb_svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: bookstackdb
  labels:
    app: bookstackdb
spec:
  ports:
  - port: 3306
    protocol: TCP
  selector:
    app: bookstackdb
kubectl create -f bookstackdb_svc.yaml

Step6:Create bookstack application yaml file with database service name.

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: "bookstackdb"
        - 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

Step7: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

Step8: Connect to the application with your browser.

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

Test Connection The Bookstack Applicaiton