1 job基础
job负责仅执行一次的任务。
2 job样例
2.1 查看job
yaml文件:
{{- if .Values.manifests.job_db_init_mongodb }}
{{- $envAll := . }}
{{- $dependencies := .Values.dependencies.db_init_mongodb }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: ceilometer-db-init-mongodb
spec:
template:
spec:
restartPolicy: OnFailure
nodeSelector:
{{ .Values.labels.job.node_selector_key }}: {{ .Values.labels.job.node_selector_value }}
initContainers:
{{ tuple $envAll $dependencies "[]" | include "helm-toolkit.snippets.kubernetes_entrypoint_init_container" | indent 8 }}
containers:
- name: ceilometer-db-init-mongodb
image: {{ tuple .Values.images.tags "db_init_mongodb" . | include "helm-toolkit.utils.update_image" }}
imagePullPolicy: {{ .Values.images.job_pull_policy | quote }}
{{ tuple $envAll $envAll.Values.pod.resources.jobs.db_init_mongodb | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }}
env:
- name: ROOT_DB_CONNECTION
valueFrom:
secretKeyRef:
name: {{ .Values.secrets.mongodb.admin }}
key: DB_CONNECTION
- name: USER_DB_CONNECTION
valueFrom:
secretKeyRef:
name: {{ .Values.secrets.mongodb.user }}
key: DB_CONNECTION
command:
- /tmp/db-init-mongodb.sh
volumeMounts:
- name: ceilometer-bin
mountPath: /tmp/db-init-mongodb.sh
subPath: db-init-mongodb.sh
readOnly: true
volumes:
- name: ceilometer-bin
configMap:
name: ceilometer-bin
defaultMode: 0555
{{- end }}
实际结果:
apiVersion: batch/v1
kind: Job
metadata:
creationTimestamp: 2020-01-15T07:45:53Z
labels:
controller-uid: 0e81db7b-376b-11ea-8f18-b82a72d4e66a
job-name: ceilometer-db-init-mongodb
name: ceilometer-db-init-mongodb
namespace: openstack
resourceVersion: "47873"
selfLink: /apis/batch/v1/namespaces/openstack/jobs/ceilometer-db-init-mongodb
uid: 0e81db7b-376b-11ea-8f18-b82a72d4e66a
spec:
backoffLimit: 6
completions: 1
parallelism: 1
selector:
matchLabels:
controller-uid: 0e81db7b-376b-11ea-8f18-b82a72d4e66a
template:
metadata:
creationTimestamp: null
labels:
controller-uid: 0e81db7b-376b-11ea-8f18-b82a72d4e66a
job-name: ceilometer-db-init-mongodb
spec:
containers:
- command:
- /tmp/db-init-mongodb.sh
env:
- name: ROOT_DB_CONNECTION
valueFrom:
secretKeyRef:
key: DB_CONNECTION
name: ceilometer-mongodb-admin
- name: USER_DB_CONNECTION
valueFrom:
secretKeyRef:
key: DB_CONNECTION
name: ceilometer-mongodb-user
image: hub.easystack.io/production/mongodb:latest
imagePullPolicy: Always
name: ceilometer-db-init-mongodb
resources:
limits:
cpu: "2"
memory: 1Gi
requests:
cpu: 100m
memory: 124Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /tmp/db-init-mongodb.sh
name: ceilometer-bin
readOnly: true
subPath: db-init-mongodb.sh
dnsPolicy: ClusterFirst
initContainers:
- command:
- kubernetes-entrypoint
env:
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: INTERFACE_NAME
value: eth0
- name: DEPENDENCY_SERVICE
value: openstack:mongodb
- name: DEPENDENCY_JOBS
- name: DEPENDENCY_DAEMONSET
- name: DEPENDENCY_CONTAINER
- name: COMMAND
value: echo done
image: hub.easystack.io/production/kubernetes-entrypoint:v0.2.1
imagePullPolicy: IfNotPresent
name: init
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
nodeSelector:
openstack-control-plane: enabled
restartPolicy: OnFailure
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 365
name: ceilometer-bin
name: ceilometer-bin
status:
completionTime: 2020-01-15T09:34:32Z
conditions:
- lastProbeTime: 2020-01-15T09:34:32Z
lastTransitionTime: 2020-01-15T09:34:32Z
status: "True"
type: Complete
startTime: 2020-01-15T07:45:53Z
succeeded: 1
参考:
kubernetes-handbook
openstack helm charts