kaniko icon indicating copy to clipboard operation
kaniko copied to clipboard

kaniko v0.20.0~latest build creation time is slower than kaniko v0.19.0

Open EmilyEmily opened this issue 6 years ago • 1 comments

Actual behavior I tested with latest kaniko image to create buildrun on IBM Kubernetes Services (IKS) Cluster, and found the average buildrun creation time with kaniko image >= v0.20.0 is longer than that with kaniko image v0.19.0 and v0.18.0.

Buildrun creation time is calculated in this way:

        kubectl get br -o json |jq -r '.items[] | .metadata.name + "  " + .status.succeeded  + "  " + .status.completionTime + "  " + .status.startTime' |while read -r LINE; 
        do 
          i=$((i+1))
          br_name=$(echo "${LINE}" |awk -F ' ' '{print $1}')
          br_end_t=$(echo "${LINE}" |awk -F ' ' '{print $3}')
          br_start_t=$(echo "${LINE}" |awk -F ' ' '{print $4}')
          br_dur_t=$(($(date +%s -d "${br_end_t}") - $(date +%s -d "${br_start_t}")))
...

I did some tests to apply kaniko 0.18.0/ 0.19.0/0.20.0/0.22.0(latest), this is the buildrun creation time for my 4 groups of test:

Kaniko version v0.18 v0.19 v0.20 v0.22(latest)
Buildrun creation time 70~85s 70~85s around 120s around 120s

From this result, we can see buildrun creation time becomes longer after applying kaniko v0.20.0 and later.

Expected behavior Buildrun creation time with latest kaniko image is similar to that with kaniko v0.19.0. At present, the former is 1.5 times the latter one.

To Reproduce Steps to reproduce the behavior:

  1. Apply Cluster level buildStrategy with kaniko:latest definition file and with that of kaniko:v0.19.0 kubectl apply -f buildstrategy_kaniko_cr.yaml kubectl apply -f buildstrategy_kaniko_cr_19.yaml
  2. Apply build definitions for kaniko latest and kaniko v0.19.0 yaml file kubeclt apply -f build_kaniko_cr.yml kubeclt apply -f build_kaniko_cr_19.yml
  3. Apply buildrun definition for kaniko latest and kaniko v0.19.0 yaml file kubectl apply -f buildrun_kaniko_cr.yml kubectl apply -f buildrun_kaniko_cr_19.yml
  4. Get buildrun creation time from buildrun output:
        kubectl get br -o json |jq -r '.items[] | .metadata.name + "  " + .status.succeeded  + "  " + .status.completionTime + "  " + .status.startTime' |while read -r LINE; 
        do 
          i=$((i+1))
          br_name=$(echo "${LINE}" |awk -F ' ' '{print $1}')
          br_end_t=$(echo "${LINE}" |awk -F ' ' '{print $3}')
          br_start_t=$(echo "${LINE}" |awk -F ' ' '{print $4}')
          br_dur_t=$(($(date +%s -d "${br_end_t}") - $(date +%s -d "${br_start_t}")))
...

Additional Information

  • Dockerfile Please provide either the Dockerfile you're trying to build or one that can reproduce this error.
  • Build Context 1-1. BuildStagety with latest kaniko:
# cat buildstrategy_kaniko_cr.yaml
---
apiVersion: build.dev/v1alpha1
kind: ClusterBuildStrategy
metadata:
  name: kaniko
spec:
  buildSteps:
    - name: step-build-and-push
      image: gcr.io/kaniko-project/executor:latest
      workingdir: /workspace/source
      securityContext:
        runAsUser: 0
        capabilities:
          add:
            - CHOWN
            - DAC_OVERRIDE
            - FOWNER
            - SETGID
            - SETUID
      env:
        - name: DOCKER_CONFIG
          value: /tekton/home/.docker
      command:
        - /kaniko/executor
      args:
        - --skip-tls-verify=true
        - --dockerfile=$(build.dockerfile)
        - --context=/workspace/source/$(build.source.contextDir)
        - --destination=$(build.output.image)

1-2. Build definition with latest kaniko:

# cat build_kaniko_cr.yml
---
apiVersion: build.dev/v1alpha1
kind: Build
metadata:
  name: kaniko-golang-build-emily
spec:
  source:
    url: https://github.com/sbose78/taxi
  strategy:
    name: kaniko
    kind: ClusterBuildStrategy
  dockerfile: Dockerfile
  resources:
    limits:
      cpu: "500m"
      memory: "1Gi"
  output:
    image: us.icr.io/emilyregistry/taxi-app
    credentials:
      name: icr-knbuild

1-3. Buildrun definition with latest kaniko:

# cat buildrun_kaniko_cr.yml
---
apiVersion: build.dev/v1alpha1
kind: BuildRun
metadata:
  name: kaniko-golang-buildrun-emily
