How to Deploy Ghost on Kubernetes

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

  1. Kubernetes Cluster: A running Kubernetes cluster with kubectl configured.
  2. Traefik: Installed and configured as the ingress controller.
  3. TrueNAS: Accessible and configured to provide NFS or other shared storage.
  4. Persistent Storage Setup: Ensure your storage path on TrueNAS is mounted correctly (e.g., /mnt/nas-pool/mysql).
  5. 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

  1. 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整理完成。

Read more

如何安裝 KubeSphere 以及管理 Workspace 和新增 Label

前言 在 Kubernetes 的世界中,KubeSphere 是一個功能強大的開源容器平台,它不僅讓 Kubernetes 的管理更簡單,還集成了多集群管理、DevOps、微服務治理等功能。本篇文章將教您如何使用 Helm 快速安裝 KubeSphere,並如何通過管理 Workspace 和新增 Label 來實現資源的高效管理。 一、使用 Helm 安裝 KubeSphere 1. 為什麼選擇 Helm 安裝? Helm 是 Kubernetes 中廣泛使用的包管理工具,使用 Helm 安裝 KubeSphere 有以下優點: * 自動化:簡化安裝過程,減少手動配置。 * 靈活性:可以根據需求自定義安裝的模組。 * 版本控制:支持管理和回滾安裝的不同版本。 2. 安裝前準備 在開始安裝之前,請確保以下條件:

By Tim Chiagn

我的經驗

1. 網絡與安全 (Networking & Security) * Fortigate: 防火牆來管理網路環境 * Traefik: 用於 K8s 的 2. 虛擬化與存儲 (Virtualization & Storage) * Esxi: 買了一台server 使用 Esxi 管理 vm * TrueNAS: 還沒有買 NAS 使用這個加減用一下 3. DevOps 與持續交付 (DevOps & CI/CD) * ArgoCD: GitOps 工具,用於 Kubernetes 的應用交付和管理,支持自動化部署和同步。 * KubeSphere:提供完整的 CI/CD 工作流管理、應用部署和 DevOps 整合功能,是 Kubernetes

By Tim Chiagn