与k8s作业和imagePullSecret一起使用的apiVersion

时间:2018-10-15 18:17:41

标签: kubernetes kubectl azure-kubernetes

我有一个作业,该作业运行Python服务的迁移。这是工作规格:

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

似乎没有一个同时支持imagePullSecrets和kubernetes Job的apiVersion。关于如何使它起作用的任何想法?

这是我的k8s配置:

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"}

1 个答案:

答案 0 :(得分:1)

imagePullSecrets应该在containers范围之外。这对我有用:

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