-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
G_A_C in GKE Tekton pipeline: open /secret/kaniko-secret: no such file or directory #3828
Comments
/kind bug |
Something is definitely broken here, but we haven't yet had the time to reproduce the issue. Lowering the priority due to current bandwidth. |
@yuwenma - Hey Yuwen. I'd like to take a closer look at this issue. I'm new to the project, so I'm having a difficult time following along. Can you help me clarify:
Thank you for your help! |
@tstromberg Sure thing! here is the broken example. Two things are incorrect after I triaged the issue:
Creating kaniko secret [<MY NAMESPACE>/kaniko-secret]...
Building [gcr.io/XXX/redisslave]...
error checking push permissions -- make sure you entered the correct tag name, and that you are authenticated correctly, and try again: checking push permission for "gcr.io/<MY PROJECT>/<MY IMG>:7ef7eb8": creating push check transport for gcr.io failed: Get https://gcr.io/v2/token?scope=repository%3A<MYPROJECT>%2F<MY IMG>%3Apush%2Cpull&service=gcr.io: invoking docker-credential-gcr: exit status 1; output: docker-credential-gcr/helper: could not retrieve GCR's access token: google: error getting credentials using GOOGLE_APPLICATION_CREDENTIALS environment variable: open /secret/kaniko-secret: no such file or directory
time="2020-03-13T21:27:24Z" level=fatal msg="build failed: building [gcr.io/yuwenma-gke-playground/redisslave]: waiting for pod to complete: condition error: pod already in terminal phase: Failed" You can see from the example's volume mount config, the k8s secret kaniko-secret is in fact mounted to the correct path. You can find the full tekton config from the above issue description. Let me know if there's anything unclear. |
So I got curious about this issue and decided to test it out myself. I don't know how Skaffold handles all these, but here's what I did to make this work.
|
Thanks @chanseokoh for jumping in. Just to confirm a couple of things, the config I post is tekton which is different from running an isolated docker task. Besides, the GOOGLE_APPLICATION_CREDENTIALS env is specifically required by kaniko when pushing the images to a container registry. If it's not GKE cluster and not container registry, then it may not be required. Besides, hard coding the secret as "kaniko-secret" won't fit our needs. because what I do is giving our customers the option to set up kaniko-secret themselves and eventually this part would be changed to something different. @tstromberg |
I ran a Tekton task.
I am saying
Not sure what you mean by "hard-coding" here. Just like what you did, I am providing |
Did a bit more testing, and actually, it turns out you don't even need to mount a secret. You just need to set the data key name of the secret to - --profile
- oncluster
- --file-output
- build.out
workingDir: /workspace/workspace
resources: {}
- env:
- - name: GOOGLE_APPLICATION_CREDENTIALS
- value: /secret/kaniko-secret # tried both kaniko-secret and kaniko-secret.json (the file name contained in the k8s kaniko-secret). The skaffold/examples folder seems to have both formats.
- volumeMounts:
- - name: kaniko-secret
- mountPath: /secret
- volumes:
- - name: kaniko-secret
- secret:
- secretName: kaniko-secret I think Skaffold does all the magic with cluster:
pullSecretName: kaniko-secret
|
Thanks Chanseoko, I did another try but still couldn't get it work. Here's what I did:
apiVersion: skaffold/v2beta3
kind: Config
metadata:
name: app-cicd-demo-
profiles:
- name: oncluster
build:
artifacts:
- image: gcr.io/yuwen-cicd-demo2/ci-redisslave1
context: redis-slave
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-and-push
namespace: "cicd"
spec:
params:
- name: pathToDockerFile
default: /workspace/workspace/php-redis/Dockerfile
description: The path to the dockerfile to build
- name: pathToContext
default: /workspace/workspace
description: The build context used by Kaniko
default: skaffold.yaml
steps:
- name: run-skaffold-build
image: gcr.io/k8s-skaffold/skaffold
command:
- skaffold
- build
args:
- --filename
- $(params.skaffoldConfig) # location of my skaffold.yaml
- --profile
- oncluster
- --file-output
- build.out
workingDir: /workspace/workspace
resources: {} Then the tekton task reports gcloud 400 errors kubectl -n cicd logs ci-run-vpzgd-build-frontend-nmmkh-pod-9s6sb -c step-run-skaffold-build
Generating tags...
- gcr.io/yuwen-cicd-demo2/ci-redisslave1 -> gcr.io/yuwen-cicd-demo2/ci-redisslave1:4b3da59
Checking cache...
- gcr.io/yuwen-cicd-demo2/ci-redisslave1: Not found. Building
Building [gcr.io/yuwen-cicd-demo2/ci-redisslave1]...
ERROR: gcloud crashed (MetadataServerException): HTTP Error 400: Bad Request
If you would like to report this issue, please run the following command:
gcloud feedback
To check gcloud for common problems, please run the following command:
gcloud info --run-diagnostics
couldn't build "gcr.io/yuwen-cicd-demo2/ci-redisslave1": docker build: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? I also tried including the G_A_C env, and got the same error. @chanseokoh Let me know if there's any other info you may want to know. Thanks for jumping in and giving suggestions! Would be great to hear some insights from @tstromberg and @nkubala as well! |
@yuwenma here's a minimal, complete step-by-step example that I created for demonstration. Note I'm just telling you how you can make this work; I do think Skaffold has room for improvement or at least needs to fix the sample with better documentation around providing the Kaniko secret. Preparation
Working Sample
First, update - name: oncluster
build:
artifacts:
- - image: gcr.io/chanseok-playground-new/skaffold-pipeline-test
+ - image: gcr.io/yuwen-cicd-demo2/skaffold-pipeline-test
context: .
kaniko: {}
tagPolicy:
Watch it fails due to the wrong secret.
At this point, it is already proved that it picks up the very wrong secret I provided. No such error you observed as
Watch the image is built and pushed to
For example,
|
@yuwenma skaffold hardcoded the If the secret you created was at different filepath, kaniko pod would fail. With this change,
|
Thanks @tejal29 I tried changing the kaniko-secret to match the hard-coded one and it works. - gcr.io/yuwen-cicd-demo2/ci-redisslave1: Not found. Building
Building [gcr.io/yuwen-cicd-demo2/ci-redisslave1]...
couldn't build "gcr.io/yuwen-cicd-demo2/ci-redisslave1": undefined artifact type: {DockerArtifact:<nil> BazelArtifact:<nil> JibArtifact:<nil> KanikoArtifact:0xc0003150e0 BuildpackArtifact:<nil> CustomArtifact:<nil>} I did specified an artifact KainkoArtifact in my skaffold.yaml apiVersion: skaffold/v2beta3
kind: Config
metadata:
name: app-cicd-demo-
profiles:
- name: oncluster
build:
artifacts:
- image: gcr.io/yuwen-cicd-demo2/ci-redisslave1
context: redis-slave
kaniko:
dockerfile: /workspace/workspace/redis-slave/Dockerfile Wondering it complains that the artiact type is not defined. @nkubala @tejal29 |
@yuwenma - It's tough to tell from this error, but I think this may be caused because there is no cluster specified to build on, so it's falling back onto the local builder, which doesn't support Kaniko. skaffold/pkg/skaffold/build/local/local.go Line 104 in eab0d15
For example, see
|
Is there a way to specify the cluster name? From the examples/generate-pipeline, it seems that the skaffold image doesn't need the cluster to be specified. |
Yes, feel free to close the issue @nkubala |
Expected behavior
From the example, when running skaffold in a tekton pipeline using GKE cluster, an env var GOOGLE_APPLICATION_CREDENTIALS needs to be specified with a kaniko secret mounted to it.
Either by running "skaffold generate-pipeline" or using the examples from the examples folder should successfully mount the secret to the GOOGLE_APPLICATION_CREDENTIALS.
Actual behavior
The image
gcr.io/k8s-skaffold/skaffold
(tested v1.4.0 and v1.5.0) can't find the secret from GOOGLE_APPLICATION_CREDENTIALS. Here's the error message:Information
Here's my tekton task config
Additional Information
The kaniko-secret itself is correct. The service account of the kaniko-secret has the expected access to upload images to my gcr and I've tested the secret using kaniko directly in tekton task config.
The text was updated successfully, but these errors were encountered: