How to Deploy Ghost on Kubernetes

This guide explains how to deploy the Ghost blogging platform on Kubernetes using Traefik as the ingress controller and TrueNAS for persistent storage. The setup ensures scalability and resilience while keeping the data secure and manageable.
Prerequisites
- Kubernetes Cluster: A running Kubernetes cluster with
kubectl
configured. - Traefik: Installed and configured as the ingress controller.
- TrueNAS: Accessible and configured to provide NFS or other shared storage.
- Persistent Storage Setup: Ensure your storage path on TrueNAS is mounted correctly (e.g.,
/mnt/nas-pool/mysql
). - Domain and TLS: A domain name pointing to your Kubernetes cluster and a valid TLS certificate (e.g., via Let's Encrypt).
Step 1: Create Persistent Volumes Claims
MySQL Persistent Volume Claim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
spec:
storageClassName: nfs-ghost
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 12Gi
Step 2: Deploy MySQL
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
namespace: ghost
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:8
env:
- name: MYSQL_ROOT_PASSWORD
value: rootpassword
- name: MYSQL_DATABASE
value: ghost
- name: MYSQL_USER
value: user
- name: MYSQL_PASSWORD
value: password
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-storage
persistentVolumeClaim:
claimName: mysql-pvc
---
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: ghost
spec:
selector:
app: mysql
ports:
- port: 3306
targetPort: 3306
Step 3: Deploy Ghost
apiVersion: apps/v1
kind: Deployment
metadata:
name: ghost
namespace: ghost
spec:
replicas: 1
selector:
matchLabels:
app: ghost
template:
metadata:
labels:
app: ghost
spec:
containers:
- name: ghost
image: ghost:latest
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "200m"
env:
- name: url
value: https://your-domain
- name: database__client
value: mysql
- name: database__connection__host
value: mysql
- name: database__connection__user
value: ghostuser
- name: database__connection__password
value: ghostpassword
- name: database__connection__database
value: ghost
ports:
- containerPort: 2368
---
apiVersion: v1
kind: Service
metadata:
name: ghost
namespace: ghost
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 2368
selector:
app: ghost
Step 4: Configure Ingress with Traefik
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ghost-ingress
namespace: ghost
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/router.entrypoints: websecure
spec:
tls:
- hosts:
- your-domain
secretName: ghost-tls-secret # Ensure your TLS secret is correctly configured
rules:
- host: your-domain
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: ghost
port:
number: 80
Step 5: Verify the Setup
- Visit your domain (e.g., https://your-domain to access the Ghost platform.
Check the status of the pods and services:
kubectl get pods
kubectl get svc
kubectl get ingress
Deploy the YAML manifests:
kubectl apply -f mysql-pv.yaml
kubectl apply -f mysql-deployment.yaml
kubectl apply -f ghost-deployment.yaml
kubectl apply -f ghost-ingress.yaml
以上資料由ChatGPT整理完成。