Which apiVersion to use with k8s jobs and imagePullSecret

10/15/2018

I have a Job that runs migration for a Python service. Here is the job spec:

apiVersion: batch/v1
kind: Job
metadata:
  name: migration
  annotations:
    buildId: "__buildId__"
    branchName: "__branchName__"
    commitId: "__commitId__"
spec:
  template:
    spec:
      containers:
      - name: service
        image: <repo>/service:__buildId__
        imagePullPolicy: Always
        imagePullSecrets:
        - name: acr-key
        command: ["/bin/sh","-c"]
        args: ["python manage.py migrate --noinput --database=default && python manage.py migrate --noinput --database=data_001 && python manage.py migrate --noinput --database=data_002"]
        envFrom:
        - configMapRef:
            name: configuration
        - secretRef:
            name: secrets
        resources:
          requests:
            memory: "200Mi"
            cpu: "250m"
          limits:
            memory: "4000Mi"
            cpu: "2000m"
      restartPolicy: Never

It doesn't look like there is an apiVersion that supports both, imagePullSecrets and kubernetes Job. Any ideas on how can I get this to work?

Here's my k8s configuration:

Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.6", GitCommit:"9f8ebd171479bec0ada837d7ee641dec2f8c6dd1", GitTreeState:"clean", BuildDate:"2018-03-21T15:21:50Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.6", GitCommit:"9f8ebd171479bec0ada837d7ee641dec2f8c6dd1", GitTreeState:"clean", BuildDate:"2018-03-21T15:13:31Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
-- Saksham Gupta
azure-kubernetes
kubectl
kubernetes

1 Answer

10/15/2018

imagePullSecrets should be outside of the containers scope. This works for me:

apiVersion: batch/v1
kind: Job
metadata:
  name: migration
  annotations:
    buildId: "__buildId__"
    branchName: "__branchName__"
    commitId: "__commitId__"
spec:
  template:
    spec:
      imagePullSecrets:
      - name: acr-key
      containers:
      - name: service
        image: <repo>/service:__buildId__
        imagePullPolicy: Always
        command: ["/bin/sh","-c"]
        args: ["python manage.py migrate --noinput --database=default && python manage.py migrate --noinput --database=data_001 && python manage.py migrate --noinput --database=data_002"]
        envFrom:
        - configMapRef:
            name: configuration
        - secretRef:
            name: secrets
        resources:
          requests:
            memory: "200Mi"
            cpu: "250m"
          limits:
            memory: "4000Mi"
            cpu: "2000m"
      restartPolicy: Never
-- Rico
Source: StackOverflow