コンテンツにスキップ
mofcloud

Kubernetes に MOF をデプロイ

最終更新日:

MOF、Dash、MCP を 1 つの Pod で実行します。

Linux amd64 · kubectl · 外部 PostgreSQL · 1 Pod · 3 コンテナ

プライベートネットワーク · CREATEDB 権限が必要 · TLS 必須の PostgreSQL に非対応。

イメージソース

mof.yaml をダウンロード

Docker Hub · MOF v2.0.15 · Dash v2.0.17 · MCP v2.0.3

ダウンロード mof.yaml ↓
ファイルを表示
mof.yaml
# MOF v2.0.15 + Dash v2.0.17 + MCP v2.0.3
# Edit database address, user and password before applying. Keep this file private.
# Keep the Service names mof, mof-mcp and dash, all in one namespace: the components find each
# other by them (mof:8080, mof-mcp:8001). Renamed Services can't connect.
# Private-network PostgreSQL without TLS. TLS-only databases are not supported by this release.
apiVersion: v1
kind: Namespace
metadata:
  name: mof
---
apiVersion: v1
kind: Secret
metadata:
  name: mof-database
  namespace: mof
type: Opaque
stringData:
  password: "REPLACE_WITH_YOUR_DATABASE_PASSWORD"
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mof-config
  namespace: mof
data:
  RK_POSTGRES_0_ADDR: "db.example.com:5432"
  RK_POSTGRES_0_USER: "mof"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mof
  namespace: mof
spec:
  replicas: 1
  # First-release template: stop the old Pod before starting the new version.
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: mof
  template:
    metadata:
      labels:
        app: mof
      # Prometheus discovery by annotation; see the monitoring guide for a PodMonitor
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8080"
        prometheus.io/path: /internal/v1/mof/metrics
    spec:
      enableServiceLinks: false
      nodeSelector:
        kubernetes.io/arch: amd64
      terminationGracePeriodSeconds: 120
      containers:
        - name: mof
          image: mofcloud/mof:v2.0.15
          envFrom:
            - configMapRef:
                name: mof-config
          env:
            - name: RK_POSTGRES_0_PASS
              valueFrom:
                secretKeyRef:
                  name: mof-database
                  key: password
          ports:
            - name: api
              containerPort: 8080
          startupProbe:
            httpGet:
              path: /v1/mof/site-info
              port: api
            periodSeconds: 10
            failureThreshold: 60
          readinessProbe:
            httpGet:
              path: /v1/mof/site-info
              port: api
            periodSeconds: 10
            timeoutSeconds: 5
          resources:
            requests:
              cpu: "500m"
              memory: "1Gi"
          volumeMounts:
            - name: offer-cache
              mountPath: /usr/src/mof/offer-cache
      volumes:
        - name: offer-cache
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: mof
  namespace: mof
spec:
  selector:
    app: mof
  ports:
    - name: api
      port: 8080
      targetPort: api
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mof-mcp
  namespace: mof
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mof-mcp
  template:
    metadata:
      labels:
        app: mof-mcp
    spec:
      enableServiceLinks: false
      nodeSelector:
        kubernetes.io/arch: amd64
      containers:
        - name: mof-mcp
          image: mofcloud/mof-mcp:v2.0.3
          ports:
            - name: mcp
              containerPort: 8001
          readinessProbe:
            exec:
              command: ["node", "/app/build/healthcheck.js"]
            periodSeconds: 10
            timeoutSeconds: 5
          resources:
            requests:
              cpu: "100m"
              memory: "128Mi"
---
apiVersion: v1
kind: Service
metadata:
  name: mof-mcp
  namespace: mof
spec:
  selector:
    app: mof-mcp
  ports:
    - name: mcp
      port: 8001
      targetPort: mcp
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dash
  namespace: mof
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dash
  template:
    metadata:
      labels:
        app: dash
    spec:
      enableServiceLinks: false
      nodeSelector:
        kubernetes.io/arch: amd64
      containers:
        - name: dash
          image: mofcloud/dash:v2.0.17
          ports:
            - name: web
              containerPort: 80
          readinessProbe:
            httpGet:
              path: /
              port: web
            periodSeconds: 10
          resources:
            requests:
              cpu: "100m"
              memory: "64Mi"
---
apiVersion: v1
kind: Service
metadata:
  name: dash
  namespace: mof
spec:
  selector:
    app: dash
  ports:
    - name: web
      port: 80
      targetPort: web
  type: ClusterIP

Service 名 mof、mof-mcp、dash は変更せず、すべて同じ namespace に置いてください。コンポーネントはこれらの名前(mof:8080、mof-mcp:8001)で互いを見つけるため、他の設定は不要です。名前を変えると接続できません。

