create hostmount path and grant access
root@ecs-lab ~/wikijs# ansible all -m shell -a "mkdir /mnt/data/wikijs -p && chmod 777 /mnt/data/wikijs -R"
192.168.0.21 | CHANGED | rc=0 >>
192.168.0.22 | CHANGED | rc=0 >>
192.168.0.23 | CHANGED | rc=0 >>
resources yaml
root@ecs-lab ~/wikijs# cat ns.yml
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: null
name: wikijs
spec: {}
status: {}
root@ecs-lab ~/wikijs# cat pv-pvc.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: wikijs-pv
namespace: wikijs
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /mnt/data/wikijs
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wikijs-pvc
namespace: wikijs
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-pv
namespace: wikijs
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /mnt/data/postgres
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pvc
namespace: wikijs
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
root@ecs-lab ~/wikijs# cat db.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: wikijs
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:13
env:
- name: POSTGRES_USER
value: "wikijs"
- name: POSTGRES_PASSWORD
value: "yourpassword"
- name: POSTGRES_DB
value: "wikijs"
ports:
- containerPort: 5432
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgres-storage
volumes:
- name: postgres-storage
persistentVolumeClaim:
claimName: postgres-pvc
root@ecs-lab ~/wikijs# cat deploy.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: wikijs
namespace: wikijs
spec:
replicas: 1
selector:
matchLabels:
app: wikijs
template:
metadata:
labels:
app: wikijs
spec:
containers:
- name: wikijs
image: requarks/wiki:latest
env:
- name: DB_TYPE
value: "postgres"
- name: DB_HOST
value: "postgres.wikijs.svc.cluster.local"
- name: DB_PORT
value: "5432"
- name: DB_USER
value: "wikijs"
- name: DB_PASS
value: "yourpassword"
- name: DB_NAME
value: "wikijs"
ports:
- containerPort: 3000
volumeMounts:
- mountPath: /wiki/data
name: wikijs-storage
volumes:
- name: wikijs-storage
persistentVolumeClaim:
claimName: wikijs-pvc
root@ecs-lab ~/wikijs# cat svc.yml
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: wikijs
spec:
type: NodePort
ports:
- port: 5432
nodePort: 30001
selector:
app: postgres
---
apiVersion: v1
kind: Service
metadata:
name: wikijs
namespace: wikijs
spec:
type: NodePort
ports:
- port: 3000
nodePort: 30002
selector:
app: wikijs
Deploy to cluster
root@ecs-lab ~/wikijs# ll
total 20
-rw-r--r-- 1 root root 791 Oct 15 20:30 db.yml
-rw-r--r-- 1 root root 953 Oct 15 20:31 deploy.yml
-rw-r--r-- 1 root root 102 Oct 15 22:33 ns.yml
-rw-r--r-- 1 root root 771 Oct 15 20:30 pv-pvc.yml
-rw-r--r-- 1 root root 355 Oct 15 20:31 svc.yml
root@ecs-lab ~/wikijs# kubectl create -f ./
root@ecs-lab ~/wikijs# kubectl get all -n wikijs
NAME READY STATUS RESTARTS AGE
pod/postgres-64ff79757c-zd2tm 1/1 Running 0 31m
pod/wikijs-7bb597c9b4-6j844 1/1 Running 0 31m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/postgres NodePort 10.68.100.127 <none> 5432:30001/TCP 129m
service/wikijs NodePort 10.68.255.23 <none> 3000:30002/TCP 129m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/postgres 1/1 1 1 129m
deployment.apps/wikijs 1/1 1 1 129m
NAME DESIRED CURRENT READY AGE
replicaset.apps/postgres-64ff79757c 1 1 1 129m
replicaset.apps/wikijs-7bb597c9b4 1 1 1 129m
root@ecs-lab ~/wikijs# tcping node1.k8s.io 30001
node1.k8s.io port 30001 open.
root@ecs-lab ~/wikijs# tcping node1.k8s.io 30002
node1.k8s.io port 30002 open.
Proxy to WAF