I am able to login into a taskrun pod as long as the task is being executed by:
kubectl exec $POD_NAME /bin/bash
However, if a task has failed or completed. I am unable to login by kubectl exec command, since it states, "cannot login to a completed tasks".
If need to debug on a failed tasks, is there any way to attach to a console of a failed/completed tasks in Tekton.
I am running on a minikube environment.
Tekton Tasks are Pods. When they complete, or when they fail: that pod exits, which leaves you unable to get in.
Troubleshooting, you may edit your Task, catch the error and start some "sleep" command, which might help figuring it out.
Or, without risking to impact other jobs, I would usually prefer to re-create the Pod corresponding to my failed task.
$ kubectl get pods -n <ci-namespace> | grep <taskrun-name>
NAME
<tasksrun>-xxx-yyy
$ kubectl get pods -n <ci-namespace <taskrun>-xxx-yyy -o yaml >check.yaml
Then, edit that yaml file. Remove all metadata unless name/namespace. Change metadata.name, making sure your pod has its own name. Remove the status block. Catch failure where it's needed and add your 'sleep'. Then kubectl create that file and enter your pod.
Depending on what you're troubleshooting, it may be easier to add some PVC workspace into your task, make sure your working directories, logs, built assets, ... end up in some volume that you could mount from a separate container, should you need to troubleshoot it.
Or: if you're fast enough, just re-run your pipeline/task, enter its container while it starts, and try troubleshooting it before it fails.