データベース接続

mof.yaml に既存の PostgreSQL の情報を入力します:

RK_POSTGRES_0_ADDR
アドレス:ポート
RK_POSTGRES_0_USER
ユーザー名
stringData.password
既存のデータベースパスワード

パスワードは引用符で囲んだままにし、このファイルは非公開にしてください。

デプロイ

Terminal
kubectl apply -f mof.yaml
kubectl -n mof rollout status deployment/mof --timeout=10m
kubectl -n mof rollout status deployment/mof-mcp deployment/dash

3 つすべてのロールアウトが完了したら、Admin パスワードを確認します:

Terminal
kubectl -n mof logs deployment/mof | grep "Admin password"

MOF を開く

Terminal
kubectl -n mof port-forward service/dash 8000:80

このターミナルは実行したままにしておきます。

Adminhttp://127.0.0.1:8000/admin

ライセンスをインストールし、ユーザーを作成します。

MOF Webhttp://127.0.0.1:8000

MOF アカウントでログインします。

詳細設定

PostgreSQL の TLS 互換性

MOF は Mof と AsyncJobMof には TLS 設定を適用しますが、プロバイダーのデータベースには適用しません。このテンプレートは信頼できるプライベートネットワークが前提で、TLS 必須の PostgreSQL は使用できません。

ドメイン、HTTPS、オプションの OAuth

既存の Ingress コントローラーを使い、ドメインをそこに向けます。class、ホスト名、namespace mof 内の既存の TLS Secret を設定します。

ダウンロード ingress.yaml ↓
ingress.yaml
# Requires an installed Ingress controller and an existing TLS Secret.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mof
  namespace: mof
spec:
  ingressClassName: nginx
  tls:
    - hosts: [mof.example.com]
      secretName: mof-web-tls
  rules:
    - host: mof.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: dash
                port:
                  number: 80
Terminal
kubectl apply -f ingress.yaml
kubectl -n mof get ingress

Admin → 設定 → MCP で MCP を有効にします。エンドポイント:/v1/mof/remote-mcp。トークンには OAuth は不要です。ブラウザ OAuth には HTTPS、MOF_PUBLIC_URL、MOF_MCP_OAUTH_SECRET が必要です。

ヘルスチェックとトラブルシューティング
Terminal
kubectl -n mof get pods
kubectl -n mof logs deployment/mof --tail=100
kubectl -n mof logs deployment/mof-mcp --tail=60
kubectl -n mof logs deployment/dash --tail=60
kubectl -n mof exec deployment/mof -- wget -q -O - http://mof-mcp:8001/health

期待される状態:mof、mof-mcp、dash が Running かつ Ready、MCP ready: true。起動に失敗した場合は、イメージの取得、ノードのアーキテクチャ、データベースへのアクセスを確認してください。

テンプレートのパラメーター
RK_POSTGRES_0_ADDR外部 PostgreSQL の hostname:port。Pod から到達可能である必要があります。
RK_POSTGRES_0_USERMOF とプロバイダーのデータベースを作成する権限を持つ既存のデータベースロール。
mof-database / passwordSecret に保存したデータベースパスワード。MOF にのみ注入されます。
Services mof / mof-mcp / dashDeployment と Service をそれぞれ 1 つずつ。Service 名で互いを見つけるため、設定は不要です。
replicas / strategy1 / Recreate。アップグレード時はサービスが一時的に中断します。複数レプリカによる高可用性はこのテンプレートの対象外です。
resources.requestsスケジューリング用の予約量であり、メモリ上限ではありません。請求データの量に合わせて MOF のリソースを調整し、実際の使用量を監視してください。
offer-cache / emptyDir再構築可能な公開価格キャッシュ。Pod の置き換え時に失われますが、請求データは PostgreSQL に残ります。
ingressClassName / host / tlsインストール済みのコントローラー、公開ドメイン、TLS Secret に合わせます。ローカルのポートフォワードで確認する場合は不要です。
更新、データ、スケーリング

PostgreSQL をバックアップし、イメージバージョンを更新して mof.yaml を適用します。ConfigMap や Secret を変更した後は再起動してください。Recreate によるアップグレードではサービスが中断します。

Terminal
kubectl -n mof rollout restart deployment/mof
kubectl -n mof rollout status deployment/mof --timeout=10m

単一レプリカのみ対応です。オンデマンドの Kubernetes Job は未実装です。アプリケーションデータは外部 PostgreSQL に保持され、価格キャッシュは再構築できます。