I have a k8 job to publish a sql-server dacpac using the sqlpackage
tool. The job works, the db is successfully deployed, but the job is stuck in the Running status.
How can I ensure the job ends once the sqlpackage
has finished running?
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
When defining a Job in Kubernetes you can set the property activeDeadlineSeconds
.
apiVersion: batch/v1
kind: Job
metadata:
name: your-job
spec:
activeDeadlineSeconds: 100
template:
spec:
containers:
- [...]
Reference: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/