Running a 'tkn' command in a deployed pod wil result in the error message that it cannot find the pipeline in namespace 'test'.
The deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: tkncli
namespace: test
spec:
replicas: 1
selector:
matchLabels:
app: tkncli
template:
metadata:
labels:
app: tkncli
spec:
containers:
- name: tkncli
image: quay.io/rhcanada/tkn-cli
imagePullPolicy: IfNotPresent
command:
- tkn
args:
- -n
- test
- pipeline
- start
- postsync-pipeline
- --param
- pause-duration="2"
The error message:
Error: Pipeline name postsync-pipeline does not exist in namespace test.
Are these resources really missing? Nope.
$ k get pipeline -n test NAME AGE postsync-pipeline 24m $ k get task -n test NAME AGE postsync-task 12m
I replaced the Docker container with a more official one using this Dockerfile. Same result.
I can start the pipeline with this command:
$ tkn -n test pipeline start postsync-pipeline --param pause-duration="2" --showlog
The result is:
PipelineRun started: postsync-pipeline-run-jzfvf Waiting for logs to be available... [first-task : say-it] Text one [second-task : say-it] Text two
How to reproduce?
- Add the K8s resource: deployment - see above.
- Add the K8s resources: pipeline and task - see below.
The pipeline:
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: postsync-pipeline
namespace: test
spec:
params:
- name: pause-duration
description: uitstellen voor starten
type: string
default: "2"
tasks:
- name: first-task
taskRef:
name: postsync-task
params:
- name: pause-duration
value: $(params.pause-duration)
- name: say-what
value: "Text one"
- name: second-task
taskRef:
name: postsync-task
params:
- name: pause-duration
value: $(params.pause-duration)
- name: say-what
value: "Text two"
The Task:
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: postsync-task
namespace: test
spec:
params:
- name: pause-duration
description: How long to wait before saying something
default: "0"
type: string
- name: say-what
description: What should I say
default: hello
type: string
steps:
- name: say-it
image: registry.access.redhat.com/ubi8/ubi
command:
- /bin/bash
args: ['-c', 'sleep $(params.pause-duration) && echo $(params.say-what)']
When even further simplifying the situation, (1) with the default namespace, (2) an rbac serviceaccount and (3) just a 'pipeline ls' I get this error:
Error: Couldn't get kubeConfiguration namespace: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

In your deployment YAML, I would try and change the
commandandargsfor the container to facilitate debugging.That would replace the original
tkncommand with a shell command that keeps the container running indefinitely (sleep infinity). It allows you toexecinto the pod and manually execute thetkncommand. That way, you can interactively troubleshoot the issue.By using this debugging setup, you can manually test various
tkncommands within the pod's environment to better understand why it is unable to find the pipeline.Make sure the service account associated with the
tknclipod has the necessary permissions to interact with Tekton resources in thetestnamespace. You might need to create a Role and a RoleBinding for this purpose.See for illustration
tektoncd/pipelineissue 1830Make sure the CLI version in your container is compatible with the Tekton version on your cluster.
Verify that there are no network policies (a bit as in
tektoncd/pipelineissue 3154) preventing the pod from communicating with the Kubernetes API server. Also, make sure DNS resolution is working correctly in the pod, allowing it to resolve and access the Tekton resources.It looks like that the
tknCLI is unable to access the Kubernetes API because the necessary configuration is not available in the container's environment. Here is an ASCII diagram to illustrate the issue:The container running the
tknCLI needs to have access to the Kubernetes configuration, which usually means having a validkubeconfigfile or environment variables that provide the necessary information to connect to the Kubernetes API.Kubernetes automatically creates a service account token and mounts it into pods. Make sure your deployment is configured to use the service account with the appropriate permissions.
As suggested by the error message, you can set the
KUBERNETES_MASTERenvironment variable in your deployment to point to the Kubernetes API server. That is usually the internal cluster address.If the
tknCLI requires akubeconfigfile, you might need to create a ConfigMap or Secret containing thekubeconfigand mount it into your container. However, this is less common and can have security implications.Your deployment YAML, with the
KUBERNETES_MASTERenvironment variable, would be:Replace
your-service-accountwith the name of the service account that has the required permissions. After applying this updated deployment, you canexecinto the pod and try running thetkncommand again. If the issue is related to the Kubernetes API access, these changes should help resolve it.