ASK-102-Ghost

本案例使用:ghost.wuushu.cn

  1. 将ghost.wuushu.cn域名解析到上篇提到的CNAME:alb-***.cn-hongkong.alb.aliyuncs.com
  2. 进入集群,点击【命名空间与配额】【创建】,创建namespace为ghost的ns空间。
  3. 点击【存储】下【存储卷】【创建】
  4. 存储卷类型:NAS
    名称:pv-mntnas-ghost
    创建存储卷选中Flexvolume
    总量:100Gi
    访问模式:ReadWriteMany
    挂载点域名:选择挂载点,选择之前创建的NAS:***.cn-hongkong.extreme.nas.aliyuncs.com
  5. 点击【存储】下【存储声明】,命名空间切换为【ghost】,点击【创建】
  6. 存储卷类型:NAS
    名称:pvc-mntnas-ghost
    分配模式:已有存储卷
    已有存储卷选择刚创建的pv-mntnas-ghost
    总量:100Gi
    点击【创建】
    回到宝塔ECS,创建owner为root的文件夹ghostcontent:/mntNAS/base/ghostcontent
  7. 点击【工作负载】下【无状态】,命名空间切换为【ghost】,点击【使用镜像创建】
  8. 应用名称:ghost-prod
    副本数量:1
    类型:无状态
    点击【下一步】
  9. 镜像名称:ghost
    镜像标签:5.2.3-alpine
    所需资源:1核2GB
    端口新增:名称ghost,容器端口2368,协议TCP(镜像自带EXPOSE 2368,这个也可不加)
    环境变量:点【从镜像元数据中获取】会出现三个键值:NODE_ENV,GHOST_INSTALL和GHOST_CONTENT,点击【新增】,自定义类型,变量名称url,变量/变量引用:http://ghost.wuushu.cn
  10. 下方【数据卷】,增加NAS
    名称:contentNAS
    地址:***.cn-hongkong.extreme.nas.aliyuncs.com
    主机路径:/base/ghostcontent
    容器路径:/var/lib/ghost/content
    点【下一步】
  11. 创建【服务】ghost-prod-svc
    虚拟集群ip
    端口名称svcghostport
    服务端口80
    容器端口2368
    协议TCP
    保存
  12. 点击【网络】下【路由】点击【创建ALB Ingress】
    名称:ghost-prod-albingress
    域名:ghost.wuushu.cn
    路径:/*
    服务名称选择ghost-prod-svc
    端口80,勾选开启TLS
  13. 因为阿里云有证书自动发现功能,所以不用配置ssl,勾选TLS即可
  14. 记得加上自定义注解:alb.ingress.kubernetes.io/ssl-redirect 为 true
  15. 保存创建

访问https://域名/ghost,配置管理员,登录后台。

回到宝塔,可以看到/mntNAS/base下ghostcontent目录的owner被自动修改为www

在Ghost后台的settings下Code injection

修改Site Header:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/themes/prism-tomorrow.min.css" integrity="sha512-vswe+cgvic/XBoF1OcM/TeJ2FW0OofqAVdCZiEYkd6dwGXthvkSFWOoGGJgS2CW70VK5dQM5Oh+7ne47s74VTg==" crossorigin="anonymous" referrerpolicy="no-referrer" /> 

修改Site Footer:

<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/components/prism-core.min.js" integrity="sha512-9khQRAUBYEJDCDVP2yw3LRUQvjJ0Pjx0EShmaQjcHa6AXiOv6qHQu9lCAIR8O+/D8FtaCoJ2c0Tf9Xo7hYH01Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/plugins/autoloader/prism-autoloader.min.js" integrity="sha512-fTl/qcO1VgvKtOMApX2PdZzkziyr2stM65GYPLGuYMnuMm1z2JLJG6XVU7C/mR+E7xBUqCivykuhlzfqxXBXbg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

保存,如不成功就多保存几次。

这样编写post的时候,可以输入如:```shell回车,```yaml回车,```php回车等

注:因为除了ALB负载均衡用了TLS,自动监听并转发https请求,所以集群内部都是http 80起作用,所以环境需要设置url为http://ghost.wuushu.cn,否则会多次重定向报错,目前的配置唯一问题就是后台的view site和design里面不能预览网站,因为启动的时候设置url是http,这个目前还没想到办法解决,其他功能正常。(已解决,见上一篇文章,需要创建albconfig后,在yaml里面修改443下的XForwarded的几个为true,然后再新创建alb ingress,这样环境就可以配置成https,且后台全部页面正常显示了!)

至此集群Ghost博客系统就创建好了,可自由伸缩。

​我们进入下一个笔记,建立一个Wikijs维基词条系统,使用数据库Postgresql。​

===========================

后记:用YAML快速部署~

提前安装好albingress 和class
Ghost/SQLite由四部分组成:

  • 有状态StatefulSet
  • 服务Service
  • 路由Albingress
  • 域名指向alb的cname

Ghost StatefulSet YAML:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: prod-ghost
  name: prod-ghost
  namespace: prod-ghost
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prod-ghost
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: prod-ghost
    spec:
      containers:
        - env:
            - name: NODE_ENV
              value: production
            - name: GHOST_INSTALL
              value: /var/lib/ghost
            - name: GHOST_CONTENT
              value: /var/lib/ghost/content
            - name: url
              value: 'https://yourdomain'
          image: 'ghost:5.3.1-alpine'
          imagePullPolicy: IfNotPresent
          name: prod-ghost
          ports:
            - containerPort: 2368
              name: ghostport
              protocol: TCP
          resources:
            requests:
              cpu: 500m
              memory: 1Gi
          volumeMounts:
            - mountPath: /var/lib/ghost/content
              name: volume-ghostcontent
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      volumes:
        - name: volume-ghostcontent
          nfs:
            path: /base/ghostcontent
            server: ***.extreme.nas.aliyuncs.com

Ghost Service YAML:

apiVersion: v1
kind: Service
metadata:
  name: prod-svc-ghost
  namespace: prod-ghost
spec:
  internalTrafficPolicy: Cluster
  ports:
    - name: prod-svc-ghost-port
      port: 80
      protocol: TCP
      targetPort: 2368
  selector:
    app: prod-ghost
  type: ClusterIP

如果没有创建AlbConfig,先创建(看上一篇文章)

Ghost ALB Ingress YAML:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: alb
  finalizers:
    - ingress.k8s.alibaba/resources
  generation: 1
  name: prod-albingress-ghost
  namespace: prod-ghost
spec:
  rules:
    - host: ***.***.***域名(不加https://或http://)
      http:
        paths:
          - backend:
              service:
                name: prod-svc-ghost
                port:
                  number: 80
            path: /*
            pathType: ImplementationSpecific

开启TLS,因为阿里云有证书自动发现功能,所以不用配置ssl,勾选TLS即可
记得加上自定义注解:
alb.ingress.kubernetes.io/ssl-redirect 为 true

alb.ingress.kubernetes.io/backend-protocol: "HTTPS"

访问域名https,全部前后端页面都能正常访问,没有重定向错误,oye~

后后记:

用PVC代替直连PV

PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mntnas-ghost
  namespace: prod-ghost
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  selector:
    matchLabels:
      alicloud-pvname: prod-ghost-pvc-mntnas-ghost
  storageClassName: nas
  volumeMode: Filesystem
  volumeName: prod-ghost-pvc-mntnas-ghost
status:
  accessModes:
    - ReadWriteMany
  capacity:
    storage: 1Gi
  phase: Bound

PV:

apiVersion: v1
kind: PersistentVolume
metadata:
  annotations:
  labels:
    alicloud-pvname: prod-ghost-pvc-mntnas-ghost
  name: prod-ghost-pvc-mntnas-ghost
spec:
  accessModes:
    - ReadWriteMany
  capacity:
    storage: 1Gi
  claimRef:
    apiVersion: v1
    kind: PersistentVolumeClaim
    name: mntnas-ghost
    namespace: prod-ghost
  flexVolume:
    driver: alicloud/nas
    options:
      modeType: non-recursive
      path: /base/prod-ghost我的路径
      server: ***.nas.aliyuncs.com
      vers: '3'
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nas
  volumeMode: Filesystem
status:
  phase: Bound

然后编辑ghost相关部署,更新。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值