如何通过YAML在K8s中部署AppSmith?求生产环境非Helm部署YAML示例
在Kubernetes中通过YAML部署生产环境级别的AppSmith(无需Helm)
前置准备
- 确保你的Kubernetes集群处于健康状态,可用
kubectl cluster-info验证 - 拥有集群管理员权限,用于创建命名空间、存储卷等资源
- 集群已配置持久化存储类(StorageClass),生产环境依赖持久化存储避免数据丢失
部署步骤
1. 创建专属命名空间
先为AppSmith创建独立命名空间,隔离资源:
kubectl create namespace appsmith
2. 部署核心组件(完整YAML示例)
将以下内容保存为appsmith-production.yaml,执行kubectl apply -f appsmith-production.yaml -n appsmith完成部署。该配置包含生产环境所需的MongoDB、Redis、AppSmith主服务及配套资源:
# 1. ConfigMap:存储非敏感配置 apiVersion: v1 kind: ConfigMap metadata: name: appsmith-config data: APPSMITH_MONGODB_URI: "mongodb://appsmith-mongodb:27017/appsmith" APPSMITH_REDIS_URL: "redis://appsmith-redis:6379" APPSMITH_SERVER_URL: "http://your-domain.com" # 替换为实际访问域名/IP APPSMITH_ENV: "production" --- # 2. Secret:存储敏感信息(替换为实际密码,需base64编码) apiVersion: v1 kind: Secret metadata: name: appsmith-secrets type: Opaque data: MONGODB_ROOT_PASSWORD: "bXktc2VjcmV0LXBhc3N3b3Jk" # 生成方式:echo -n "your-password" | base64 APPSMITH_ENCRYPTION_PASSWORD: "bXktZW5jcnlwdGlvbi1wYXNzd29yZA==" # 务必设置强加密密钥 --- # 3. MongoDB StatefulSet及Service(生产环境用StatefulSet保证数据一致性) apiVersion: apps/v1 kind: StatefulSet metadata: name: appsmith-mongodb spec: serviceName: appsmith-mongodb replicas: 1 selector: matchLabels: app: mongodb template: metadata: labels: app: mongodb spec: containers: - name: mongodb image: mongo:4.4 ports: - containerPort: 27017 env: - name: MONGO_INITDB_ROOT_PASSWORD valueFrom: secretKeyRef: name: appsmith-secrets key: MONGODB_ROOT_PASSWORD volumeMounts: - name: mongodb-data mountPath: /data/db resources: requests: cpu: "500m" memory: "1Gi" limits: cpu: "1" memory: "2Gi" livenessProbe: exec: command: ["mongo", "--eval", "db.adminCommand('ping')"] initialDelaySeconds: 30 periodSeconds: 10 readinessProbe: exec: command: ["mongo", "--eval", "db.adminCommand('ping')"] initialDelaySeconds: 5 periodSeconds: 5 volumeClaimTemplates: - metadata: name: mongodb-data spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 10Gi # 若集群有指定存储类,取消注释并替换 # storageClassName: "your-storage-class" --- apiVersion: v1 kind: Service metadata: name: appsmith-mongodb spec: clusterIP: None selector: app: mongodb ports: - port: 27017 targetPort: 27017 --- # 4. Redis Deployment及Service apiVersion: apps/v1 kind: Deployment metadata: name: appsmith-redis spec: replicas: 1 selector: matchLabels: app: redis template: metadata: labels: app: redis spec: containers: - name: redis image: redis:6-alpine ports: - containerPort: 6379 volumeMounts: - name: redis-data mountPath: /data resources: requests: cpu: "200m" memory: "256Mi" limits: cpu: "500m" memory: "512Mi" livenessProbe: tcpSocket: port: 6379 initialDelaySeconds: 10 periodSeconds: 5 readinessProbe: tcpSocket: port: 6379 initialDelaySeconds: 5 periodSeconds: 5 volumes: - name: redis-data persistentVolumeClaim: claimName: redis-pvc --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: redis-pvc spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 2Gi # storageClassName: "your-storage-class" --- apiVersion: v1 kind: Service metadata: name: appsmith-redis spec: selector: app: redis ports: - port: 6379 targetPort: 6379 --- # 5. AppSmith主服务Deployment及Service apiVersion: apps/v1 kind: Deployment metadata: name: appsmith spec: replicas: 2 # 生产环境建议多副本提升可用性 selector: matchLabels: app: appsmith template: metadata: labels: app: appsmith spec: containers: - name: appsmith image: appsmith/appsmith-ce:v1.9.45 # 替换为最新稳定版镜像 ports: - containerPort: 80 env: - name: APPSMITH_MONGODB_URI valueFrom: configMapKeyRef: name: appsmith-config key: APPSMITH_MONGODB_URI - name: APPSMITH_REDIS_URL valueFrom: configMapKeyRef: name: appsmith-config key: APPSMITH_REDIS_URL - name: APPSMITH_SERVER_URL valueFrom: configMapKeyRef: name: appsmith-config key: APPSMITH_SERVER_URL - name: APPSMITH_ENV valueFrom: configMapKeyRef: name: appsmith-config key: APPSMITH_ENV - name: APPSMITH_ENCRYPTION_PASSWORD valueFrom: secretKeyRef: name: appsmith-secrets key: APPSMITH_ENCRYPTION_PASSWORD volumeMounts: - name: appsmith-data mountPath: /appsmith-stacks resources: requests: cpu: "1" memory: "2Gi" limits: cpu: "2" memory: "4Gi" livenessProbe: httpGet: path: /api/v1/health port: 80 initialDelaySeconds: 60 periodSeconds: 15 readinessProbe: httpGet: path: /api/v1/health port: 80 initialDelaySeconds: 30 periodSeconds: 10 volumes: - name: appsmith-data persistentVolumeClaim: claimName: appsmith-pvc --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: appsmith-pvc spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 5Gi # storageClassName: "your-storage-class" --- # 6. AppSmith访问Service(根据集群环境选择类型) apiVersion: v1 kind: Service metadata: name: appsmith-service spec: type: LoadBalancer # 集群支持则用,否则换为NodePort或ClusterIP配合Ingress selector: app: appsmith ports: - port: 80 targetPort: 80 nodePort: 30080 # 用NodePort时可指定端口(可选)
关键配置说明
- 持久化存储:所有核心组件配置PVC,保证Pod重启/迁移时数据不丢失,生产环境需确认集群有可用StorageClass
- 资源限制:为容器设置CPU、内存的请求与限制,避免资源抢占影响稳定性
- 健康探针:配置liveness/readiness探针,Kubernetes自动检测服务状态并重启异常Pod
- 敏感信息:密码存储在Secret中避免明文泄露,ConfigMap存储非敏感配置便于修改
- 多副本:AppSmith主服务设置2副本,MongoDB用StatefulSet保证数据一致性
验证部署
部署完成后执行以下命令确认状态:
# 查看所有Pod状态 kubectl get pods -n appsmith # 查看Service访问地址(LoadBalancer类型) kubectl get service appsmith-service -n appsmith
待所有Pod变为Running状态后,即可通过Service外部IP或配置的域名访问AppSmith。
内容的提问来源于stack exchange,提问作者Duanjax
相关产品推荐
相关产品推荐

