Kubernetes的工作永无止境

问题描述 投票:1回答:1

我有一个k8工作,使用sqlpackage工具发布一个sql-server dacpac。作业正常运行,数据库已成功部署,但作业仍处于“运行”状态。

一旦sqlpackage完成运行,我怎样才能确保工作结束?


apiVersion: batch/v1
kind: Job
metadata:
  name: my-publish-job
  namespace: my-namespace
spec:
  template:
    metadata:
      labels:
        app: my-publish-job
        namespace: my-namespace
    spec:
      containers:
        - name: my-db-publish
          image: my-db-image:v1.0.0
          imagePullPolicy: Always
          lifecycle:
            postStart:
              exec:
                command:
                - /bin/bash
                - -c
                - >
                    /sqlpackage/sqlpackage \
                      /Action:Publish \
                      /SourceFile:"/my-db.dacpac"  \
                      /p:DropObjectsNotInSource=True \
                      /p:DoNotDropObjectTypes="Users;Permissions;RoleMembership;ServerRoleMembership" \
                      /p:IgnoreAuthorizer=True \
                      /p:IgnorePermissions=True \
                      /TargetUser:sa \
                      /TargetPassword:my_db_password \
                      /TargetDatabaseName:MyDb \
                      /TargetServerName:my.db.server
      restartPolicy: Never
kubernetes
1个回答
0
投票

在Kubernetes中定义作业时,您可以设置属性activeDeadlineSeconds

apiVersion: batch/v1
kind: Job
metadata:
  name: your-job
spec:
  activeDeadlineSeconds: 100
  template:
    spec:
      containers:
      - [...]

参考:https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/

© www.soinside.com 2019 - 2024. All rights reserved.