spec:
  buildRef:
    name: kaniko-golang-build-emily
  resources:
    limits:
      cpu: "1"

2-1. BuildStrategy with Kaniko v0.19.0:

# cat buildstrategy_kaniko_cr_19.yaml
---
apiVersion: build.dev/v1alpha1
kind: ClusterBuildStrategy
metadata:
  name: kaniko-19
spec:
  buildSteps:
    - name: step-build-and-push
      image: gcr.io/kaniko-project/executor:v0.19.0
      workingdir: /workspace/source
      securityContext:
        runAsUser: 0
        capabilities:
          add:
            - CHOWN
            - DAC_OVERRIDE
            - FOWNER
            - SETGID
            - SETUID
      env:
        - name: DOCKER_CONFIG
          value: /tekton/home/.docker
      command:
        - /kaniko/executor
      args:
        - --skip-tls-verify=true
        - --dockerfile=$(build.dockerfile)
        - --context=/workspace/source/$(build.source.contextDir)
        - --destination=$(build.output.image)

2-2. Build definition for kaniko v0.19.0:

# cat build_kaniko_cr_19.yml
---
apiVersion: build.dev/v1alpha1
kind: Build
metadata:
  name: kaniko-golang-build-emily-19
spec:
  source:
    url: https://github.com/sbose78/taxi
  strategy:
    name: kaniko-19
    kind: ClusterBuildStrategy
  dockerfile: Dockerfile
  resources:
    limits:
      cpu: "500m"
      memory: "1Gi"
  output:
    image: us.icr.io/emilyregistry/taxi-app
    credentials:
      name: icr-knbuild

2-3. buildrun definition for kaniko v0.19.0:

# cat buildrun_kaniko_cr_19.yml
---
apiVersion: build.dev/v1alpha1
kind: BuildRun
metadata:
  name: kaniko-golang-buildrun-emily-19
spec:
  buildRef:
    name: kaniko-golang-build-emily-19
  resources:
    limits:
      cpu: "1"
  • Kaniko Image (fully qualified with digest) https://github.com/GoogleContainerTools/kaniko/releases/tag/v0.22.0 https://github.com/GoogleContainerTools/kaniko/releases/tag/v0.19.0

Triage Notes for the Maintainers

Description Yes/No
Please check if this a new feature you are proposing
  • - [ ]
Please check if the build works in docker but not in kaniko
  • - [ ]
Please check if this error is seen when you use --cache flag
  • - [ ]
Please check if your dockerfile is a multistage dockerfile
  • - [ ]

EmilyEmily avatar May 15 '20 13:05 EmilyEmily

Solve the problem by adding these two env properties:

        - name: AWS_ACCESS_KEY_ID
          value: NOT_SET
        - name: AWS_SECRET_KEY
          value: NOT_SET

I have tried, it works better after add the env properties:

Here is the result:

  • v0.23 WITHOUT fix:
2020-06-11T07:33:31.334427065Z E0611 07:33:31.333998      10 aws_credentials.go:77] while getting AWS credentials NoCredentialProviders: no valid providers in chain. Deprecated.
2020-06-11T07:33:31.33447597Z 	For verbose messaging see aws.Config.CredentialsChainVerboseErrors
2020-06-11T07:33:34.236923117Z INFO[0043] Retrieving image manifest node:12
2020-06-11T07:33:35.44372804Z INFO[0044] Retrieving image manifest node:12
2020-06-11T07:33:37.125185942Z INFO[0046] Built cross stage deps: map[]
2020-06-11T07:33:37.125222191Z INFO[0046] Retrieving image manifest node:12
2020-06-11T07:33:38.283113277Z INFO[0047] Retrieving image manifest node:12
2020-06-11T07:33:40.083227098Z INFO[0049] Executing 0 build triggers

You can see AWS credentials check fail and start the build after 43 seconds

  • v0.23 WITH fix:
2020-06-11T07:27:48.279422822Z INFO[0005] Retrieving image manifest node:12
2020-06-11T07:27:49.635951861Z INFO[0006] Retrieving image manifest node:12
2020-06-11T07:27:51.312964149Z INFO[0008] Built cross stage deps: map[]
2020-06-11T07:27:51.31300063Z INFO[0008] Retrieving image manifest node:12
2020-06-11T07:27:52.524858337Z INFO[0009] Retrieving image manifest node:12
2020-06-11T07:27:54.295956926Z INFO[0011] Executing 0 build triggers

You can see NO aws creds failures and build start after 5 mins

The 30s delay disappear.

Thanks @SaschaSchwarze0 ! It helped us a lot!

zhangtbj avatar Jun 11 '20 08:06 zhangtbj