--- # 创建 Namespace apiVersion: v1 kind: Namespace metadata: name: hty1024-app --- # 创建 StorageClass apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: storage-local-xbrowsersync labels: app.k8s.hty1024.com/env: prod app.k8s.hty1024.com/type: app app.k8s.hty1024.com/name: xbrowsersync app.k8s.hty1024.com/version: 1.1.13 app.k8s.hty1024.com/resources: storageClass provisioner: kubernetes.io/no-provisioner reclaimPolicy: Retain volumeBindingMode: WaitForFirstConsumer --- # 创建 PersistentVolume apiVersion: v1 kind: PersistentVolume metadata: name: hty1024-app-xbrowsersync-pv labels: app.k8s.hty1024.com/env: prod app.k8s.hty1024.com/type: app app.k8s.hty1024.com/name: xbrowsersync app.k8s.hty1024.com/version: 1.1.13 app.k8s.hty1024.com/resources: persistentVolume spec: capacity: storage: 20Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Retain storageClassName: storage-local-xbrowsersync local: path: /app/xbrowsersync/data/ nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: node.k8s.hty1024.com/type operator: In values: - app --- # 创建 PersistentVolumeClaim apiVersion: v1 kind: PersistentVolumeClaim metadata: name: hty1024-app-xbrowsersync-pvc namespace: hty1024-app labels: app.k8s.hty1024.com/env: prod app.k8s.hty1024.com/type: app app.k8s.hty1024.com/name: xbrowsersync app.k8s.hty1024.com/version: 1.1.13 app.k8s.hty1024.com/resources: persistentVolumeClaim spec: resources: requests: storage: 20Gi volumeMode: Filesystem accessModes: - ReadWriteOnce storageClassName: storage-local-xbrowsersync --- # 创建 ConfigMap(自定义 mongoconfig.js 文件) apiVersion: v1 kind: ConfigMap metadata: name: hty1024-app-xbrowsersync-mongoconfig namespace: hty1024-app labels: app.k8s.hty1024.com/env: prod app.k8s.hty1024.com/type: app app.k8s.hty1024.com/name: xbrowsersync app.k8s.hty1024.com/version: 1.1.13 app.k8s.hty1024.com/resources: configMap data: mongoconfig.js: | db.newsynclogs.createIndex( { "expiresAt": 1 }, { expireAfterSeconds: 0 } ); db.newsynclogs.createIndex( { "ipAddress": 1 } ); db.bookmarks.createIndex( { "lastAccessed": 1 }, { expireAfterSeconds: 21*86400 } ); --- # 创建 ConfigMap(自定义 settings.json 文件) apiVersion: v1 kind: ConfigMap metadata: name: hty1024-app-xbrowsersync-settings namespace: hty1024-app labels: app.k8s.hty1024.com/env: prod app.k8s.hty1024.com/type: app app.k8s.hty1024.com/name: xbrowsersync app.k8s.hty1024.com/version: 1.1.13 app.k8s.hty1024.com/resources: configMap data: settings.json: | { "location": "CN", "maxSyncs": "10000", "maxSyncSize": "10485760", "db": { "host": "127.0.0.1", "port": "27017", "name": "xbrowsersync", "username": "xbrowsersync", "password": "123456" }, "status": { "allowNewSyncs": "true", "online": "true", "message": "Welcome to the HTY1024 xBrowserSync service! We run the latest version of the xBrowserSync API and take database backups daily." } } --- # 创建 ConfigMap(自定义 healthcheck.js 文件) apiVersion: v1 kind: ConfigMap metadata: name: hty1024-app-xbrowsersync-healthcheck namespace: hty1024-app labels: app.k8s.hty1024.com/env: prod app.k8s.hty1024.com/type: app app.k8s.hty1024.com/name: xbrowsersync app.k8s.hty1024.com/version: 1.1.13 app.k8s.hty1024.com/resources: configMap data: healthcheck.js: | const http = require('http'); const response = http.request( { host: '0.0.0.0', method: 'GET', path: '/info', port: 8080, timeout: 2000, }, (res) => { let body = ''; res.setEncoding('utf8'); res.on('data', (chunk) => { body += chunk; }); res.on('end', () => { if (res.statusCode === 200) { const payload = JSON.parse(body); switch (payload.status) { case 1: case 3: console.log('HEALTHCHECK: online'); process.exit(0); case 2: default: console.log('HEALTHCHECK: offline'); } } else { console.log('HEALTHCHECK: offline'); } process.exit(1); }); } ); response.on('error', function (err) { console.log('HEALTHCHECK: offline'); process.exit(1); }); response.end(); --- # 创建 Service apiVersion: v1 kind: Service metadata: name: hty1024-app-xbrowsersync-service namespace: hty1024-app labels: app.k8s.hty1024.com/env: prod app.k8s.hty1024.com/type: app app.k8s.hty1024.com/name: xbrowsersync app.k8s.hty1024.com/version: 1.1.13 app.k8s.hty1024.com/resources: service spec: type: NodePort ports: - port: 8080 targetPort: 8080 nodePort: 30000 selector: app.k8s.hty1024.com/env: prod app.k8s.hty1024.com/type: app app.k8s.hty1024.com/name: xbrowsersync app.k8s.hty1024.com/version: 1.1.13 app.k8s.hty1024.com/resources: pod --- # 创建 StatefulSet apiVersion: apps/v1 kind: StatefulSet metadata: name: hty1024-app-xbrowsersync-statefulset namespace: hty1024-app labels: app.k8s.hty1024.com/env: prod app.k8s.hty1024.com/type: app app.k8s.hty1024.com/name: xbrowsersync app.k8s.hty1024.com/version: 1.1.13 app.k8s.hty1024.com/resources: statefulSet spec: replicas: 1 minReadySeconds: 30 selector: matchLabels: app.k8s.hty1024.com/env: prod app.k8s.hty1024.com/type: app app.k8s.hty1024.com/name: xbrowsersync app.k8s.hty1024.com/version: 1.1.13 app.k8s.hty1024.com/resources: pod template: metadata: labels: app.k8s.hty1024.com/env: prod app.k8s.hty1024.com/type: app app.k8s.hty1024.com/name: xbrowsersync app.k8s.hty1024.com/version: 1.1.13 app.k8s.hty1024.com/resources: pod spec: terminationGracePeriodSeconds: 60 volumes: - name: localtime hostPath: path: /etc/localtime - name: shanghai hostPath: path: /usr/share/zoneinfo/Asia/Shanghai - name: data persistentVolumeClaim: claimName: hty1024-app-xbrowsersync-pvc - name: mongoconfig configMap: name: hty1024-app-xbrowsersync-mongoconfig items: - key: mongoconfig.js path: mongoconfig.js - name: settings configMap: name: hty1024-app-xbrowsersync-settings items: - key: settings.json path: settings.json - name: healthcheck configMap: name: hty1024-app-xbrowsersync-healthcheck items: - key: healthcheck.js path: healthcheck.js containers: - name: mongo image: mongo:7.0.14 ports: - name: tcp containerPort: 27017 volumeMounts: - name: shanghai mountPath: /etc/localtime readOnly: true - name: data mountPath: /data/db - name: mongoconfig mountPath: /docker-entrypoint-initdb.d/mongoconfig.js env: - name: MONGO_INITDB_DATABASE value: "xbrowsersync" - name: MONGO_INITDB_ROOT_USERNAME value: "xbrowsersync" - name: MONGO_INITDB_ROOT_PASSWORD value: "123456" - name: XBS_DB_NAME value: "xbrowsersync" - name: XBS_DB_USERNAME value: "xbrowsersync" - name: XBS_DB_PASSWORD value: "123456" - name: xbrowsersync image: xbrowsersync/api:1.1.13 ports: - name: tcp containerPort: 8080 # volumeMounts: # - name: shanghai # mountPath: /etc/localtime # readOnly: true # - name: settings # mountPath: /usr/src/api/config/settings.json # - name: healthcheck # mountPath: /usr/src/api/healthcheck.js env: - name: XBROWSERSYNC_DB_USER value: "xbrowsersync" - name: XBROWSERSYNC_DB_PWD value: "123456" nodeSelector: node.k8s.hty1024.com/type: app